Variables

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.

Declaring Variables

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 ...

Get Python Programming with the Java™ Class Libraries: A Tutorial for Building Web and Enterprise Applications with Jython now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.