1. Home
  2. Computing & Technology
  3. Python

Beginning Python: Data Types

From , former About.com Guide

6 of 10

Accessing Variables

To access the value of a variable within the Python shell, simply type it.

>>> x = 1500
>>> x
1500

Within a program, one can use the 'print' command.

cat = 'dog'
print cat
output:
dog

If the variable is a string, you can also access its parts. Each character of the string is indexed, starting with the first character at '0'. By accessing the string with an indexing operator, you can access only part of the string and leave the rest untouched. An example:

cat = 'dog'
print cat[0]
print cat[1]
print cat[2]
output:
d
o
g

Explore Python
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Python

©2009 About.com, a part of The New York Times Company.

All rights reserved.