

        .  ,           .

  

           ?  .      .

>>> def __():
...     return (2, '')
...
>>> ,  = __()
>>> 
2
>>> 
''

 , ,  = < >          .

 ,         :

>>>  = 5;  = 8
>>> , 
(5, 8)
>>> ,  = , 
>>> , 
(8, 5)

 

     __init__  __del__  .

       . ,   []    (  -  ),     __getitem__()  ,   .  ,      !

      .      ,  .

  • __init__(self, ...)

    •           .
  • __del__(self)

    •      (   ,    )
  • __str__(self)

    •  print    str()  .
  • __lt__(self, )

    •    (<)    . ,   (+, >, )   .
  • __getitem__(self, )

    • []    .
  • __len__(self)

    •    len()   .

  

           . ,    .        ,            .    :

>>>  = True
>>> if : print('')
...


     ,     .        ,   ,       . ,    ,          .

 

       . ,          .    .       .

 (_.py  ):

 = [{'': 2, '': 3},
          {'': 4, '': 1}]
.sort(key=lambda : [''])
print()

:

$ python _.py
[{'': 1, '': 4}, {'': 3, ': 2}]

  

   sort ,            (,       ).  ,      ,      .          def   ,         .

 

          .      ,    2-    ,   2-        .      .

 (__.py  ):

 = [2, 3, 4]
 = [2* forin  if  > 2]
print()

:

$ python __.py
[6, 8]

  

,      (if  > 2)     (2*)     .       .

     ,                  .

    

    *  **           .        .

>>> def (, *):
...     '''      .'''
...      = 0
...     forin :
...          += pow(, )
...     return 
...
>>> (2, 3, 4)
25
>>> (2, 10)
100

   *  ,         .    **  ,     /  .

assert 

      assert  . ,             ,  ,       ,    assert   .   , ​​ AssertionError  .  pop() ,       .

>>>  = ['']
>>> assert len() >= 1
>>> .pop()
''
>>> assert len() >= 1
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AssertionError

 assert    .  ,  ,         .



     .        ""    . ,      .      .      ,   5     ,       .             .

from time import sleep
from functools import wraps
import logging
logging.basicConfig()
 = logging.getLogger("")


def ():
    @wraps()
    def _(*, **):
        _ = 5
        for  in range(1, _ + 1):
            try:
                return (*, **)
            except Exception:
                .exception(" %s/%s  : %s",
                              ,
                              _,
                              (, ))
                sleep(1 * )
        .critical(" %s   : %s",
                     _,
                     (, ))
    return _


 = 


@
def _():
    print("      .")
    print("      .")
    global 
     += 1
    #      
    #    (,  )  
    if  < 2:
        raise ValueError()


if __name__ == '__main__':
    _("   ")

:

$ python _.py
      .
      .
ERROR:: 1/5  : (('   ',), {})
Traceback (most recent call last):
  File "_.py", line 14, in _
    return (*, **)
  File "_.py", line 39, in _
    raise ValueError()
ValueError:    
      .
      .

  

:

 2   3  

:



       ,       . ,  ,       .        .

,      .

results matching ""

    No results matching ""