New variable?

Chris cwitts at
Tue Jun 3 22:23:20 CEST 2008

On Jun 3, 9:34 pm, "Dan Upton" <up... at> wrote:
> On Tue, Jun 3, 2008 at 3:16 PM, tmallen <thomasmal... at> wrote:
> > On Jun 3, 3:03 pm, Chris <cwi... at> wrote:
> >> On Jun 3, 8:40 pm, tmallen <thomasmal... at> wrote:
> >> > 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.
> 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...

You can always use the conversion functions if you want to be explicit
str(), int(), list(), dict(), set() etc

More information about the Python-list mailing list