Python 2.6 Cheatsheet (2008).pdf

(96 KB) Pobierz
711533414 UNPDF
Python 2.6 Cheatsheet
Statements
import module
import module as alias
import module.member
from module import member, ‥
print expr, ‥
variable = expr
del variable
if condition :
suite ‥
elif condition :
suite ‥
Literals
42 1e6 3.14 1+3j 0x1F 0b10
'String' “string” '''docstring'''
r'Raw' b'Bytes' u'Unicode'
[] [ expr , ] () ( expr , )
{} { expr : expr , }
tuple
type
dict
list
object
set
frozenset
slice
None False True Ellipsis
Operators
` expr `
x[i:j:k]
x [i] x[key]
x . attribute
x ** y
~ x
+ x , - x
* / %
+ -
<< >>
x & y
x ^ y
x | y
< <= > >=
<> != ==
x in iter
x not in iter
not x
and
or
lambda x , :
else :
suite ‥
for variable in iterable :
suite ‥
while condition :
suite ‥
break
continue
def a_function( arg,
Functions
):
abs
bin
chr
coerce
cmp
dir
divmod
eval
file
hash
hex
input
max min
oct
open
ord
pow
raw_input
repr
round
sum
unichr
'''Docstring.'''
global variable
suite ‥
return expr
class AClass(object):
'''Docstring.'''
suite
def __init__(self, arg,
):
Sequence functions
suite ‥
all
any
apply
enumerate
filter
iter
len
map
next
range
reduce
reversed
sorted
xrange
zip
try :
suite ‥
except expr ,
:
expr
expr if cond else expr
[ x for x in iterable if cond ]
( x for x in iterable if cond )
suite ‥
finally :
suite ‥
assert expr
raise exception
exec expr
pass
with expr as variable:
suite ‥
def a_generator( arg , ):
'''Docstring.'''
suite ‥
yield expr
Common attributes
__doc__ Doc string
Introspection functions
__dict__
Module, class or
instance namespace
callable
classmethod
compile
delattr
execfile
getattr
hasattr
globals
id
intern
isinstance
issubclass
locals
property
reload
setattr
staticmethod
super
vars
__file__
pathname of module
(if available)
__name__
module, class, or
function name
Types
bool
buffer
complex
float
int
long
str
unicode
Python 2.6 Cheatsheet
String methods
capitalize ()
center (width[, fillchar])
count (sub[, start[, end]])
decode ([encoding[, errors]])
encode ([encoding[, errors]])
endswith (suffix[, start[, stop]])
expandtabs ([tabsize])
find (sub[, start[, stop]])
format (format_string, *args,
**kwargs)
index (sub[, start[, stop]])
isalnum ()
isalpha ()
isdecimal () †
isdigit ()
islower ()
pop ([i]) ‡
remove (x) ‡
reverse () ‡
sort (
[cmp[, key[,
reverse]]]) ‡
‡ Lists/mutable sequences only
Useful modules
collections
decimal
datetime
doctest
io
math
os
os.path
string
sys
re
time
Dictionary methods
Exceptions
Exception ArithmeticError
AssertionError AttributeError
BaseException EOFError
EnvironmentError
FloatingPointError
GeneratorExit IOError
ImportError IndentationError
IndexError KeyError
KeyboardInterrupt
LookupError MemoryError
NameError NotImplemented
NotImplementedError
OSError OverflowError
ReferenceError RuntimeError
StandardError StopIteration
SyntaxError SystemError
SystemExit TabError
TypeError UnboundLocalError
UnicodeDecodeError
UnicodeEncodeError
UnicodeError
UnicodeTranslateError
ValueError ZeroDivisionError
isnumeric () †
isspace ()
istitle ()
isupper ()
† Unicode only
clear ()
copy ()
fromkeys (seq[,
value])
get (key[,
default])
has_key (key)
items ()
iteritems ()
iterkeys ()
itervalues ()
keys ()
pop (key[,
default])
popitem ()
setdefault (
key[, default)
update ([other])
values ()
join (seq)
ljust (width[, fillchar])
lower ()
lstrip ([chars])
partition (sep)
replace (old, new[, count])
rfind (sub[, start[, stop]])
rindex (sub[, start[, stop]])
rjust (width[, fillchar])
rpartition (sep)
rsplit (sep[, maxsplit])
rstrip ([chars])
splitlines ([keepends])
split (sep[, maxsplit])
startswith (suffix[, start[, stop]])
strip ([chars])
swapcase ()
title ()
translate (table[, deletechars])
upper () zfill (width)
File object methods
close ()
closed
encoding
errors
fileno ()
flush ()
isatty ()
mode
name
newlines
next ()
read ([size])
readinto
readline ([size])
readlines (
[sizehint])
seek (offset[,
whence])
softspace
tell ()
truncate ([size])
write (str)
writelines (seq)
xreadlines ()
Warnings
Warning DeprecationWarning
FutureWarning
ImportWarning
PendingDeprecationWarning
RuntimeWarning
SyntaxWarning
UnicodeWarning
Set/Frozenset methods
issubset (oth)
issuperset (oth)
pop (elem) §
remove (elem) §
union (oth)
update (oth) §
intersection_update (oth) §
symmetric_difference (oth)
symmetric_difference_update
(oth) § § Set type only
UserWarning
String constants
ascii_letters ascii_lowercase
ascii_uppercase
digits
hexdigits
letters
lowercase
octdigits
Sequence methods
append (x) ‡
count (x)
extend (t) ‡
index (x)
insert (i, x) ‡
add (elem) §
clear () §
copy ()
difference (oth)
discard (elem) §
isdisjoint (oth)
printable
punctuation
uppercase
whitespace
Zgłoś jeśli naruszono regulamin