覆盖变量 [英] Overwriting Variable
问题描述
大家好
我在Python中有一个循环,负责系统的主要功能.我在循环中有各种字符串变量,可在循环的每次迭代中重复使用这些变量,并不断为其分配新的字符串值.
在为它们分配新的字符串值之前,我不会清除字符串变量.
我应该在分配新的字符串值之前清除每个字符串变量吗?
还是在分配新值时以前的变量值被完全覆盖??
感谢您的所有帮助
问候
Hi Guys
I have a loop in Python that is responsible for the main functionality of my system. I have various string variables in the loop that are re-used on each iteration of the loop and are continuously assigned new string values.
I do not clear string variables before I assign them with new string values.
Should I be clearing each string variable before assigning a new string value??
Or are previous variable values completely overwritten when you assign a new value??
Thanks for all the help
Regards
推荐答案
嗨sach262,
如果您使用
之类的赋值语句var1 = expression_yielding_a_string
您会做的很好,而像var1 += expression_yielding_a_String
这样的作业
会将字符串内容累积到var1中.
希望这会有所帮助.
干杯
Manfred
Hi sach262,
if you''re using assignment statements in the likes of
var1 = expression_yielding_a_string
you''ll be doing fine, whereas assignments likevar1 += expression_yielding_a_String
will accumulate string content into var1.
Hope this helps.
Cheers
Manfred
在分配新的字符串值之前,我不会清除字符串变量.
我应该在分配新的字符串值之前清除每个字符串变量吗?
I do not clear string variables before I assign them with new string values.
Should I be clearing each string variable before assigning a new string value??
编号
No.
或者在分配新值时以前的变量值会被完全覆盖吗?
Or are previous variable values completely overwritten when you assign a new value??
是的.
:)
Yes.
:)
这篇关于覆盖变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!