Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: 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
Posted 14-Nov-10 22:22pm
sach262229
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi sach262,
 
if you're using assignment statements in the likes of
var1 = expression_yielding_a_string you'll be doing fine, whereas assignments like var1 += expression_yielding_a_String
 
will accumulate string content into var1.
 
Hope this helps.
 
Cheers
 
Manfred
  Permalink  
Comments
sach262 at 15-Nov-10 4:08am
   
thanks Manfred. appreciated
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

sach262 wrote:
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.
 

sach262 wrote:
Or are previous variable values completely overwritten when you assign a new value??

Yes.
Smile | :)
  Permalink  
Comments
sach262 at 15-Nov-10 4:08am
   
Thank you for clearing that up for me:)
CPallini at 15-Nov-10 4:30am
   
You are welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 7,203
1 OriginalGriff 5,587
2 Peter Leow 4,097
3 Mika Wendelius 2,850
4 CHill60 2,818


Advertise | Privacy | Mobile
Web04 | 2.8.150224.1 | Last Updated 15 Nov 2010
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100