Python statements and their execution priority

. (, , , , , ). : if, , == true, , == false.

, , .

a = b + c
      
      



b c, a. a = b + c - . , , - . - , - “+”.

Python

. Python Matlab Octave. int, float, complex.

Operators, operands, result




, . . , , - .





.

+

-

*

/

//

%

**

additional. subtraction. multiplication. exponenta. division.

modulus (%) . a = 10, b = 20, b%a == 0. , . 9/2 == 4.5, 9//2 , 4. floor division (//) .

, . .

Python . . c = a+bj, - ,

c.real()

#a
      
      



b - .

c.imag()

#b
      
      



c , . complex numbers . a X Y x + yi. , X , Y - .

Python . , , , .





Comparison operators




>

<

>=

<=

==

!= <>

a x b, x - .

“=” , . “==”, “=” . != . “<>”, , , .

Python .

=

+=

-=

*=

/=

%=

**=

//=

. , .

Assignment Operators




:

  • ;
  • ;
  • - ;
  • - true false.

:

a x b, x - , a = a x b. , a += b , a b, a. . , a **= b a = a ** b, a b, a.

Python.

Condition if




:

  • if - ;
  • elif - ( if else elseif);
  • else - .
a = int(input())

if X:

    A = Y

else:

    A = Z
      
      



.

A = Y if X else Z
      
      



else elseif , :

if 1:

print("hello 1")
      
      



break continue. Break . Continue , .

Python .

Bitwise operators




, 32- .

a = 0
#00000000000000000000000000000000

a = 1

#00000000000000000000000000000001

a = 2

#00000000000000000000000000000010

a = 3

#00000000000000000000000000000011

a = 255

#00000000000000000000000011111111
      
      



1.

314

#00000000000000000000000100111010

-314

#11111111111111111111111011000101 + 1 = 11111111111111111111111011000110
      
      



&

1,

a = b

|

1,

a = 1 b = 1,

a = b

^

1, a = 1 b = 1, 0, a = 1 b = 1

~a

a << b

a b

a >> b

a b

a >>> b

a b

a >> b a >>> b , .

9
#00000000000000000000000000001001

9 >> 2
#00000000000000000000000000000010

-9
#11111111111111111111111111110111

-9 >> 2
#11111111111111111111111111111101
      
      



a >>> b .

-9
#11111111111111111111111111110111

-9 >>> 2
#00111111111111111111111111111101
      
      



.

Yes no or




:

  • and - true, a == b == x;
  • or - true a == x b == x;
  • not - false, a == b == x.

, .

  • a in b true, a b;
  • a not in b true, b.

  • a is b true, ;
  • a is not b true, .

, .

Python :

  • .
  • Python.
  • .
  • .
  • .
  • , , .
  • .
  • .
  • .
  • .
  • .
  • , .
  • .
  • .
  • , , , .

- -. Lambda expression . ,

def <lambda>(arguments):

    return expression
      
      



- , Python.

. :

a[i]
      
      



- , i - .

. [x:y:z]. x , y - , z - . X , y - , z . z , .




All Articles