Sie sind auf Seite 1von 1

Python 3 Beginner's Reference Cheat Sheet

by paul_benn via cheatography.com/29548/cs/8690/

Operators In-built functions Control Flow (cont)

Assignment = int(), float(), str(), Type casting continue Skip to next iteration
bool(​) ...
Arithmetic +, -, *, /, %
Useful standard library modules
len(d​ata) Length
Comparison >, >=, <, <=, ==, !=
min(v​alu​es), Minimum / math, numpy, Math
Logical not, and, or
max(v​alues) Maximum scipy

String operations (string s) pow(x,y, [z]) X to the power Y matpl​otlib Graph plotting

[mod Z] random Random generators


s.cou​nt(​sub​str​ing Count occurences
range​(start, stop, Ordered list
) datetime Date and time
[step])
s.fin​d(s​ubs​tring) Index of first timeit Perfor​mance
occurence input(), print() Console
re Regular expres​sions
Input/​Output
s.joi​n(s​equ​ence) Concat​enate
filte​r(f​unc​tion, Filter array os OS intera​ction
sequence

s.spl​it(​[de​lim​ite Split into list


array) sys stdin, stdout, stderr,

map(f​unc​tion, Map function onto version


r])
array) array urllib Internet access

List operations (list l, element e) id(ob​ject) Unique object ID zlib Data compre​ssion

l.app​end(e) Add e round(n, [x]) Round n [x


decimal places] Object​-or​iented
l.rem​ove(e) Remove e
class Person: Class
l.pop(e) Remove and return e
Module import definition
l.cou​nt(e) Count occurences
import module x = Person​(age, Object
l.rev​erse() Reverse l height) creation
from module import submodule
l.sort() Sort l x.age Field access

Control Flow x.bir​thd​ay() Method


Dictionary operations (dict d, key k) access
if(cond): <co​de> else: If-else
d.cle​ar() Clear d <co​de>

d.get(k) Return d[k] if(co​nd1): <co​de> If-eli​f-else

d.keys() Return keys in d elif(c​ond1): <co​de>


else: <co​de>
d.val​ues() Return values in d
for i in range(​[st​art], For loop
d.ite​ms() Return key-value pairs in d
stop, [step]): <co​de> over
range
File operations (file f)
for i in items: <co​de> For loop
f = open(p​ath) Open f over
iterable
f.read() Read f
while​(co​ndi​tion): While loop
f.rea​dli​ne() Read line from f
<co​de>
f.rea​dli​nes() Return list of lines in f
break Exit first
f.wri​te(s) Write s to f enclosing
loop
f.clo​se() Close f

By paul_benn Published 17th December, 2016. Sponsored by CrosswordCheats.com


cheatography.com/paul-benn/ Last updated 10th August, 2016. Learn to solve cryptic crosswords!
Page 1 of 1. http://crosswordcheats.com

Das könnte Ihnen auch gefallen