Skip to content

Latest commit

 

History

History
108 lines (88 loc) · 2.8 KB

File metadata and controls

108 lines (88 loc) · 2.8 KB

Control Flow

Conditionals

  • Arithmetic Operators
Operator Description
** Exponent
+ Addition
- Subtration
* Multiplication
/ Division
% Modulus
// Floor Division
  • Comparison (Relational) Operators
Operator Description
< Less than
> Greater than
<= Less than or Equal to
>= Greater than or Equal to
== Equal to
!= NOT Equal to
  • Assignment Operators
Operator Example. Equivatent to.
= x = 5 x = 5
+= x += 5 x = x+5
-= x -= 5 x = x-5
*= x *= 5 x = x*5
/=     x /= 5 x = x/5
%= x %= 5 x = x%5
**= x **= 5 x = x**5
//=   x //= 5   x = x//5
  • Logical Operators
Operator Meaning
and True if both the operands are true
or True if either of the operands is true
not True if operand is false (complements the operand)
  • Bitwise Operators
Operator Meaning
& Bitwise AND
` `
~ Bitwise NOT
^ Bitwise XOR
>> Bitwise right shift
<< Bitwise left shift
  • Membership Operators
Operator Meaning Example
in True if value/variable is found in the sequence 5 in x
not in True if value/variable is not found in the sequence 5 not in x
  • Identity Operators
Operator Meaning Example
is refer to the same object x is True
is not do not refer to the same object x is not True

If

  • if-elif-else
if condition:
   operation
elif condition:
   operation
else:
   operation

For

for i in iterables:
    operation(with i or not)
  • break
  • continue
  • range()

While

condition = True
while condition:
    operation
  • break
  • continue
  • else