Show Menu
Cheatography

Python Overview_V1 Cheat Sheet (DRAFT) by

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Data Types

Integer
-256, 15
Float
-253.23, 1.253e-10
String
"­­He­l­l­o", 'Goodbye', "­­"­"­­Mul­­ti­l­i­ne­­"­­"­"
Boolean
True, False
List
[ value, ... ]
Tuple
( value, ... )1
Dictionary
{ key: value, ... }
Set
{ value, value, ... }2
1 Parent­­heses usually optional
2 Create an empty set with set()

Statements

if [Bedin­gung]:
sta­te­ments
elif [Bedin­gung]:
sta­te­ments
While Loop
while expre­­ssion
For Loop
for var in colle­­ction:
sta­te­ments
Counting For Loop'
for i in range(start, end [ step]
 

Functions (aka Operat­ions)

len(s)
length of s
s[i]
ith item in s (0-based)
s[s­tart : end]
slice of s from start (included) to end (excluded)
x in s
True if x is contained in s
x not in s
True if x is not contained in s
s + t
the concat­­en­ation of s with t
s * n
n copies of s concat­­enated
sorted­(s)
a sorted copy of s
s.in­d­ex­­(i­tem)
position in s of item
s.up­per()
uppercase copy of s
s.lo­wer()
lowercase copy of s
s.re­p­la­­ce(­­old, new)
copy of s with old replaced with new
s.split( delim )
list of substrings delimited by delim
See also http:/­­/d­o­c­s.p­­yt­­ho­n.o­r­g­/l­­ibr­­ar­y­/­st­­dty­­pe­s.h­t­m­l#­­str­­in­g­-­me­­thods