Using basic variables

  1. Assign values to some variables:

    >>> one = 1

    >>> two = 2

    >>> three = one + two

    >>> hello = "hello"

    >>> world = "world"

    >>> helloworld = hello + " " + world

  2. Try printing the values of the variables:

    >>> three

    3

    >>> helloworld

    'hello world'

    Tip: Assigning a value to a variable when it has not been referenced before will also instantiate it. You do not need to define the variable first.

See also

Starting the Python shell

Printing hello world

Creating an array and a dictionary and printing values

Looping through a predefined list

Looping using the xrange function