6.1. Conditional Operators

6.1.1. Operator precedence

Table 17. Operator precedence

Operator

Description

lambda

Lambda expression

if, elif, else

Conditional expression

and

Boolean AND

or

Boolean OR

not x

Boolean NOT

in, not in, is, is not,

<, <=, >, >=, !=, ==

Comparisons, including membership tests and identity tests

|

Bitwise OR

^

Bitwise XOR

&

Bitwise AND

<<, >>

Shifts

**

Exponentiation

*, @, /, //, %

Multiplication, matrix multiplication, division, floor division, remainder

+, -

Addition and subtraction

+x, -x, ~x

Positive, negative, bitwise NOT

await

Await expression

x[index], x[index:index],

x(arguments...), x.attribute

Subscription, slicing, call, attribute reference

(expressions...), [expressions...],

{key: value...}, {expressions...}

Binding or tuple display, list display, dictionary display, set display

6.1.2. Assignments

6.1.2.1. Is odd number

English
  1. Read a number from user

  2. User will pass only valid int

  3. Print whether number is odd

  4. Number is odd, when divided modulo (%) by 2 has a reminder

Polish
  1. Wczytaj liczbę od użytkownika

  2. Użytkownika poda tylko poprawne int

  3. Wypisz czy liczba jest nieparzysta

  4. Liczba jest nieparzysta, gdy dzielona modulo (%) przez 2 ma resztę

The whys and wherefores
  • Reading input from user

  • Type casting

  • Print formatting

  • Numerical operators

Hints
  • % has different meaning for int and str