Click here to Skip to main content
12,395,252 members (66,710 online)
Rate this:
 
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 21: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 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 15-Nov-10 4:08am
   
Thank you for clearing that up for me:)
CPallini 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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160721.1 | Last Updated 15 Nov 2010
Copyright © CodeProject, 1999-2016
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