Adding info to a variable

Thread Solved
Reply

Join Date: Nov 2008
Posts: 58
Reputation: adam291086 is an unknown quantity at this point 
Solved Threads: 0
adam291086 adam291086 is offline Offline
Junior Poster in Training

Adding info to a variable

 
0
  #1
Nov 24th, 2008
I have the variable Adam that contains some information.

Later on i have some more information to add to the variable adam. How can this be done

something like
  1. adam = "john"
  2. adam = adam + "mike"
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 110
Reputation: solsteel is on a distinguished road 
Solved Threads: 31
solsteel solsteel is offline Offline
Junior Poster

Re: Adding info to a variable

 
0
  #2
Nov 24th, 2008
It depends on the type of data and how you intend to use it.
  1. >>> adam = "john"
  2. >>> adam += "mike"
  3. >>> adam
  4. 'johnmike'
  5. >>> ' '.join([adam, 'fred'])
  6. 'johnmike fred'
  7. >>>
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 837
Reputation: Paul Thompson has a spectacular aura about Paul Thompson has a spectacular aura about 
Solved Threads: 130
Sponsor
Paul Thompson's Avatar
Paul Thompson Paul Thompson is offline Offline
previously paulthom12345

Re: Adding info to a variable

 
0
  #3
Nov 24th, 2008
If you want to do that to an int and you just want to add it on the end then you could go:
  1. >>> adam = 123
  2. >>> john = 456
  3. >>> #if you just add them together they don't add on to the end,
  4. >>> print adam+john
  5. 579
  6. >>> print str(adam)+str(john)
  7. 123456
  8. >>> # and then you can turn that back into an int using the int() function
Make it idiot proof and someone will make a better idiot.
Check out my Site | and join us on IRC | Python Specific IRC
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 33
Reputation: paddy3118 is an unknown quantity at this point 
Solved Threads: 8
paddy3118 paddy3118 is offline Offline
Light Poster

Re: Adding info to a variable

 
0
  #4
Nov 25th, 2008
You seem to be wanting to store a collection of information. Have a look at lists, sets and dictionaries in the python documentation.

- Paddy.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Python Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC