Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Declaring Variable

Status
Not open for further replies.

paubri

Programmer
Apr 25, 2005
21
ZA
Hi.

I've just started to use Python coming from Delphi 5. In delphi you have to declare all variables you are going use, but in Python this doesn't seem to be the case. Is it better to declare them so that the program knows what kind of variable they are or just assigning values to them.

Also, could someone please tell me how to get a 2 dimentional array.

Thanks,
British
 
Python is strongly typed, but dynamically declared. Variable names are simply labels you assign to objects, you get no benefit from declaring them before you use them.

Two dimensional array:
Code:
>>> myarr = [ [ "zero zero", "zero one", "zero two" ], 
...           [ "one zero", "one one", "one two" ],
...           [ "two zero", "two one", "two two" ] ]
>>> print myarr[1][1]
one one
>>> print myarr[1][2]
one two
>>> print myarr[2][0]
two zero
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top