Deitel & Associates, Inc. Logo

Back to www.deitel.com
digg.png delicious.png blinkit.png furl.png
Internet & World Wide Web How to Program, 3/e
Internet & World Wide Web How to Program, 3/e

ISBN:
0-13-145091-3
© 2004
pages: 1420

Order
Amazon logo

This tutorial presents an introduction to Python—the popular, cross-platform, object-oriented programming language. We show how to create and run a simple Python program and how to work interactively with the Python interpreter.
Download the Code Examples
[Note: This tutorial is an excerpt (Section 35.1) of Chapter 35, Python, from our textbook Internet & World Wide Web How to Program, 3/e. This tutorial may refer to other chapters or sections of the book that are not included here. Permission Information: Deitel, Harvey M. and Paul J., INTERNET & WORLD WIDE WEB HOW TO PROGRAM, 3/E, 2004, pp.1242-1246. Electronically reproduced by permission of Pearson Education, Inc., Upper Saddle River, New Jersey.]
35.1   Introduction to Python (Continued)
35.1.2  Python Keywords
Before we discuss Python programming in more detail, we present a list of Python's keywords (Figure 35.3). These words have special meanings in Python and cannot be used as variable names, function names or other objects.
Fig. 35.3 Python keywords.
Python keywords
and
continue
else
for
import
not
raise
assert
def
except
from
in
or
return
break
del
exec
global
is
pass
try
class
elif
finally
if
lambda
print
while
A list of Python keywords can also be obtained from the keyword module. Figure 35.4 illustrates how to obtain the list of Python keywords in interactive mode. [Note: We discuss modules further in Section 35.4.]
Fig. 35.4Printing Python keywords in interactive mode.

Python 2.1 (#15, Apr 16 2001, 18:25:49) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
>>> import keyword
>>> print keyword.kwlist
['and', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while']
>>>

Python is a case-sensitive language. This means that Python treats variable x (lowercase) and variable X (uppercase) as two different variables. Similarly, the statement
Def = 3
is a valid Python statement, but the statement
def = 3
causes a syntax error, because def is a keyword and, therefore, not a valid variable name.
Good Programming Practice 35.1
Using variable or function names that resemble keywords (e.g., variable Def) or Python functions (e.g., list) may confuse the program writer and readers. Avoid using such variable or function names.
Page 1 | 2 | 3
Read additional Python Tutorials
Return to Tutorial Index