. , , . . len range .
, ( ) . , .
, def . , ; , , . , . :
(1.py ):
def _():
#
print(' ')
#
_() #
_() #
:
$ python 1.py
_ _. , . , .
, .
, . , , . , . , , .
, , . , . - , .
(_.py ):
def _(, ):
if > :
print(, '')
elif == :
print(, '', )
else:
print(, '')
#
_(3, 4)
= 5
= 7
#
_(, )
:
$ python _.py
4
7
, _ . if..else , .
_ , . , _(x, y) . , , . _ .
, - , . . , , .
(_.py ):
= 5
def ():
print(' ', )
= 2
print(' ', )
()
print(' ', )
:
$ python _.py
5
2
5
, , .
, 2 . . , , .
print , , , .
global
(, ) , , . global . global , .
( ). , , . global , .
(_.py ):
= 5
def ():
global
print(' ', )
= 2
print(' ', )
()
print(' ', )
:
$ python _.py
5
2
2
global - , , .
global .. global , , .
, , , . . , (=) , , .
. , - . , .
(_.py ):
def (, =1):
print( * )
('')
('', 5)
:
$ python _.py
, . , . 1- .
, , . , , 5 .
, , , , .
, . ,
def (a, b=5) , def (a=5, b) .
, , - - , () .
- , , . , , .
(_.py ):
def (, =5, =1):
print(' ', , ' ', , ' ', )
(3, 7)
(25, =24)
(=5, =1)
:
$ python _.py
3, 7 1
25, 5 24
1, 5 5
, , .
, (3, 7), 3 , 7 10 .
(25, =24), 25 . , 24 . 5 .
(=50, =100), . , .
, , ; (_.py):
def (=5, *, **):
print('', )
#
for in :
print('_', )
#
for _, _ in .items():
print(_,_)
(1,1,2,3,=1123,=2231,=156)
:
$ python _.py
1
_ 1
_ 2
_ 3
156
2231
1123
*, '' .
, **, '' .
.
return
, return . , .
(_.py ):
def (, ):
if > :
return
elif == :
return ' '
else:
return
print((2, 3))
:
$ python _.py
3
maximum , . if..else , .
return return None .None . , None , .
, return None .return print(some_()) :
def some_():
pass
, pass .
: ' '
max, .
, . , , . , , !
(_.py ):
def _(, ):
''' .
.'''
#
= int()
= int()
if > :
print(, '')
else:
print(, '')
_(3, 5)
print(_.__doc__)
:
$ python _.py
5
.
.
, . , ; .
, . , , . , .
_ , __doc__ ( ) (... ) . , . .
help(), ! , __doc__ , . - help(_) .help q .
. , . pydoc , help() .
, . , .
, .