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 OriginalGriff 350
1 Jochen Arndt 190
2 Richard MacCutchan 135
3 Sergey Alexandrovich Kryukov 120
4 DamithSL 105
0 OriginalGriff 6,045
1 DamithSL 4,611
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,310


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 15 Nov 2010
Copyright © CodeProject, 1999-2014
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