DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Python (http://www.daniweb.com/forums/forum114.html)
-   -   Adding info to a variable (http://www.daniweb.com/forums/thread159240.html)

adam291086 Nov 24th, 2008 9:12 am
Adding info to a variable
 
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
adam = "john"
adam = adam + "mike"

solsteel Nov 24th, 2008 11:24 am
Re: Adding info to a variable
 
It depends on the type of data and how you intend to use it.
>>> adam = "john"
>>> adam += "mike"
>>> adam
'johnmike'
>>> ' '.join([adam, 'fred'])
'johnmike fred'
>>>

Paul Thompson Nov 24th, 2008 3:37 pm
Re: Adding info to a variable
 
If you want to do that to an int and you just want to add it on the end then you could go:
>>> adam = 123
>>> john = 456
>>> #if you just add them together they don't add on to the end,
>>> print adam+john
579
>>> print str(adam)+str(john)
123456
>>> # and then you can turn that back into an int using the int() function

paddy3118 Nov 25th, 2008 3:11 am
Re: Adding info to a variable
 
You seem to be wanting to store a collection of information. Have a look at lists, sets and dictionaries in the python documentation.

- Paddy.


All times are GMT -4. The time now is 5:00 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC