Está en la página 1de 1

Python 3 Beginner's Reference Cheat Sheet

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


Operators

In-built functions

Assignment

Arithmetic

+, -, *, /, %

Comparison

>, >=, <, <=, ==, !=

Logical

not, and, or

Type casting

continue

len(data)

Length

Useful standard library modules

min(values),

Minimum /

math, numpy,

max(values)

Maximum

scipy

pow(x,y, [z])

X to the power Y

matplotlib

Graph plotting

[mod Z]

random

Random generators

datetime

Date and time

timeit

Performance

Input/Output

re

Regular expressions

Filter array

os

OS interaction

sys

stdin, stdout, stderr,

int(), float(), str(),

String operations (string s)

range(start, stop,

)
Index of first

s.find(substring)

occurence

s.split([delimite

input(), print()

sequence

filter(function,

Split into list

array)

r])
List operations (list l, element e)
l.append(e)

Add e

l.remove(e)

Remove e

l.pop(e)

Remove and return e

l.count(e)

Count occurences

l.reverse()

Reverse l

l.sort()

Sort l

Ordered list

[step])

Concatenate

s.join(sequence)

Console

array)

array

urllib

Internet access

id(object)

Unique object ID

zlib

Data compression

round(n, [x])

Round n [x
decimal places]

class Person:

import module
from module import submodule

if(cond): <code> else:

Return d[k]

if(cond1): <code>

d.keys()

Return keys in d

elif(cond1): <code>

d.values()

Return values in d

else: <code>

d.items()

Return key-value pairs in d

for i in range([start],

For loop

stop, [step]): <code>

over

for i in items: <code>

For loop

Read f

f.readline()

Read line from f

f.readlines()

Return list of lines in f

f.write(s)

Write s to f

f.close()

Close f

x = Person(age,

Object

height)

creation

x.age

Field access

x.birthday()

Method
access

If-else

d.get(k)

f.read()

Class
definition

<code>

Open f

Object-oriented

Module import

Clear d

f = open(path)

version

Map function onto

d.clear()

File operations (file f)

Math

map(function,

Control Flow
Dictionary operations (dict d, key k)

Skip to next iteration

bool() ...

Count occurences

s.count(substring

Control Flow (cont)

If-elif-else

range
over
iterable

while(condition):

While loop

<code>
break

Exit first
enclosing
loop

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

También podría gustarte