Python , :
x += y | x = x + y |
x -= y | x = x - y |
x *= y | x = x * y |
x /= y | x = x / y |
x //= y | x = x // y |
x **= y | x = x ** y |
x %= y | x = x % y |
x &= y | x = x & y |
x |= y | x = x | y |
x ^= y | x = x ^ y |
x>>= y | x = x>>y |
x <<= y | x = x << y |
f = open("data.txt", "rb")
R=f.readlines()
print (R)
f.close()
XML
def export_xml_etree(filename):
root = xml.etree.ElementTree.Element("Cycle")
for i in ():
element = xml.etree.ElementTree.Element("Process",
m=str(i[0]),
n=str(i[1]))
root.append(element)
tree = xml.etree.ElementTree.ElementTree(root)
. .
- , . , .
, . , - , , . - beep, .
, .
Python def, :
def remainder(a, b):
q = a // b
# // .
r = a - q*b
return r
, , , : result = remainder(37, 15). Python , , :
def divide(a, b):
q = a // b
# a b , q
r = a - q*b
return (q,r)
, , :
quotient, remainder = divide(1456, 33)
:
def connect(hostname, port, timeout=300):
#
, . , . :
|
|
connect(port=80, hostname=www.python.org)
, . , , . , global:
count = 0
...
def foo():
global count
count += 1
# count
def, , , :
def movement(self,α=0):
""" """
Python , , , Python IDE .
, LIFO ( . Last In First Out , ).
, . , . , . , ( ) ( Python) ( C).
, f3() f2(), f2() f1():
def f1():
print (" f1()")
#a = 1/0
print (" f1()")
def f2():
print (" f2()")
f1()
print (" f2()")
def f3():
print (" f3()")
f2()
print (" f3()")
f3()
:
f3()
f2()
f1()
f1()
f2()
f3()
f1(), f2() f3(), . . .
, , ( ) , .. . , , .
a = 1/0, f1() . :
f3()
f2()
f1()
|
|
Traceback (most recent call last):
File ".py", line 22, in <module>
f3()
File ".py", line 20, in f3
f2()
File ".py", line 16, in f2
f1()
File ".py", line 12, in f1
a = 1/0
ZeroDivisionError: division by zero
f1() traceback ( , , ). Traceback , , . , . . [2]
-
def . , . , , -. . .
: k(T) :
def k(T):
return 1.444-1.812e-4*T+5.146e-8*T**2
-
k= lambda T:1.444-1.812e-4*T+5.146e-8*T**2
lambda , () .
:
import math
polar= lambda x,y:(math.sqrt(x**2+y**2),math.atan2(x,y))
R,φ=polar(-3,-4)
print (R,φ)
polar x y , R φ.
, :
R,φ=(lambda x,y:(math.sqrt(x**2+y**2),math.atan2(x,y)))(-3,-4)
print (R,φ)
, print ():
print ((lambda x,y:(math.sqrt(x**2+y**2),math.atan2(x,y)))(-3,-4))