Show Menu

Python 3 Beginner's Reference Cheat Sheet by

Python 3 Beginner's reference
python     programming     beginner     scripting     python3     reference

Operators

Assignment
=
Arithmetic
+, -, *, /, %
Comparison
>, >=, <, <=, ==, !=
Logical
not, and, or

String operations (string s)

s.cou­nt(­sub­str­ing)
Count occurences
s.fin­d(s­ubs­tring)
Index of first occurence
s.joi­n(s­equ­ence)
Concat­enate sequence
s.spl­it(­[de­lim­iter])
Split into list

List operations (list l, element e)

l.app­end(e)
Add e
l.rem­ove(e)
Remove e
l.pop(e)
Remove and return e
l.cou­nt(e)
Count occurences
l.rev­erse()
Reverse l
l.sort()
Sort l

Dictionary operations (dict d, key k)

d.cle­ar()
Clear d
d.get(k)
Return d[k]
d.keys()
Return keys in d
d.val­ues()
Return values in d
d.ite­ms()
Return key-value pairs in d
 

File operations (file f)

f = open(p­ath)
Open f
f.read()
Read f
f.rea­dli­ne()
Read line from f
f.rea­dli­nes()
Return list of lines in f
f.wri­te(s)
Write s to f
f.clo­se()
Close f

In-built functions

int(), float(), str(), bool(­)...
Type casting
len(d­ata)
Length
min(v­alu­es), max(v­alues)
Minimum / Maximum
pow(x,y, [z])
X to the power Y [mod Z]
range­(start, stop, [step])
Ordered list
input(), print()
Console Input/­Output
filte­r(f­unc­tion, array)
Filter array
map(f­unc­tion, array)
Map function onto array
id(ob­ject)
Unique object ID
round(n, [x])
Round n [x decimal places]

Module import

import module
from module import submodule
 

Control Flow

if(cond): <co­de> else: <co­de>
If-else
if(co­nd1): <co­de> elif(c­ond1): <co­de> else: <co­de>
If-eli­f-else
for i in range(­[st­art], stop, [step]): <co­de>
For loop over range
for i in items: <co­de>
For loop over iterable
while­(co­ndi­tion): <co­de>
While loop
break
Exit first enclosing loop
continue
Skip to next iteration

Useful standard library modules

math, numpy, scipy
Math
matpl­otlib
Graph plotting
random
Random generators
datetime
Date and time
timeit
Perfor­mance
re
Regular expres­sions
os
OS intera­ction
sys
stdin, stdout, stderr, version
urllib
Internet access
zlib
Data compre­ssion

Object­-or­iented

class Person:
Class definition
x = Person­(age, height)
Object creation
x.age
Field access
x.bir­thd­ay()
Method access

Download the Python 3 Beginner's Reference Cheat Sheet

1 Page
//media.cheatography.com/storage/thumb/paul-benn_python-3-beginner-s-reference.750.jpg

PDF (recommended)

Alternative Downloads

Share This Cheat Sheet!

 

Comments

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets