Professional Documents
Culture Documents
This appendix summarizes the most commonly-used Python language features in the textbook.
Hello, World.
import stdio
INTRO TO P ROGRAMMING
1. Elements of Programming
2. Functions
3. OOP
4. Data Structures
R ELATED B OOKSITES
WEB R ESOURCES
FAQ
Code
Errata
Appendices
Strings.
Integers.
Floating-point numbers.
converted by W eb2PDFConvert.com
Booleans.
Comparison operators.
Common functions.
Type conversion.
converted by W eb2PDFConvert.com
if-elif-else statements.
if income
elif income
elif income
elif income
elif income
elif income
elif income
else:
<
<
<
<
<
<
<
0:
8925:
36250:
87850:
183250:
398350:
400000:
rate
rate
rate
rate
rate
rate
rate
rate
=
=
=
=
=
=
=
=
0.00
0.10
0.15
0.23
0.28
0.33
0.35
0.396
break statements.
converted by W eb2PDFConvert.com
while True:
x = 1.0 + 2.0*random.random()
y = 1.0 + 2.0*random.random()
if x*x + y*y <= 1.0:
break
Arrays.
a = stdarray.create1D(n)
...
for i in range(n):
stdout.writeln(a[i])
...
for element in a:
stdout.writeln(element)
Array operations.
converted by W eb2PDFConvert.com
Two-dimensional arrays.
a = stdarray.create2D(rowCount, colCount)
...
for i in range(rowCount):
for j in range(colCount)):
stdio.writeln(a[i][j])
...
for row in a:
for element in row:
stdio.writeln(element)
converted by W eb2PDFConvert.com
converted by W eb2PDFConvert.com
Functions.
converted by W eb2PDFConvert.com
Modules.
converted by W eb2PDFConvert.com
converted by W eb2PDFConvert.com
Defining a class.
converted by W eb2PDFConvert.com
Creating an object.
Using an object.
p = c1.potentialAt(.20, .50)
Special methods.
converted by W eb2PDFConvert.com
Copyright 20002015 by Robert Sedgewick, Kevin Wayne, and Robert Dondero. All rights reserved.
converted by W eb2PDFConvert.com