June 2002
Beginner to intermediate
640 pages
14h 24m
English
Think of variables as individual storage containers that hold different kinds of data in memory. Each variable has a name and a value, and each variable value has a type.
In most languages, before you can use a variable you have to declare it; that is, you must assign it a name and a type. Python is different; unlike in other languages, you declare a variable implicitly by assigning a value to it. Here's an example:
# declare age to be of type integer and of value 28. age = 28 # declare name to be of type string # and of value "rick" name = "rick"
Variable declarations can go anywhere in a module. You can declare more than one variable at once by stringing them together. (Follow along).
>>> x,y,z = 1,2,3 >>> print ...
Read now
Unlock full access