Шпаргалка по Python3 - Python 3 для ...
Mmento v1.2.2
?2012-2013 - Laurent Pointal
Licence Creative Commons Attribution 2
ѧ٧ӧ ڧ
integer, float, boolean, string
int
float
bool
str
783
0
-192
9.23 0.0
-1.7e-6
10-6
True False
"One\nTwo" 'I\'m'
֧֧ӧ ܧ
ާߧԧߧ
ߧ֧ڧ٧ާ֧ߧ֧ާѧ, է֧ߧߧѧ
ݧ֧էӧѧ֧ݧߧ ڧާݧ
str
dict {"key":"value"}
{}
{1:"one",3:"three",2:"two",3.14:""}
ݧӧѧ
ӧ֧ӧڧ ާ֧اէ ܧݧѧާ ٧ߧѧ֧ߧڧާ
set {"key1","key2"}
. ާѧڧӧѧߧڧ ߧ էԧ ߧ էݧ ҧݧ֧ ߧܧԧ ܧߧݧ
ڧݧ٧ۧ ѧӧߧ֧ߧڧ (==, !=, , ), էѧڧ ݧԧڧ֧ܧڧ ֧٧ݧѧ
bool
ڧݧ٧֧ ܧѧاէ ݧ֧ާ֧ߧ
list("abc")
['a','b','c']
ݧ֧էӧѧ֧ݧߧ
dict([(3,"three"),(1,"one")])
":".join(['toto','12','pswd'])
֧էڧߧѧ ܧ
"words with
lst=[ 11,
ݧاڧ֧ݧߧ ֧
ڧѧ֧ݧߧ ֧
0
-6
1
-5
'toto:12:pswd'
['words','with','spaces']
"1,4,8,2".split(",")
['1','4','8','2']
ܧ-ѧ٧է֧ݧڧ֧ݧ
-4
2
-3
3
-2
4
-1
5
ݧ֧ާ֧ߧѧ ݧ֧էӧѧ֧ݧߧ֧
len(lst)
-3
-2
-1
lst[:-1][11,67,"abc",3.14,42]
lst[1:-1][67,"abc",3.14,42]
lst[::2][11,"abc",42]
lst[:][11,67,"abc",3.14,42,1968]
6
է է֧ݧߧ ݧ֧ާ֧ߧѧ ֧֧ [ڧߧէ֧ܧ]
67, "abc",3.14, 42, 1968 ] lst[1]67
2
3
4
6
5
lst[-2]42
-4
{'one','two'}
ݧ֧էӧѧ֧ݧߧ
spaces".split()
էݧ ڧܧ, ܧ֧ا֧, ...
ݧاڧ֧ݧߧ ڧߧէ֧ܧ
{1:'one',3:'three'}
ڧݧ٧֧ ܧѧاէ ݧ֧ާ֧ߧ
ݧ֧էӧѧ֧ݧߧ
set(["one","two"])
y,z,r = 9.2,-7.6,"bad"
-5
1
set()
int("15") ާاߧ ܧѧ٧ѧ ֧ݧ ߧӧѧߧڧ ڧ֧ާ ڧڧݧ֧ߧ ӧ ѧѧާ֧
int(15.56) ҧڧ էҧߧ ѧ (էݧ ܧԧݧ֧ߧڧ է֧ݧѧۧ round(15.56))
float("-11.24e8")
str(78.3) էݧ ҧܧӧѧݧߧԧ ֧ҧѧ٧ӧѧߧڧ
repr("Text")
٧ߧѧ֧ߧڧ ڧݧ ӧڧݧڧާ ӧѧا֧ߧڧ
ڧާ ֧֧ާ֧ߧߧ (ڧէ֧ߧڧڧܧѧ)
-6
0
{1,9,3,0}
type(ӧѧا֧ߧڧ) ֧ҧѧ٧ӧѧߧڧ
x = 1.2+8+sin(0)
ܧߧ֧ۧߧ֧ ߧ֧ܧݧܧڧާ
٧ߧѧ֧ߧڧާ (٧է֧ ܧ֧)
էҧѧӧݧ֧ߧڧ
x-=2
ӧڧѧߧڧ
?ߧ֧֧է֧ݧקߧߧѧ? ܧߧѧߧ
[]
()
ܧѧ է֧ߧߧѧ ݧ֧էӧѧ֧ݧߧ ڧާӧݧ
? է ٧ѧѧߧ֧ ߧ֧ڧ٧ӧ֧֧, ҧ է ܧݧ, ܧݧ = ҧѧ٧ӧ ڧ ڧݧ ܧ֧ا
ާ֧ߧ
ڧӧ֧ߧڧ ֧֧ާ֧ߧߧ
ڧѧ֧ݧߧ ڧߧէ֧ܧ
["x",11,8.9] ["word"]
11,"y",7.4
("word",)
ӧѧا֧ߧڧ էߧڧާ ٧ѧާ
ߧ֧ڧ٧ާ֧ߧ֧ާ
ڧާӧ ѧҧݧڧ
? a toto x7 y_max BigOne
? 8y and
x+=3
x=None
list [1,5,9]
tuple (1,5,9)
"""X\tY\tZ
1\t2\t3"""
aEzAEZ_ aEzAEZ_0E9
? ߧ֧ݧѧڧߧܧڧ ҧܧӧ ѧ٧֧֧ߧ, ߧ ڧ٧ҧ֧ԧѧۧ ڧ
? ܧݧ֧ӧ ݧӧ ٧ܧ ٧ѧ֧֧ߧ
? ާѧݧ֧ߧܧڧ/ ҧܧӧ ݧڧѧ
ڧާ֧ߧ
֧֧ާ֧ߧߧ
ߧ֧ۧߧ֧ߧ ڧ
? է֧ߧߧѧ ݧ֧էӧѧ֧ݧߧ, ҧ է ڧߧէ֧ܧ
' ܧѧߧڧӧѧߧ
էݧ ֧֧ާ֧ߧߧ, ߧܧڧ,
ާէݧ֧, ܧݧѧ...
ڧڧѧݧߧѧ էܧާ֧ߧѧڧ Python3
ѧԧѧݧܧ Python3
lst[0]11 ֧ӧ
lst[-1]1968 ݧ֧էߧڧ
է էݧ֧էӧѧ֧ݧߧ [ߧѧѧݧ ֧٧:ܧߧ֧ ֧٧:ѧ]
lst[1:3][67,"abc"]
lst[-3:-1][3.14,42]
lst[:3][11,67,"abc"]
lst[4:][42,1968]
c֧ ҧ֧ ܧѧ٧ѧߧڧ ԧѧߧڧ ߧѧѧݧ է ܧߧ
ݧ ڧ٧ާ֧ߧ֧ާ ݧ֧էӧѧ֧ݧߧ֧, ݧ֧٧ߧ էѧݧ֧ߧڧ del lst[3:5] ڧ٧ާ֧ߧ֧ߧڧ ާ ڧӧ֧ߧڧ lst[1:4]=['hop',9]
< > = == !=
=
ݧԧڧ֧ܧ
a and bҧ ӧ֧ߧ էߧӧ֧ާ֧ߧߧ
a or b ݧԧڧ֧ܧ ڧݧ
ӧ֧ߧ ҧ էߧ
ݧԧڧ֧ܧ ߧ֧
not a
True ܧߧѧߧ ?ڧڧߧ?
False ܧߧѧߧ ?ݧا?
ݧܧ ڧߧܧڧ
էڧ֧ݧܧѧ ڧߧܧڧ:
ҧݧ ڧߧܧڧ 1
?
էڧ֧ݧܧѧ ڧߧܧڧ:
ҧݧ ڧߧܧڧ 2
?
!
ݧ֧ӧ ݧԧڧܧ
ѧӧߧ֧ߧڧ:
ݧ֧. ڧߧܧڧ ݧ ҧݧܧ 1
? ڧݧ ݧѧӧѧ֧ ܧۡ ڧҧݧڧا֧ߧߧ ٧ߧѧ֧ߧڧ!
ѧ֧ާѧڧܧ
ԧݧ ѧէڧѧߧѧ
֧ѧ: + - * / // % **
from math import sin,pi
(1+5.3)*212.6
abs(-3.2)3.2
round(3.57,1)3.6
sin(pi/4)0.707
cos(2*pi/3)-0.4999
acos(0.5)1.0471
sqrt(81)9.0
log(e**2)2.0 .. (. էܧ)
է֧ݧ֧ߧڧ ҧ֧ ѧܧ
ab
ѧ
ӧѧا֧ߧڧ ҧݧܧ ӧݧߧ֧ ݧӧߧ ֧ѧ
ݧܧ ֧ݧ ݧӧڧ ڧڧߧߧ
if ݧԧڧ֧ܧ ӧѧا֧ߧڧ:
ҧݧ ӧѧا֧ߧڧ
ާا֧ ӧاէѧ ߧ֧ܧݧܧڧާ elif, elif, ,
ߧ ݧܧ էߧڧ ܧߧѧ֧ݧߧڧ else. ڧާ֧:
if x==42:
# ҧݧ ӧݧߧڧ, ֧ݧ x==42 ڧڧߧߧ
print("real truth")
elif x>0:
# ڧߧѧ ҧݧ, ֧ݧ ݧ. ӧѧا֧ߧڧ x > 0 ڧڧߧߧ
print("be positive")
elif bFinished:
# ڧߧѧ ҧݧ, ֧ݧ ݧ. ֧֧. bFinished ڧڧߧߧ
print("how, finished")
else:
# ڧߧѧ ҧݧ էݧ ӧ֧ ѧݧߧ ݧѧ֧
print("when it's not")
֧֧ӧ : ֧է ..
ڧܧ ݧӧڧ֧
ҧݧ ڧߧܧڧ ӧݧߧ֧
է ֧ , ܧ ݧӧڧ ڧڧߧߧ
ڧܧ ֧֧ҧ
ҧݧ ڧߧܧڧ ӧݧߧ֧
էݧ ӧ֧ ݧ֧ާ֧ߧ ܧߧ֧ۧߧ֧ ڧݧ ڧ֧ѧ
while ݧԧڧ֧ܧ ӧѧا֧ߧڧ:
ҧݧ ڧߧܧڧ
ѧӧݧ֧ߧڧ ڧܧݧ
s = 0
i = 1 ڧߧڧڧѧݧڧ٧ѧڧ ֧֧ ڧܧݧ
break
ݧ֧էѧ ڧ֧ѧڧ
for c in s:
ڧѧ ڧݧ
if c == "e":
ҧܧ e ܧ
cnt = cnt + 1
print("found",cnt,"'e'")
s= i 2
i=1
ڧܧ dict/set = ڧܧ ݧ֧էӧѧ֧ݧߧ ܧݧ֧
ڧݧ٧ۧ ֧٧ էݧ է էݧ֧էӧѧ֧ݧߧ
? ֧֧ԧѧ֧ۧ ҧ֧ܧߧ֧ߧ ڧܧݧ !
֧ѧ / ӧ
print("v=",3,"cm :",x,",",y+4)
ݧ֧ާ֧ߧ էݧ ҧѧا֧ߧڧ : ݧڧ֧ѧݧ, ֧֧ާ֧ߧߧ, ӧѧا֧ߧڧ
ߧѧۧܧ print:
? sep=" " (ѧ٧է֧ݧڧ֧ݧ ѧԧާ֧ߧ, ާݧ. ҧ֧)
? end="\n" (ܧߧ֧ ֧ѧ, ާݧ. ֧֧ӧ ܧ)
? file=f (֧ѧ ѧۧ, ާݧ. ѧߧէѧߧ ӧӧ)
s = input("Instructions:")
? input ӧ֧ԧէ ӧ٧ӧѧѧ֧ ܧ, ֧ҧѧ٧ۧ ֧ ߧاߧާ
ڧ ѧާ (. ?֧ҧѧ٧ӧѧߧڧ? ߧ էԧ ߧ).
ڧߧէ֧ܧѧ ݧ֧էӧѧ֧ݧߧ
? ާاߧ ڧӧѧڧӧѧ ݧ֧ާ֧ߧ ڧߧէ֧ܧ
? է ֧էߧڧ ݧ֧ާ֧ߧѧ
lst = [11,18,9,12,23,4,17]
lost = []
for idx in range(len(lst)):
ԧѧߧڧڧ ٧ߧѧ֧ߧڧ
val = lst[idx]
ҧݧ 15, ٧ѧާߧڧ
if val > 15:
֧ߧ ٧ߧѧ֧ߧڧ
lost.append(val)
lst[idx] = 15
print("modif:",lst,"-lost:",lost)
ۧ էߧӧ֧ާ֧ߧߧ ڧߧէ֧ܧѧ ٧ߧѧ֧ߧڧ :
for idx,val in enumerate(lst):
֧ѧڧ ܧߧ֧ۧߧ֧ѧާ
len(c) ܧݧڧ֧ӧ ݧ֧ާ֧ߧ
ڧ. : էݧ ݧӧѧ֧ ާߧا֧
min(c) max(c) sum(c)
sorted(c) ڧӧѧߧѧ ܧڧ ֧ѧڧ ѧҧѧ ܧݧѧާ.
val in c boolean, membersihp operator in (absence not in)
enumerate(c) ڧ֧ѧ ѧѧ (ڧߧէ֧ܧ, ٧ߧѧ֧ߧڧ)
ݧܧ էݧ ݧ֧էӧѧ֧ݧߧ֧ (lists, tuples, strings) :
c*5 ӧڧ
c+c2 ֧է֧ߧڧ
c.count(val) էק ӧاէ֧ߧڧ
֧ѧڧ ڧܧѧާ
էҧѧӧڧ ݧ֧ާ֧ߧ ܧߧ֧
lst.append(item)
էҧѧӧڧ ݧ֧էӧѧ֧ݧߧ ܧߧ֧
lst.extend(seq)
ӧѧӧڧ ٧ߧѧ֧ߧڧ ڧߧէ֧ܧ
lst.insert(idx,val)
էѧݧڧ ֧ӧ ӧاէ֧ߧڧ val
lst.remove(val)
էѧݧڧ ٧ߧѧ֧ߧڧ ڧߧէ֧ܧ ӧ֧ߧ ֧ԧ
lst.pop(idx)
lst.sort() lst.reverse() ڧӧѧ/ҧѧڧ ڧ ާ֧
? ڧ٧ާ֧ߧ ֧ӧߧѧѧݧߧ ڧ
֧ѧڧ ݧӧѧާ
֧ѧڧ ާߧا֧ӧѧާ
d[key]=value
d.clear() ֧ѧ:
| ҧ֧էڧߧ֧ߧڧ (ӧ֧ڧܧѧݧߧѧ ֧)
d[key]value
del d[key] & ֧֧֧֧ߧڧ
d.update(d2) ҧߧӧڧ/էҧѧӧڧ - ^ ѧ٧ߧ/ڧާާ֧ڧߧѧ ѧ٧.
ѧ
< >= ߧ֧ߧڧ ӧܧݧ֧ߧڧ
d.keys()
d.values() ާ ܧݧ֧,
s.update(s2)
d.items() ٧ߧѧ֧ߧڧ ѧ
s.add(key) s.remove(key)
d.pop(key)
s.discard(key)
ѧۧݧ
ѧߧ֧ߧڧ ڧӧѧߧڧ ѧۧݧ էڧܧ
f = open("fil.txt","w",encoding="utf8")
ڧާ ѧۧݧ
ߧ էڧܧ
(+)
֧اڧ ѧҧ
? 'r' read
? 'w' write
? 'a' append
. ߧܧڧ ާէݧ os os.path
٧ѧڧ
f.write("hello")
ܧէڧӧܧ
ڧާӧݧ ֧ܧӧ ѧۧݧѧ:
utf8 ascii
cp1251 ...
ѧ ܧ ܧߧ ѧۧݧ
֧ߧڧ
s = f.read(4)֧ݧ ܧݧڧ֧ӧ
? ֧ܧӧ ѧۧ ֧ߧڧ/٧ѧڧ
ڧѧ ݧ֧է ڧާӧݧ ߧ ܧѧ٧ѧߧ,
ڧѧ֧ ӧ֧ ѧۧ
ݧܧ , ֧ҧѧ٧ۧ
ܧ
֧ҧ֧ާ ڧ
s = f.readline()
f.close() ? ߧ ٧ѧҧӧѧۧ ٧ѧܧӧѧ ݧ ڧݧ٧ӧѧߧڧ
ӧާѧڧ֧ܧ ٧ѧܧ : with open() as f:
֧ߧ ѧ: ڧܧ ܧѧ (ܧѧاէѧ է '\n') ֧ܧӧԧ ѧۧݧ
for line in f :
# ҧݧ ܧէ էݧ ҧѧҧܧ ܧ
֧֧ާ֧ߧߧѧ ڧܧݧ, ٧ߧѧ֧ߧڧ ѧӧݧ֧ ڧܧݧ for
i=100
print("sum:",s) ӧڧݧ֧ߧߧ ֧٧ݧѧ ڧܧݧ
ѧۧݧӧѧ
֧֧ާ֧ߧߧѧ
էݧ ֧ѧڧ
s = "Some text" ڧߧڧڧѧݧڧ٧ѧڧ ֧֧ ڧܧݧ
cnt = 0
continue
֧ߧ֧ѧ ݧ֧էӧѧ֧ݧߧ֧ int
ާݧѧߧڧ 0
ѧ ڧݧ٧
ڧܧݧѧ for
ߧ ӧܧݧѧ֧
range([start,]stop [,step])
range(5)
0 1 2 3 4
range(3,8)
3 4 5 6 7
range(2,12,3)
2 5 8 11
range ӧ٧ӧѧѧ֧ ?ԧ֧ߧ֧ѧ?, ҧ ӧڧէ֧ ٧ߧѧ֧ߧڧ,
֧ҧѧ٧ۧ ֧ԧ ݧ֧էӧѧ֧ݧߧ, ߧѧڧާ֧:
print(list(range(4)))
ڧާ ߧܧڧ (ڧէ֧ߧڧڧܧѧ) ֧է֧ݧ֧ߧڧ ߧܧڧ
ڧާ֧ߧӧѧߧ ѧѧާ֧
def fctname(p_x,p_y,p_z):
"""documentation"""
# ڧߧܧڧ, ӧڧݧ֧ߧڧ ֧٧ݧѧ
return res
֧٧ݧѧ ӧ٧ӧ. ֧ݧ ߧ֧
ӧ٧ӧѧ ٧ߧѧ֧ߧڧ,
? ѧѧާ֧ ӧ֧ ҧݧ
ާݧѧߧڧ ӧ֧ߧק None
֧ӧ ݧܧ ӧ ӧ֧ާ
ӧ٧ӧ ߧܧڧ (?֧ߧѧ ܧҧܧ?)
٧ ߧܧڧ
r = fctname(3,i+2,2*i)
էڧ ѧԧާ֧ߧ ܧѧاէާ ѧѧާ֧
ݧڧ ֧٧ݧѧ (֧ݧ ߧا֧)
ާѧߧ էڧ֧ܧڧӧ
ާѧڧӧѧߧڧ
٧ߧѧ֧ߧڧ էݧ ާѧڧӧѧߧڧ
"model {} {} {}".format(x,y,r)
"{֧ݧ֧ܧ:ާѧ!֧ҧѧ٧ӧѧߧڧ}"
str
"{:+2.3f}".format(45.7273)
? ֧ݧ֧ܧ :
2
'+45.727'
x
"{1:>10s}".format(8,"toto")
0.nom
'
toto'
4[key]
"{!r}".format("I'm")
0[2]
'"I\'m"'
? ާѧ :
٧ѧݧߧ֧ߧڧ ӧѧӧߧڧӧѧߧڧ ٧ߧѧ ާڧߧڧڧߧ.ߧ~ާѧܧڧڧߧ ڧ
ڧާ֧
# ӧѧا֧ߧڧ ӧڧݧ ܧ i 100
s = s + i**2
i = i + 1 ڧ٧ާ֧ߧ֧ ֧֧ާ֧ߧߧ ڧܧݧ
reversed(c) reverse iterator
c.index(val) ٧ڧڧ
ݧ֧ާ֧ߧѧ ݧ֧էӧѧ֧ݧߧ
ߧ֧ާ֧էݧ֧ߧߧ ӧ
ݧӧڧ ҧ էߧڧ ڧ٧ާ֧ߧڧާ ٧ߧѧ֧ߧڧ֧
(٧է֧ i)
while i ................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.