T
tmallen
What's the proper way to instantiate a new variable? x = ""?
What's the proper way to instantiate a new variable? x = ""?
You don't need to pre-declare your variables. Just assign them as you
need them and they will take the correct type.
unless I'm using the += or a similar operator, right? That doesn't
seem to instantiate a variable.
From: [email protected] [mailtoython-
[email protected]] On Behalf Of tmallen
Sent: Tuesday, June 03, 2008 2:41 PM
To: (e-mail address removed)
Subject: New variable?
What's the proper way to instantiate a new variable? x = ""?
unless I'm using the += or a similar operator, right? That doesn't
seem to instantiate a variable.
Right... because you don't have anything to increment or append to. I
guess this also comes up in the case of something like lists or
dictionaries you want to uniformly create in a loop. I guess you
could call it instantiating, but really it's more like going ahead and
assigning to them as Chris mentioned and you're just starting them
with a default value. Assuming you're working with strings, x=""
should work just fine in that case. Lists, x=[], dictionaries, x={},
integers, probably x=1 or x=0...
What's the proper way to instantiate a new variable? x = ""?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.