Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
25 views

Python Cheat Sheet

Uploaded by

venao
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Python Cheat Sheet

Uploaded by

venao
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

I' python Cheat Sheet cc

Math Power & Logarithmic


exp(x) log(x[, base])
Angular Conversion
degrees(x) radians(x) math.pi
Constants
Number Theoretic logl p(x) log 1 O(x) The mathmatlcal constant of pie
pow(x,y) sqrt(x) = 3.1415.92..• up to the available
ceil(x) copyslgn(x,y) Hyperbofic Functions precision
fabs(x) factorlal(x)
·floor(x) fmod(x,y)
Trigonometric Functions acosh(x) asinh(x) math.e
acos(x) asin(x) atan(x) atanh(x) cosh(x) The mathmatical constant e=
frexp(x) fsum(iterable) 2.718281... up to the available
atan2(y,x) cos(x) hypot(x,y) sinh(x) tanh(x)
isinf(x) isnan(x) precision
sin(x) tari(x)
ldexp(x,i) modf{) trunc0

String Formatting Formattlng Operations


'd' Signed integer decimal 'i' Signed integer decimal 'o' Signed octal value 'u' Obsolete type - It was identical to 'd'
'x' Signed hexadecimal (lowercase) 'X' Signed hexldeclmal (uppercase) 'e' Floating point exponential format (lowercase)
'E' Floating point exponential format {uppercase) 'f' Floating point decimal format 'F' Floating point decimal format'
'g' Floating point format. Uses the lowercase exponential format If the exponent is less than -4 or not less than precision,
otherwise it uses the decimal format
'G' Floating point format. Uses the uppercase exponential format i f the exponent is less than -4 or not less than precision,
otherwise it uses the decimal format
'c' Single character (accepts either Integer or single character string) 'r' S·tring (converts any Python object using repr())
's' String (converts any Python object using strO) '%' No argument ls converted, adds a% character In the end result
-
File Class
Methods Special Methods
Attributes _ new _(cls) _lt (self,
_ other) _init_(self, args)
close() flush() fileno() closed encoding _le_( self, other) _del_(self) _gt (self,_ o�her)
isatty() nextO read([size]) errors mode repr (seln ge (self, other) str (seln
readline ([size]) readllnes([size]) name newlines eq (self, other) cmp (self, other)
xreadllnesO seek(offset[, whence]) softspace =ne=(self, other) =index=(self) =nonzero=(self)
tell() truncate([slze]) _hash_(self) _getattr_{self, nan,e)
write(str) writelines(sequence) _getattribute_(self, name) _setattr_(self, name, attr,)
_delattr_(self, name) _call_(self, args, kwargs)

Random 1 Array Indexes & Slices


a:_[Q,1,2,3,4,S]
Functions Array Methods
b=a[:] Shallow copy of a
all:] [1,2,3,4,SJ
seed([x]) getstate() vonmisesvarlate(mu,kappa) append(x) buffer_info() a[S:] [O, 1,2,3,4]
setstate(state) jumpahead(n) paretovarlate(alpha) byteswap() count(x) a[-2:] [O,1,2,3) len(a) 6
getrandbits(k) randlnt(a,b) welbullvarlate(alpha,beta) extend(lterable) fromfile(f,n) a[l :3] [1,2J a[OJ 0
randrange([start], stopL step] lognormvarlate(mu,slgma) fromllst(llst) fromstrfhg(s} a[Sl -5
- [1,2,3,4]
a[l :1]
cholce(seq) shuffle(xL randon:in normalvarlate(mu, sigma) fromunicode(s) index(x) a[-1] s
sample(population,k) random(} gammevarlate(alpha,beta) lnsert(l,x) pop([iJ) remove(x) a[-21 4
unlform(a,b) trlangular(low,hlgh,mode) gauss(mu,slgma) reverse'() tofile(f) tolist()
l:ietavarlate(alpha,beta) expovarlate(lambd) tostring() tounicode(l
----
- ----
OS SYS
platform Current platforn1
stdln, stdout; stderr File objects for 1/0
verslon_lnfo Python ver5ion Info
OS Variables SYS Variables winver Version number
argv Command lineargs
altsep Alternati.ve separa.tor pardir Parent dJr string
curdir Current dir string
builtin_module_names Linked C modules
check_-interval Signal <;heck frequency
SYS Arg V
pathsep Pat<::h separator
exec_prefix Root directory sys.ar9v[O] fo0.py
defpath Default search path sep Path separator sys.argv[l] bar
devnull Path of null device name name of OS executable Nan1e of Executable
sys.argv[2] -c
exitfunc Exit function name
extsep Extension separator linesep Line separator sys.argv[3] qux
modules Loaded modules
path Search path sys.argv[4] -h

String String Methods


Cllpltal�() center(wldth[, fillchar]) counr{subL start[, endll) Set & Mapping Mapplng Types
decode encode((encodlng[, errors]J) is.llnum()'
len(d) dlkey] d[key]=value
endswlth(suffixL start!, endll) e)(pand�bs((rabslte))
del d(key] key I n d key not In d
find(sub[, startL end]J) formatj•args, "'kwargs) I.alpha()
lter(d) clear() copy() items()
lnd.,,.(sub[, start[, end)]) !$digit() !$lower() isspaa!() lstitle()
�upper() joln(ltt>rable) ljust(wldthL fillchatl) lower()
Set Types ftomkeys(si,qL \laluel} keys()
get(keyL default]) has_key(key)
lstilpl[charsl) partltlon(sep) replace(old, new!, count]) le11(s) x In.< x not In.- lsdlsjolnl(other) lteritems() lterkeys()
rlfnd{sub � start� end)]) rlndei({subl, startL end)]) lssubset(othersJ lssuperset unlon(other_)
l ltervaluesO popltem()
rjust(wldthl, fillcharl) rpa_rtltlon(si,p) rsplltl[sepL maxspllt]J) lntersectlon(other... ) dlfference(other...) pop(key(, default]}
rstripl[charsl) splltl[sep[, maxspllt])) splitllnestlk_,.,pends)) syinmetric_difference(other) copy() �pdate() setdefault(key(, default]}
sfilrtswlth(prefil(L starrL end]]) strlp{Ichars]), swapcase, tllle() lntersectlon _update() dlfference_updateO update((otherl)
transrnte(tableL deletechars]), upper() zfill(width) syinmetric_difference_update() · .a dd(elem) 11aluecs
�numeric() lsdeclmal() remove() dlscard(elem) pop() cle�rO

Date Object
Date Time reptace(lyear,month,day)l tlmetuple()
toordlnalO w�kdayO(l isoweekday()O
Date Formatting
isocalendar()() isoformat{) _nr O_
Time Object ·ct i me{) strlt i meO %a Abbreviated weekday (Mon) 'l!iA Weekday (Monday)
%b Abbreviated rrionth hame (Nov) %8 Month name (November)
replace(l,hourL rnlnutel,,secondt microsetc;,ndl, 12lnfo]II]]) %c Date-<1nd time %d Day (leadlng zeros) (01 to 31)
isoforrnatll _str_O strf1imel) utcoffse1() c:!s1() 12name()
%H 24 hour (leading 2eros)(OO to 23) %1 12 hour (leading zeros)(01 to 12)
%) Day ofy!,!ar (001 tq366) %m Month (01 to 12) 'Mir.I Mioute (00 to59)
Datetime Object %p AM or PM %S Second(OOto617) %U Weeknumberl (00to53)
date() tlmet) t ·lmelZ() roordlnal() weekday() lsoweel\day() isocalendar() %w Weekday2 (0 to 6) %W Week number3 (00 to 53) %x Da(e
replace(lyear{, month(.dayt houri , minute!, secondL mlaosec_ond[ , tzlnfollJ}JIII) %X Time %y Year without c.entury (001099) %Y Year (2016)
astimezone(IZ) u1c_offsetO ds1<) tznameO limetuple() u1crln1erupl e{) %Z T ime zone (EST) %% A literal •%•character(%)
lsoforn,at{) _str_(l ctlme() 5lrftlme{)

Python Cheat Sheet I Resource by: CodeConquest.com


fl"•••••••••••••••••••••••••••••••••••••••••••••••••-. ,- - - -·--------------------·-- I
' len(c) - ite 1ns cou11t Generic O perations on Containers : G� - -
�-i{��t�1;����iy-�� ;;q �- ��;��,;- i���i" �� �;{d ��i���� :
min(c) max(c) sum(c)
:
Nore:For dictionaries and sers,tliese :for idx,val in enumerate(lst ): 1

sorted( C)- list sorted cop_v operations use ke_r"S. -- - - - -- -- - - -- ---- - - - -- - - -- -- - - -- ---- - - ---- - -f
,. • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • ,
val in c - boolean, 1ne1nbership operator in (abse11ce not in) : range ({start,} e,,d [,step]) Integers Sequences :
enumerate (c) - ireraror on ( il1dex, value)
zip(cl,c2___) - iterator on ruples containing ci iten1s at sa1ne index : � start default 0, fin not included in sequence_ pas sig11ed default 1 1

1
range(s)-01234 range(2,12,3)-25811 :
all(c)- True if all c ite1ns evaluated to true, else False : range(3, a)-34 5 6 7 range(20, 5 , -s)-20 15 10 ,
1

-���--��-�-�--!�-��-�!-�!-����-�-����-�����-��--�-������-��-�--t-���•--���-:.�-���----------- : range(len(seq)) - sequence of index of valuesrin seq :


Specific ro ordered sequences co11tai11ers (lisrs, tuples, strings, byres... ) • t range provides an i11u1111rable sequence of int consr 11cred as needed •
reversed( c) � i11versecl ireraror c* s� duplicate c+c2� concatenate ';::::::::::::::::::: ·:::::::::::::::::::::: ·'
(ide11tifier )
c
-- _ index ___
i mport cop y
( l'al) - position c _ count ( val) - even rs count
------------------------------------------------------------------------------··--------------------
!
fU11ctio11 na1ne
1;am�d p �ran1eters
Function Definition '

, copy . copy(c) - shallow copy of container def fct ( x, y, z ) :


t
c_opr,;. ��e.P�:'�� cJ .:-: �e�� :,0,PJ.'._ �f_C_?l!t�!e!· . • •. • • • • • • • _ _ • _ • . • • _.,. t
,..--------------------------------------------------
� ,
n II n documentatio n n 11 11

ti 1nodify original list Operations on Lists --• # staten1e11ls block, res con1p11tc1tio11, etc.
1st_ append ( ,•al) add ite111 at e11d / return res ◄- result value of the call, if no con1puted
add se que11ce of ite111s at e11cl result to return: return None
1st_ extend (seq) ii, paran1eters and all
1st_ insert (id..>.·, l'al) i11sert ite1n at i11dex variables of this block exist only in the block and during the function
1st_ remove (1 1al) re111ove first item witl1 value ,,al call (think of a "black box')
1st_ pop ([icl\ ·})-> 11al11e re111ove & retw·n iten1 at index idx (default last) Advanced: def fct (x, y , z, *args, a=3, b=S, **kwargs):
1st_ sort() 1st _ reverse () sort I reverse liste in place
""·-----------·-·-----·-· �·----·------······-----
�------------·----·-- ·---·-------------·------------
:- : -- - : - - ., - - :--- - - -'
, *n,gs vnrinble positionnl a1g11111ents (-tuple), defnulr values,
* */..,,va1gs l'ariable na111ed a1gu111enrs (--J diet)
' ---------------------- - ---, -------------------------�, ·----------------------------------------,
Boo Iean Log1c • •'
, Statements Blocks , 111od11le truc¢:::>file true. PY Modules/Names Imports :
: Co1n1)arators: < > <= >= == ! = : from monmod import noml,nom2 as fct •
• (boolean resulrs) < > * pare11.t stc1te111e11t: • -+direct acces to na,nes1 rena111ing 111ith as :
I
both sinntlra- - stc1te111e11t block 1 ... I .
import monmod -+acces via monmod. nom1 ...

--=
, a and b logical arid •
: :
, -neously = •
• � Yb n1odules and packa.ges searched in python parh (cf sys. path)
1

one or other ...


pare11t state1ne11.t:
�----------------------------------------'
------------------------------------------,
: a or b locical 0
or
or borh stare,n.enr block e.xecured on�y Conditional Statement
I
state1ne11.•t DlocKl ... if a co11clirio11 is tr1t, e
: Yb pitfall : and and or ren1rn value of a or
.=..

• of b (under shorrcut evaluation).
I if logical coriditio,i :
, ⇒ ensure that a anrl b are booleans.
11ext state1n.e1it rifter block 1 ----,1 state1nerits block
, not a
I
logical 11ot
' True Can go with several elifi, elif... and only
: False } True a11d False coiistants � configure ediror to inserr 4 spaces in one final else. Only the block of first true if age<=18:
place of an indentarion rab.
,�-------------------------- � ------------------------'�
,
�---------------------------------------------------- condition is executed.
state="Kid"
elif age>65:
: floating nu111bers ... approxilnatecl values
� angles in radians Maths � with a boolean var x: state="Retired"
else:
'Operators:+ - * / / / % ** from math import sin, pi... if x==True: <=> if x:
state="Active"
:Priority( ... ) x + t t ab
sin( pi/4) ➔0. 707... ,-----------------------------------------
....
if x==False: <=> if not x:
-----------------------------------------
, integer+ +re1naincler cos(2*pi/ 3) ➔ -0.4999... Sigi1ali_ng an error: Exceptions on Errors
, @ � 1natrix x pyrhon3.5+numpy sqrt ( 81) 9. 0 4
.f raise Ex. ceprron(...) Errors processing:
I
, (1+5. 3) *2➔12.6 log (e**2) ➔ 2. 0 error try:
:abs(-3. 2) ➔3. 2 ceil(12.5) ➔ 13 normal 0 --� 1iorrrictl procesising block
:round(3.57,1) ➔3.6 floor(12.5) ➔ 12
raiser-......_.J error
.
processing
.
rocess1n raise except E.xceptio1i as e:
, pow( 4, 3) ➔64. 0 : modules math, statistics, random, � error processi,ig block
: ti} usual p1iorities
decimal, fractions, numpy, etc. (cf doc) 11 finally block for final processing in all cases.
-----------------------------------------------------' ------------------------------------------
- -------------------------------------------------- ------------------------------------------ �
a
._.
Conditional Loop Statement
staten·1ents block executecl fts lo1tg fts � : stc1te1 rie1its block v:ecuted for eftc/1 Iterative Loop Statement :
conclitio,i is tru e : : ite1ri of a co,itainer or iterator . :
.--�
for var in sequerice :
#• • • • • • • • • • • • • • L- • • • • • t

while coriditiori logique : •


C) ,....,_..,.. I
.-S1 Loop Control . ,
-� -I staterrie1its block _ no .-t..::-,-;:>-
,_, finish :
:
......,... b r e a� i,ru,i �di at e ex it : - -� s taferrie11,fs block '.=
_
continue ne r iterati on : .......................................................................................... :
.___
• � else block for nor1nal loop e.xit. I Go over seque11ce's valt1es
'-S-, ..................................................................................... t
.:::;
'& s = OJ 1111fla
1

. . . l'1<:aflo11
. � b,I". • _ _ _ _ _ _ _ _ _ _ _ _ _ _ T,• _ _ _ _ ,
i = 1
I
e1 ore tIte loop
� . ••

:
.
,
_
- Some text } 1111rzal1zatro11s before the loop
- '---
s
• • =
co11dzt1011 ,vzth a least one variable value (here i)
11 11 • • • • •

� while
. cnt 0
�•
--'
Algo: �•
s = s + i** 2
� i <= 1 0 0: i= lOO loov, variable, assig111ne11t 111a11aged by for state1ne11t
for 1c"1 in s:
:•
i = i + 1 l'b 111ake co11ditio11 variable change ! -
_ , ,2 1

..C)
� 5 L..,.; l if c == "e " : Algo: count >:
-�
cnt = cnt + 1 g.
- ------ - --- ------- -------- -------------------Display
-----
print (" sum: " , s) i=l : niunber of e
, - • - • • • - • • • • • • - - - - - - - - - • • - - - - - - - - - - • • - - • - - • - - - - - - - - _.
' ... pri·nt ("found", cnt, " ' e ' " ) ,·,,, tlte s11·1·11g. _Q
,.............

• print ( 11 v= " 3 " cm •· " x " " y +4 ) ' 1oop on d.1ct;set ¢=> 1oop on keys sequences _;:,--,
:';::l

f f f f f f

--------------------------------------------------------------------------------------------------------
use slices to loop on a subset of a sequence s
I

� ��-- - -t-✓�

I "8
: ite1ns to display : literal values, variables, expressil11s Go over sequence's i11dex �
print options: □ 1noclify ite111 at index §
□ access ite1ns around iI1dex (before / after) :='.
□ sep=
□ end= \n 11
ite1ns separator, default space
II

11
II

e11d of print, default new line


I
1st = [ 11 , 18, 9 , 12 , 23 , 4 , 17 ] ;E

pri11t to file, default sta11dard output Jg
lost = [ ]
□ file=f for idx in range ( len (1st ) ) : Algo: li111it values greater "O
val = 1st [ idx] r'1a11 15, 1ne111orizi11g 0
s = input ( " Instructions : " ) Input if val> 15: of losr values. �f)

f!! input always rett1r11s a stri11g, co11vert it to required type


"ii1I
lost . append (val )
(cf. boxed 011 tl1e other side).
' , _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ , print ( "modif : 11 , lst , 11 -lost : " , lost)
Conl'ersions lst [idx] = 15
1
---------------------------- - -- -- - - - - -- - - - - - ----- - -- - - - - - - - - - -- - - - - - -- - - - ------ - - - - -- - - - - - -- - �
.,,.
for variables, fu11ctio11s. Identifiers ' 1 { type e:x.pressio1i) Conversions •
,nodules, classes. . . 11an1es
int ( ,,15 ,, ) � 15
int ( "3£ " , 1 6) � 63 can specif.Y integer 1no11ber base in 2"d para111erer
a... zA...z_ followed by a... zA...z_o ... 9
□ diacritics allowed bt1t should be avoided int (15 . 56) � 15 tr1,11icate deci1rial pctrt
□ language keywords forbidden float ( "-11 . 24e8 ") � -1124000000. 0
□ lower/UPPER case discri111iI1atio11 round (15 . 56, 1 ) � 15 . 6 ro1uidi11g to 1 deci11ial (0 cleci11lctl � i11,teger 11,uniber)
o a toto x7 y_max BigOne bool (x) False for 1u,tll x, enipty co1itai1ier x , None x or False x ; True for otl1er x
-�-----------------------------
-------------- ------ ---------,,
-
® ,Sy and for str (x) � "... " represe11tc1tio11 st rhig of x for displa_y (cf fornlati11g 011 tl1e brick)
- Variables assignment
chr (64) � '@ ' ord ( ' @ ' ) � 64 code H cl1ar
repr (x) � "... " literctl represe1itati.011. sni1ig of x
1 ) evaluation of righr side e,\pression value
2) assig11111e11r in order H! ifl, lefr side 11an1es bytes ( [ 72, 9 , 64 ] ) � b 'H\t@ '
1.1 assignn1ent ¢.? bincling of a 11a111e with a value list ( "abc ") � [ ' a ' , 'b ' , ' c ' ]
x=l . 2+8+sin {y) dict ( [ (3 , "three " ) , (1 , "one ") ] ) � { 1 : ' one ' , 3 : ' three ' }
a=b=c = O assign111ent to sa111e value set ( [ "one " , " two " ] ) � { ' one ' , ' two ' }
y , z , r= 9 . 2 , - 7 . 6 , O 1111tltiple assig11111ents separator str a11d seque1ice of str � assen,bled str
a, b =b , a values S1vap ' : ' . join ( [ ' toto ' , ' 12 ' , 'pswd ' ] ) � ' toto : 1 2 : pswd '
a , *b =seq } �111packi11g of sequence in str splitted 011 11l'l1itespc1ces � list of str
_
* a , b=seq 1te111 and hsr ''words with spaces " . spli t () � [ ' words ' , 'with ' , ' spaces ' ]
and str splitted 011 separario1i str � list of str
x+= 3 i11cre111enr x=x+3 *=
") � [ ' 1 ' , ' 4 ' , ' 8 ' , ' 2 ' ]
¢=>

x-=2 decre111enr x=x-2


¢=> I= "1 , 4 , 8, 2 " . spl i t ( ",
x=None « u11defi11ed » consra,,r value %= seque1tce of 01te t_ype � list of a11otl1er (ype ( via conlprel1e1tsio11. list)

-
del x re1110Pe 11a111e x '
- - -- -
[int (x) £or x in ( ' 1 ' , ' 29 ' , ' -3 ' ) ] � [1 , 29 , -3]
- - --- - - - ---- -- -� -- - - - - ,
- -------------------------------------------------- ------------------------------------------ �
a
._.
Conditional Loop Statement
staten·1ents block executecl fts lo1tg fts � : stc1te1 rie1its block v:ecuted for eftc/1 Iterative Loop Statement :
conclitio,i is tru e : : ite1ri of a co,itainer or iterator . :
.--�
for var in sequerice :
#• • • • • • • • • • • • • • L- • • • • • t

while coriditiori logique : •


C) ,....,_..,.. I
.-S1 Loop Control . ,
-� -I staterrie1its block _ no .-t..::-,-;:>-
,_, finish :
:
......,... b r e a� i,ru,i �di at e ex it : - -� s taferrie11,fs block '.=
_
continue ne r iterati on : .......................................................................................... :
.___
• � else block for nor1nal loop e.xit. I Go over seque11ce's valt1es
'-S-, ..................................................................................... t
.:::;
'& s = OJ 1111fla
1

. . . l'1<:aflo11
. � b,I". • _ _ _ _ _ _ _ _ _ _ _ _ _ _ T,• _ _ _ _ ,
i = 1
I
e1 ore tIte loop
� . ••

:
.
,
_
- Some text } 1111rzal1zatro11s before the loop
- '---
s
• • =
co11dzt1011 ,vzth a least one variable value (here i)
11 11 • • • • •

� while
. cnt 0
�•
--'
Algo: �•
s = s + i** 2
� i <= 1 0 0: i= lOO loov, variable, assig111ne11t 111a11aged by for state1ne11t
for 1c"1 in s:
:•
i = i + 1 l'b 111ake co11ditio11 variable change ! -
_ , ,2 1

..C)
� 5 L..,.; l if c == "e " : Algo: count >:
-�
cnt = cnt + 1 g.
- ------ - --- ------- -------- -------------------Display
-----
print (" sum: " , s) i=l : niunber of e
, - • - • • • - • • • • • • - - - - - - - - - • • - - - - - - - - - - • • - - • - - • - - - - - - - - _.
' ... pri·nt ("found", cnt, " ' e ' " ) ,·,,, tlte s11·1·11g. _Q
,.............

• print ( 11 v= " 3 " cm •· " x " " y +4 ) ' 1oop on d.1ct;set ¢=> 1oop on keys sequences _;:,--,
:';::l

f f f f f f

--------------------------------------------------------------------------------------------------------
use slices to loop on a subset of a sequence s
I

� ��-- - -t-✓�

I "8
: ite1ns to display : literal values, variables, expressil11s Go over sequence's i11dex �
print options: □ 1noclify ite111 at index §
□ access ite1ns around iI1dex (before / after) :='.
□ sep=
□ end= \n 11
ite1ns separator, default space
II

11
II

e11d of print, default new line


I
1st = [ 11 , 18, 9 , 12 , 23 , 4 , 17 ] ;E

pri11t to file, default sta11dard output Jg
lost = [ ]
□ file=f for idx in range ( len (1st ) ) : Algo: li111it values greater "O
val = 1st [ idx] r'1a11 15, 1ne111orizi11g 0
s = input ( " Instructions : " ) Input if val> 15: of losr values. �f)

f!! input always rett1r11s a stri11g, co11vert it to required type


"ii1I
lost . append (val )
(cf. boxed 011 tl1e other side).
' , _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ , print ( "modif : 11 , lst , 11 -lost : " , lost)
Conl'ersions lst [idx] = 15
• • • � �---------------------------------------------------------�
Base Types �' orderecl seqt1e11ces, fast iI1dex access, repeatable values
... ... •• .... 4, ••

intege,� float, boolean, sn·ing, b_ytes ■ Container Typ�s


int 783 0 -192 ObOlO Oo642 OxF3 , list [ 1 , 5 , 9 ] [ " x " , 11 , 8 . 9 ] [ "mot " ] [i ]
null binary octal ltexa � tuple ( 1 , 5 , 9 ) 1 1 , " y" , 7 . 4 ( " mot " , ) (l)
float 9 .23 O . O -1 . 7,e-; 6, /
Non 111odifiable values (inu11utables) � eJ.pression with just co111as -+ tuple
I

bool True False x10·


6 1
: � st r bytes (ordered sequences of chars I bytes)
I 11 · 11
I
str
key co11tai11ers, 110 a prio, i. order, fast key acces, eacl1 key is u11ique
I " One\nTwo" Multiline string: b" "
: ■
escaped n'ew' line
I
I " " " X\tY\tZ
I
I ' I\ '
';-I
m ' 1 \t2\t3 " " 11
y
I
dictionary die t { " key " : 11 value " } dict (a=3 , b=4 , k= " v" ) {}
escaped ' escaped tab (key/value associations) { 1 : " one 11 , 3 : 11 three" , 2 : " two" , 3 . 1 4 : " n" }
bytes b"toto\xfe\ 775"
�"--y---..1
collection set { " keyl " , 11 key2 " } {1, 9, 3, 0} set d )
I
---------- - ltexadeci,nal octal
- - - --- - - .. .... - - ----- - ------ - - - - - -------------- - ----- ------ - -------- - -- -
ti i1111nutables , � keys=ltashable values (base types. i111111utables... ) frozenset i1111nutable set e1npty 1

You might also like