Python Cheat Sheet
Functions
float()
converts variable into a floating point number
int()
converts variable into an integer number
str()
converts variable into a sting
len()
returns the length of the input
min()
returns smallest item
max()
returns largest item
print
prints the input to the console
range(stop)
returns the range up to but not including the input
range(start, stop)
returns the range from the start input, up to but not including the
stop input
range(start, stop, step)
returns the range as above but only includes increments
of the
step input
raw_input()
requests input from the user
x = raw_input()
requests input from the user and assigns to variable
Boolean Operations
x or y
looks at both variables, a match on either or returns True
x and y
looks at both variables, a match on both returns True
not x
a nonmatch returns True
Comparisons
<
less than
<=
less than or equal to
>
greater than
>=
greater than or equal to
==
equal to
!=
not equal to
Is
identity matches
Is not
identity does not match
Number Operations
+
sum
subtract
*
multiply
/
divide
%
remainder
**x
to the power of x
Sequence Operations
x in s
if item x is found in item s returns True