Python



Python.



  • .



    (, , )
    (list)
    (dictionary)


    C

    math
    string


  •   , Guido van Rossum


    Guido van Rossum

    , , . , . . , , .

    , Python (), (Guido van Rossum) 90- .

    Python 1980- CWI . Amoeba , Python , ABC ( , ). 1991 alt.sources. Python - .

    Python.

    Python , - . , . Pascal, C++ , C, , , (, , ).

    , Python . C, . Python .

    - , , , . , . . , . , C Python , "" .

    - , . Python . :

    , , Python-, . , , .

    1. Python, (Pascal, C++, Java, ..), . , .. - . , . Python Basic.
    . , .

    2. Pascal, C, C++ . . , , , , . . , Delphi Pascal TList, ; ++ STL (Standard Template Library), , , , , . , .

    Python (tuple), (list) (dictionary), (map). .

    1. - : . - . , . , (list) , , .. i- - . , -. , :


    2. (1, 2, 5, 8)
      (3.14, string , -4)
      . i- i . :
      t = (0, 1, 2, 3, 4)
      print t[0], t[-1], t[-3]
      : 0 4 2
      , -, .
    3. , (string) Turbo Pascal. , , , , . . , , :


    4. [3, 5.14, s]
      [string, (0,1,8), [1,1]]
        , . . :
      l = [1, s, (2,8), [0,3,4]]
      print l[0], l[1], l[-2], l[-1][0]
      : 1 s (2,8) 0
    5. (record) Pascal (structure) . , " "-"" ""-"". ""-"". "" - ( ), () ( ).


    6. ( ""-"", ), . , , . :
      d = {'a': 1, 'b': 3, 5: 3.14, 'name': 'John'}
      d['b'] = d[5]
      print d['a'], d['b'], d[5], d['name']
      : 1 3.14 3.14 John
      ""-"" :
      d['new'] = 'new value'
      print d
      : {'a':1, 'b':3, 5:3.14, 'name':'John', 'new':'new value'}

    3. Python Pascal, C, C++ , . Java. , . Python.

    4. Python , , .. "=" .

    ([1]), , (), .. , , . , , , .. , , .

    ( - - ) , . , , "=" . .

    Python : , , , , , . :
    a = 2; b = a; b = 3
    print ' : a=', a, 'b=', b
    a = [2,5]; b = a; b[0] = 3
    print ' : a=', a, 'b=', b
    :
    : a= 2 b= 3
    : a= [3,5] b= [3,5]

    , , Python. Basic, Pascal, C/C++ -"", (, , - ), "" , Python -"" . ( Prolog?) Python? , : , , , , ( Object Pascal ), (!), , .. , , "", "" .

    , () . - , " ", , , , . - , , (, ; , , ).

    , a = [2,5]; b = a; b[0] = 3, Python :

  • " [2,5]" a ;
  • - b ;
  • .

  • "" .

    , : , - :

    t = (1, 2, [7,5], 'string')
    t[0] = 6 #  
    del t[1] #  
    t[2][1] = 0 # ,    -  [7,0]
    t[3][0] = 'S' # :   
    

    5. , Python . Pascal begin-end, C, C++, Java - {}, Basic (NEXT, WEND, END IF, END SUB).
    Python : . :

     if x > 0:
          print  x > 0 
          x = x - 8
     else:
          print  x <= 0 
          x = 0
    , , Pascal, C++, Java .., , , - .
     

    .

    if <1>: <1>
        [  elif <2>: <2>]* 
    [  else: <3>  ] 
     
     
     
     
    "". . "*" , . 

    , <1> <1> elif else. , <2>, <2>, else . <3>. 

     
    while <>:
        <1> 
    [else: <2>]
     
    "". <1> , <>. , .. break, <2>. 
     
    for <> in <>:
        <1> 
    [else: <2>]  
     
    "". <> <> <> <1>. , .. break, <2>. 
     
    break while for. 
    continue while for. 
    return [<>] , <>. 
     
     

    try :
        <1> 
    [except [<> [,<>] ]:
        <2>] 
    [else <3>] 
    <1>, <>, <2>. <> , <>. 
    <1>, <3>. 
    try :
        <1> 
    finally :
        <2> 
     
    <1>. , <2>. <2> . 
    raise <> [<>]  <> <>. 

    - (string).  :

    my_ex = bad index
    try:
        if bad:
            raise my_ex, bad
    except my_ex, value:
        print  Error , value
     

    def <_> ( [
    <_>] ):
        <_>
     
     
     
     
     
     
    <_> - , "def". 
    <_> : 
    [ < id > [,< id >]* ] [ < id >=< v > [,< id >=< v >]* ] [, *< id >] 
    < id > - ; < v > - . 
    < id > "=" < v > . 
    " *< id > ", id (tuple) , . 
     
     

    class <_> [( <1>
     [,<2>]* )]:
        <_>
     
     
     
     
    <_> ( , .. ) ( ). 
    (, , ). , "self". __init__() . 

    :

    class cMyClass:
        def __init__(self, val):
            self.value = val
        #
        def printVal (self):
            print  value = , self.value
        #
    # end cMyClass
    obj = cMyClass (3.14)
    obj.printVal ()
    obj.value = " string now "
    obj.printVal ()
    :
    value = 3.14
    value = string now
     

    (, , )

    len (s)   s.
    min (s), max (s) s .
    x in s (1), s x, - (0).
    x not in s  , s x, .
    s + t   s t.
    s * n , n * s  n s, (, * * 5 - *****).
    s[i]  i- s, i 0.
    s[i:j] s, i j-1 . i, j, (i 0, j - s). 
     

    (list)

    s[i] = x i- s x.
    s[i:j] = t s i j-1 t (t ).
    del s[i:j] s ( s[i:j] = []).
    s.append (x) x s.
    s.count (x) s x.
    s.index (x) i, , s[i]==x.
    s.insert (i,j) s, i- , , s[i] x.
    s.remove (x) , del s[ s.index(x) ] - s, x.
    s.reverse ()
    s.sort ()
     

    (dictionary)

    len (a) .
    a[k] k.
    a[k] = x k x.
    del a[k] a[k] .
    a.items () (, ).
    a.keys () .
    a.values () .
    a.has_key (k) 1, k, 0.
     

    open() ( ). : f = open (mydan.dat,r).
    :
     

    f.close ()   .
    f.read ( [size] )   < size > . < size > , .
    f.readline () .
    f.readlines () .
    f.seek (offset, mode) 
     
     
     
      . 
      < offset > - : 
    a) ( mode == 0 - ); 
    b) ( mode == 1 ); 
    c) ( mode == 2). 
    f.tell ()   . 
    f.write (str) < str > .
     

    =  .
    print [ < c1 > [,< c2 >]* [,] ]    < c1 >, < c2 > . . , .
    abs (x)   x.
    apply (f, <>)   ( ) f < >.
    chr (i) ASCII i.
    cmp (x, y) , , , , , x <, ==, > y.
    divmod (a, b) (a/b, a%b), a/b - a div b ( ), a%b - a mod b ( ).
    eval (s) 
     
    , s (string). S . S , : x = 1 ; incr_x = eval ("x+1") .
    float (x) x.
    hex (x) , x.
    input (<>) <>, .
    int (x) x.
    len (s) ( ) .
    long (x) x.
    max (s), min (s)   s (.. s - , ).
    oct (x) , x.
    open (< >, <>=r) , . <> = w - .
    ord (c) ASCII ( 1) c.
    pow (x, y) x y.
    range (<>, <>, <>) , <> <>, <>.
    raw_input ( [ <> ] ) <> (string) .
    round (x, n=0)   x, n- .
    str (<>) <>.
    type (<>)
    : if type(x) == type(): print
    xrange (<>, <>, <>) range, , . for.
     

    C

    filter (<>, <>) <c>, <> "".
    map (<>, <>) <> <> .
    reduce (f, <>,
     [, < > ] ) 
     
     
     
     
     
     
     
     
      "" <> f. , p, < >, , <>, f : p <>. f p. <> reduce p. 
    , , : 
    def func (red, el):
        return red+el
    sum = reduce (func, [1,2,3,4,5], 0)
    #  sum == 15
    
    lambda [< >] : <> 
     
     
     
     
     
     
    "" , . , < >, <>. filter, reduce, map. :
    >>>print filter (lambda x: x>3, [1,2,3,4,5])
    [4, 5]
    >>>print map (lambda x: x*2, [1,2,3,4])
    [2, 4, 6, 8]
    >>>p=reduce (lambda r, x: r*x, [1,2,3,4], 1)
    >>>print p
    24
    
     

    import <1> [, <2> ]* .
    from <> import <1> [, <2> ]* (, , ..) <>. 
    from <> import * <>, "_". 
     
     

    math

    : pi, e.
    ( C):
     

    acos(x) cosh(x) ldexp(x,y) sqrt(x)
    asin(x) exp(x) log(x) tan(x)
    atan(x) fabs(x) sinh(x) frexp(x)
    atan2(x,y) floor(x) pow(x,y) modf(x)
    ceil(x) fmod(x,y) sin(x)  
    cos(x) log10(x) tanh(x)  
     

    string

    :
     

    index (s, sub, i=0) sub s, i.
    lower (s) s .
    splitfields (s, sep) s sep.
    joinfields (<>, <>) <> <>.
    strip (s) , s .
    upper (s) s .
     

      Python, (, , ..) , .
      Python - ( -) (, ++, Pascal). , , , , , . , Python , .

     

    1. . - . - .: , 1997.
    2. Guido van Rossum. Python Tutorial. (www.python.org)
    3. Chris Hoffman. A Python Quick Reference. (www.python.org)
    4. Guido van Rossum. Python Library Reference. (www.python.org)
    5. Guido van Rossum. Python Reference Manual. (www.python.org)
    6. . Python. (http://sultan.da.ru)

    , - - - , .




     10.11.2021 - 12:37: - Personalias -> WHO IS WHO - - _.
    10.11.2021 - 12:36: - Conscience -> . ? - _.
    10.11.2021 - 12:36: , , - Upbringing, Inlightening, Education -> ... - _.
    10.11.2021 - 12:35: - Ecology -> - _.
    10.11.2021 - 12:34: , - War, Politics and Science -> - _.
    10.11.2021 - 12:34: , - War, Politics and Science -> . - _.
    10.11.2021 - 12:34: , , - Upbringing, Inlightening, Education -> , - _.
    10.11.2021 - 09:18: - New Technologies -> , 5G- - _.
    10.11.2021 - 09:18: - Ecology -> - _.
    10.11.2021 - 09:16: - Ecology -> - _.
    10.11.2021 - 09:15: , , - Upbringing, Inlightening, Education -> - _.
    10.11.2021 - 09:13: , , - Upbringing, Inlightening, Education -> - _.
    Bourabai Research -  XXI Bourabai Research Institution