Skip to Content
Python Pocket Reference
book

Python Pocket Reference

by Mark Lutz
November 1998
Beginner
80 pages
1h 14m
English
O'Reilly Media, Inc.
Content preview from Python Pocket Reference

Statements and Syntax

Syntax Rules

Rules for writing Python programs.

Control flow

Statements execute one after another, unless control-flow statements are used (if, while, for, raise, calls, . . . ).

Blocks

Blocks are delimited by indenting all their statements the same amount with spaces or tabs. A tab counts for enough spaces to move the column to a multiple of 8.

Statements

Statements end at the end of a line but may continue over multiple lines if the prior line ends with a \, or an open ( ), [ ], or {} pair, or an open triple-quoted string. Separate statements with a semicolon (;) if more than one on a line.

Comments

Comments start with a # (not in a string constant) and span to the end of the line.

Documentation strings

If a function, module file, or class begins with a string constant, it’s stored in the object’s __doc__ attribute.

Name Rules

Rules for user-defined names in programs.

Format

User-defined names start with a letter or ‘_’, followed by any number of letters, digits, or ‘_’s.

Reserved words

User-defined names cannot be the same as any Python reserved word (listed in Table 1-11).

Case sensitivity

User-defined names and reserved words are always case- sensitive: SPAM and spam are different.

Unused tokens

Python does not use characters @, $, or ?, though they may appear in string constants.

Creation

User-defined names are created when assigned, but must exist when referenced.

Table 1-11. Reserved Words

and

assert

break

class

continue

def

del

elif

else

except

exec

finally

for

from

global

if

import

in

is

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Python Pocket Reference, 5th Edition

Python Pocket Reference, 5th Edition

Mark Lutz

Publisher Resources

ISBN: 1565925009Catalog PageErrata