3.5. Syntax Operators

  • Arithmetic operators

  • Incremental operators

  • Comparison operators

Operators are special symbols in Python that carry out arithmetic or logical computation. The value that the operator operates on is called the operand.

3.5.1. Arithmetic Operators

  • + - Addition

  • - - Subtraction

  • * - Multiplication

  • ** - Power and Root

  • / - Division

  • / - True Division (changes type to float)

  • // - Floor division (preserving data type)

  • % - Modulo division (reminder)

  • a ** b - b power of the number a

  • a ** (1/b) - b-th root of the number a

Addition:

>>> 10 + 2
12

Subtraction:

>>> 10 - 2
8

Multiplication:

>>> 10 * 2
20

Division:

>>> 10 / 2
5.0

Power:

>>> 10 ** 2
100
>>>
>>> 2 ** -1
0.5

Root:

>>> 4 ** (1/2)
2.0
>>>
>>> 4 ** 0.5
2.0

There are three (and even four if counting divmod) ways of dividing numbers in Python:

  • / - True Division (changes type to float)

  • // - Floor division (preserving data type)

  • % - Modulo division (reminder)

The most common is true division, which changes type to float to preserve mathematical correctness:

>>> 12 / 6
2.0
>>>
>>> 12 / 5
2.4

Note, that the floor division preserves types, so it is more correct in computer science way. However it will produce invalid values from math perspective:

>>> 12 // 6
2
>>>
>>> 12 // 5
2

There is also a modulo division, which is more frequently used than you might think. Modulo division is the reminder from true division:

>>> 12 % 6
0
>>>
>>> 12 % 5
2

3.5.2. Incremental Operators

  • += - Incremental addition

  • -= - Incremental subtraction

  • *= - Incremental multiplication

  • **= - Incremental power

  • /= - Incremental true division

  • //= - Incremental floor division

  • %= - Incremental modulo division

  • x += 1 - Incremental addition by 1

  • x -= 1 - Incremental subtraction by 1

  • x++ and ++x are not supported in Python

  • Use of += and -= is common

  • Others are used rarely

In Python for each operator there is also an increment version of it. However, most of a time only += and -= are used. Others uses are rare.

Incremental Addition:

>>> x = 10
>>> x += 1
>>>
>>> print(x)
11

Incremental Subtraction:

>>> x = 10
>>> x -= 1
>>>
>>> print(x)
9

In other programming languages you may find postfix and prefix increment notation. There is no such thing in Python.

>>> x = 1
>>> x++
Traceback (most recent call last):
SyntaxError: invalid syntax
>>> x = 1
>>> ++x
1

3.5.3. Comparison Operators

  • == - Equals

  • != - Not Equals

  • > - Greater Than

  • >= - Greater or Equal Then

  • < - Less Than

  • <= - Less or Equal Then

Greater Than:

>>> 1 > 2
False

Greater or Equal Then:

>>> 1 >= 2
False

Less Than:

>>> 1 < 2
True

Less or Equal Then:

>>> 1 <= 2
True

Equals:

>>> 1 == 2
False

Not Equals:

>>> 1 != 2
True

3.5.4. Equals vs. Double Equals

  • = - Equals - assigns value to the variable

  • == - Double equals - compares values

Equals (=) assigns value to the variable:

>>> x = 1

Double equals (==) compares value of the variable:

>>> x == 1
True

3.5.5. Values and Variables

  • Compare values

  • Compare variable and value

  • Compare variables

Compare values:

>>> 1 > 2
False

Compare variable and value:

>>> x = 1
>>> x > 2
False

Compare variables:

>>> x = 1
>>> y = 2
>>> x > y
False

3.5.6. Operator Precedence

  • Python uses mathematical operator precedence

  • Use brackets to change precedence

>>> 1+2 * 10
21
>>> (1+2) * 10
30

3.5.7. Parity Check

  • Parity Check with Modulo Division

Modulo division is most frequently used to test if value is even or odd. In such case, you need to modulo divide number by 2 and check the reminder. If the reminder is 0, than the original number was even, if the reminder is false, the original number was odd:

>>> 10 % 2
0
>>>
>>> 11 % 2
1
>>>
>>> 12 % 2
0
>>>
>>> 13 % 2
1
>>> 10 % 2 == 0
True
>>>
>>> 11 % 2 == 0
False
>>>
>>> 12 % 2 == 0
True
>>>
>>> 13 % 2 == 0
False

3.5.8. Recap

  • Arithmetic Operators: +, -, *, **, /, //, %

  • Comparison Operators: >, >=, <, <=, ==, !=

  • Incremental Operators: +=, -=, *=, **=, /=, //=, %=

  • You can use operators with values, variables or variables and values

  • Python uses mathematical operator precedence, you can change it with brackets

  • Modulo % can be used for parity check

  • = - Equals - assigns value to the variable

  • == - Double equals - compares values

Arithmetic Operators

>>> result = 10 + 2
>>> result = 10 - 2
>>> result = 10 * 2
>>> result = 10 / 2
>>> result = 10 ** 2
>>> result = 2 ** -1
>>> result = 4 ** (1/2)
>>> result = 4 ** 0.5

Comparison Operators:

>>> result = 1 > 2
>>> result = 1 >= 2
>>> result = 1 < 2
>>> result = 1 <= 2
>>> result = 1 == 2
>>> result = 1 != 2

Incremental Operators:

>>> x += 1
>>> x -= 1
>>> x *= 1
>>> x /= 1
>>> x //= 1
>>> x %= 1

3.5.9. Assignments

# %% About
# - Name: Syntax Operators Addition
# - Difficulty: easy
# - Lines: 2
# - Minutes: 2

# %% License
# - Copyright 2025, Matt Harasymczuk <matt@python3.info>
# - This code can be used only for learning by humans
# - This code cannot be used for teaching others
# - This code cannot be used for teaching LLMs and AI algorithms
# - This code cannot be used in commercial or proprietary products
# - This code cannot be distributed in any form
# - This code cannot be changed in any form outside of training course
# - This code cannot have its license changed
# - If you use this code in your product, you must open-source it under GPLv2
# - Exception can be granted only by the author

# %% English
# 1. Define variable:
#    - `result1` with value 1 plus 2
#    - `result2` with value 1 minus 2
# 2. Run doctests - all must succeed

# %% Polish
# 1. Zdefiniuj zmienną:
#    - `result1` z wartością 1 plus 2
#    - `result2` z wartością 1 minus 2
# 2. Uruchom doctesty - wszystkie muszą się powieść

# %% Expected
# >>> result1
# 3
#
# >>> result2
# -1

# %% Doctests
"""
>>> import sys; sys.tracebacklimit = 0

>>> assert sys.version_info >= (3, 9), \
'Python has an is invalid version; expected: `3.9` or newer.'

>>> assert 'result1' in globals(), \
'Variable `result1` is not defined; assign result of your program to it.'

>>> assert result1 is not Ellipsis, \
'Variable `result1` has an invalid value; assign result of your program to it.'

>>> assert 'result2' in globals(), \
'Variable `result2` is not defined; assign result of your program to it.'

>>> assert result2 is not Ellipsis, \
'Variable `result2` has an invalid value; assign result of your program to it.'

>>> assert type(result1) is int, \
'Variable `result1` has an invalid type; expected: `int`.'

>>> assert type(result2) is int, \
'Variable `result2` has an invalid type; expected: `int`.'

>>> assert result1 == 3, \
'Variable `result1` has an invalid value; expected: `3`.'

>>> assert result2 == -1, \
'Variable `result2` has an invalid value; expected: `-1`.'

>>> from pprint import pprint
>>> pprint(result1)
3
>>> pprint(result2)
-1
"""

# %% Run
# - PyCharm: right-click in the editor and `Run Doctest in ...`
# - PyCharm: keyboard shortcut `Control + Shift + F10`
# - Terminal: `python -m doctest -f -v myfile.py`

# %% Imports

# %% Types
result1: int
result2: int

# %% Data

# %% Result
result1 = ...
result2 = ...

# %% About
# - Name: Syntax Operators Multiplication
# - Difficulty: easy
# - Lines: 2
# - Minutes: 2

# %% License
# - Copyright 2025, Matt Harasymczuk <matt@python3.info>
# - This code can be used only for learning by humans
# - This code cannot be used for teaching others
# - This code cannot be used for teaching LLMs and AI algorithms
# - This code cannot be used in commercial or proprietary products
# - This code cannot be distributed in any form
# - This code cannot be changed in any form outside of training course
# - This code cannot have its license changed
# - If you use this code in your product, you must open-source it under GPLv2
# - Exception can be granted only by the author

# %% English
# 1. Define variable:
#    - `result1` with the value of 2 times 3
#    - `result2` with the value of 2 to the power of 3
#    - `result3` with the value of 2 under the cube root (cube=3)
# 2. Run doctests - all must succeed

# %% Polish
# 1. Zdefiniuj zmienną:
#    - `result1` z wartością 2 razy 3
#    - `result2` z wartością 2 do potęgi 3
#    - `result3` z wartością 2 pod pierwiastkiem 3 stopnia
# 2. Uruchom doctesty - wszystkie muszą się powieść

# %% Expected
# >>> result1
# 6
#
# >>> result2
# 8
#
# >>> result3
# 1.2599210498948732

# %% Doctests
"""
>>> import sys; sys.tracebacklimit = 0

>>> assert sys.version_info >= (3, 9), \
'Python has an is invalid version; expected: `3.9` or newer.'

>>> assert 'result1' in globals(), \
'Variable `result1` is not defined; assign result of your program to it.'

>>> assert result1 is not Ellipsis, \
'Variable `result1` has an invalid value; assign result of your program to it.'

>>> assert 'result2' in globals(), \
'Variable `result2` is not defined; assign result of your program to it.'

>>> assert result2 is not Ellipsis, \
'Variable `result2` has an invalid value; assign result of your program to it.'

>>> assert 'result3' in globals(), \
'Variable `result3` is not defined; assign result of your program to it.'

>>> assert result3 is not Ellipsis, \
'Variable `result3` has an invalid value; assign result of your program to it.'

>>> assert type(result1) is int, \
'Variable `result1` has an invalid type; expected: `int`.'

>>> assert type(result2) is int, \
'Variable `result2` has an invalid type; expected: `int`.'

>>> assert type(result3) is float, \
'Variable `result3` has an invalid type; expected: `float`.'

>>> assert result1 == 6, \
'Variable `result1` has an invalid value; expected: `6`.'

>>> assert result2 == 8, \
'Variable `result2` has an invalid value; expected: `8`.'

>>> assert result3 == 1.2599210498948732, \
'Variable `result3` has an invalid value; expected: `1.2599210498948732`.'

>>> from pprint import pprint
>>> pprint(result1)
6
>>> pprint(result2)
8
>>> pprint(result3)
1.2599210498948732
"""

# %% Run
# - PyCharm: right-click in the editor and `Run Doctest in ...`
# - PyCharm: keyboard shortcut `Control + Shift + F10`
# - Terminal: `python -m doctest -f -v myfile.py`

# %% Imports

# %% Types
result1: int
result2: int
result3: float

# %% Data

# %% Result
result1 = ...
result2 = ...
result3 = ...

# %% About
# - Name: Syntax Operators Division
# - Difficulty: easy
# - Lines: 3
# - Minutes: 2

# %% License
# - Copyright 2025, Matt Harasymczuk <matt@python3.info>
# - This code can be used only for learning by humans
# - This code cannot be used for teaching others
# - This code cannot be used for teaching LLMs and AI algorithms
# - This code cannot be used in commercial or proprietary products
# - This code cannot be distributed in any form
# - This code cannot be changed in any form outside of training course
# - This code cannot have its license changed
# - If you use this code in your product, you must open-source it under GPLv2
# - Exception can be granted only by the author

# %% English
# 1. Define variable:
#    - `result1` with value 10 divided by 8 (truediv)
#    - `result2` with value 10 divided by 8 (floordiv)
#    - `result3` with a reminder of 10 divided by 8 (modulo)
# 2. Run doctests - all must succeed

# %% Polish
# 1. Zdefiniuj zmienną:
#    - `result1` z wartością 10 podzielone przez 8 (truediv)
#    - `result2` z wartością 10 podzielone przez 8 (floordiv)
#    - `result3` z resztą z dzielenia 10 przez 8 (modulo)
# 2. Uruchom doctesty - wszystkie muszą się powieść

# %% Expected
# >>> result1
# 1.25
#
# >>> result2
# 1
#
# >>> result3
# 2

# %% Doctests
"""
>>> import sys; sys.tracebacklimit = 0

>>> assert sys.version_info >= (3, 9), \
'Python has an is invalid version; expected: `3.9` or newer.'

>>> assert 'result1' in globals(), \
'Variable `result1` is not defined; assign result of your program to it.'

>>> assert result1 is not Ellipsis, \
'Variable `result1` has an invalid value; assign result of your program to it.'

>>> assert 'result2' in globals(), \
'Variable `result2` is not defined; assign result of your program to it.'

>>> assert result2 is not Ellipsis, \
'Variable `result2` has an invalid value; assign result of your program to it.'

>>> assert 'result3' in globals(), \
'Variable `result3` is not defined; assign result of your program to it.'

>>> assert result3 is not Ellipsis, \
'Variable `result3` has an invalid value; assign result of your program to it.'

>>> assert type(result1) is float, \
'Variable `result1` has an invalid type; expected: `float`.'

>>> assert type(result2) is int, \
'Variable `result2` has an invalid type; expected: `int`.'

>>> assert type(result3) is int, \
'Variable `result3` has an invalid type; expected: `int`.'

>>> assert result1 == 1.25, \
'Variable `result1` has an invalid value; expected: `1.25`.'

>>> assert result2 == 1, \
'Variable `result2` has an invalid value; expected: `1`.'

>>> assert result3 == 2, \
'Variable `result3` has an invalid value; expected: `2`.'

>>> from pprint import pprint
>>> pprint(result1)
1.25
>>> pprint(result2)
1
>>> pprint(result3)
2
"""

# %% Run
# - PyCharm: right-click in the editor and `Run Doctest in ...`
# - PyCharm: keyboard shortcut `Control + Shift + F10`
# - Terminal: `python -m doctest -f -v myfile.py`

# %% Imports

# %% Types
result1: float
result2: int
result2: int

# %% Data

# %% Result
result1 = ...
result2 = ...
result3 = ...

# %% About
# - Name: Syntax Operators Even/Odd
# - Difficulty: easy
# - Lines: 1
# - Minutes: 2

# %% License
# - Copyright 2025, Matt Harasymczuk <matt@python3.info>
# - This code can be used only for learning by humans
# - This code cannot be used for teaching others
# - This code cannot be used for teaching LLMs and AI algorithms
# - This code cannot be used in commercial or proprietary products
# - This code cannot be distributed in any form
# - This code cannot be changed in any form outside of training course
# - This code cannot have its license changed
# - If you use this code in your product, you must open-source it under GPLv2
# - Exception can be granted only by the author

# %% English
# 1. Define variable `result` with result
#    of checking if `NUMBER` is even
# 2. Run doctests - all must succeed

# %% Polish
# 1. Zdefiniuj zmienną `result` z wynikiem
#    sprawdzenia czy `NUMBER` jest parzyste
# 2. Uruchom doctesty - wszystkie muszą się powieść

# %% Expected
# >>> result
# 1

# %% Doctests
"""
>>> import sys; sys.tracebacklimit = 0

>>> assert sys.version_info >= (3, 9), \
'Python has an is invalid version; expected: `3.9` or newer.'

>>> assert 'result' in globals(), \
'Variable `result` is not defined; assign result of your program to it.'

>>> assert result is not Ellipsis, \
'Variable `result` has an invalid value; assign result of your program to it.'

>>> assert type(result) is bool, \
'Variable `result` has an invalid type; expected: `bool`.'

>>> assert result == 1, \
'Variable `result` has an invalid value; expected: `1`.'

>>> from pprint import pprint
>>> pprint(result)
1
"""

# %% Run
# - PyCharm: right-click in the editor and `Run Doctest in ...`
# - PyCharm: keyboard shortcut `Control + Shift + F10`
# - Terminal: `python -m doctest -f -v myfile.py`

# %% Imports

# %% Types
result: bool

# %% Data
NUMBER = 4

# %% Result
result = ...

# %% About
# - Name: Syntax Operators Increment
# - Difficulty: easy
# - Lines: 1
# - Minutes: 1

# %% License
# - Copyright 2025, Matt Harasymczuk <matt@python3.info>
# - This code can be used only for learning by humans
# - This code cannot be used for teaching others
# - This code cannot be used for teaching LLMs and AI algorithms
# - This code cannot be used in commercial or proprietary products
# - This code cannot be distributed in any form
# - This code cannot be changed in any form outside of training course
# - This code cannot have its license changed
# - If you use this code in your product, you must open-source it under GPLv2
# - Exception can be granted only by the author

# %% English
# 1. Increment variable `result` by 1
# 2. Use `+=` operator
# 3. Run doctests - all must succeed

# %% Polish
# 1. Zwiększ zmienną `result` o 1
# 2. Użyj operatora `+=`
# 3. Uruchom doctesty - wszystkie muszą się powieść

# %% Expected
# >>> result
# 11

# %% Doctests
"""
>>> import sys; sys.tracebacklimit = 0

>>> assert sys.version_info >= (3, 9), \
'Python has an is invalid version; expected: `3.9` or newer.'

>>> assert 'result' in globals(), \
'Variable `result` is not defined; assign result of your program to it.'

>>> assert result is not Ellipsis, \
'Variable `result` has an invalid value; assign result of your program to it.'

>>> assert type(result) is int, \
'Variable `result` has an invalid type; expected: `int`.'

>>> assert result == 11, \
'Variable `result` has an invalid value; expected: `11`.'

>>> from pprint import pprint
>>> pprint(result)
11
"""

# %% Run
# - PyCharm: right-click in the editor and `Run Doctest in ...`
# - PyCharm: keyboard shortcut `Control + Shift + F10`
# - Terminal: `python -m doctest -f -v myfile.py`

# %% Imports

# %% Types
result: int

# %% Data
result = 10

# %% Result

# %% About
# - Name: Syntax Operators Decrement
# - Difficulty: easy
# - Lines: 1
# - Minutes: 1

# %% License
# - Copyright 2025, Matt Harasymczuk <matt@python3.info>
# - This code can be used only for learning by humans
# - This code cannot be used for teaching others
# - This code cannot be used for teaching LLMs and AI algorithms
# - This code cannot be used in commercial or proprietary products
# - This code cannot be distributed in any form
# - This code cannot be changed in any form outside of training course
# - This code cannot have its license changed
# - If you use this code in your product, you must open-source it under GPLv2
# - Exception can be granted only by the author

# %% English
# 1. Decrement variable `result` by 1
# 2. Use `-=` operator
# 3. Run doctests - all must succeed

# %% Polish
# 1. Zmniejsz zmienną `result` o 1
# 2. Użyj operatora `-=`
# 3. Uruchom doctesty - wszystkie muszą się powieść

# %% Expected
# >>> result
# 9

# %% Doctests
"""
>>> import sys; sys.tracebacklimit = 0

>>> assert sys.version_info >= (3, 9), \
'Python has an is invalid version; expected: `3.9` or newer.'

>>> assert 'result' in globals(), \
'Variable `result` is not defined; assign result of your program to it.'

>>> assert result is not Ellipsis, \
'Variable `result` has an invalid value; assign result of your program to it.'

>>> assert type(result) is int, \
'Variable `result` has an invalid type; expected: `int`.'

>>> assert result == 9, \
'Variable `result` has an invalid value; expected: `9`.'

>>> from pprint import pprint
>>> pprint(result)
9
"""

# %% Run
# - PyCharm: right-click in the editor and `Run Doctest in ...`
# - PyCharm: keyboard shortcut `Control + Shift + F10`
# - Terminal: `python -m doctest -f -v myfile.py`

# %% Imports

# %% Types
result: int

# %% Data
result = 10

# %% Result

# %% About
# - Name: Syntax Operators Comparison
# - Difficulty: easy
# - Lines: 4
# - Minutes: 2

# %% License
# - Copyright 2025, Matt Harasymczuk <matt@python3.info>
# - This code can be used only for learning by humans
# - This code cannot be used for teaching others
# - This code cannot be used for teaching LLMs and AI algorithms
# - This code cannot be used in commercial or proprietary products
# - This code cannot be distributed in any form
# - This code cannot be changed in any form outside of training course
# - This code cannot have its license changed
# - If you use this code in your product, you must open-source it under GPLv2
# - Exception can be granted only by the author

# %% English
# 1. Define variable `result1` with result of checking if 1 is greater than 2
# 2. Define variable `result2` with result of checking if 1 is greater or equal than 2
# 3. Define variable `result3` with result of checking if 1 is less than 2
# 4. Define variable `result4` with result of checking if 1 is less or equal than 2
# 5. Run doctests - all must succeed

# %% Polish
# 1. Zdefiniuj zmienną `result1` z wynikiem sprawdzenia, czy 1 jest większe od 2
# 2. Zdefiniuj zmienną `result2` z wynikiem sprawdzenia, czy 1 jest większe lub równe 2
# 3. Zdefiniuj zmienną `result3` z wynikiem sprawdzenia, czy 1 jest mniejsze od 2
# 4. Zdefiniuj zmienną `result4` z wynikiem sprawdzenia, czy 1 jest mniejsze lub równe od 2
# 5. Uruchom doctesty - wszystkie muszą się powieść

# %% Expected
# >>> result1
# False
#
# >>> result2
# False
#
# >>> result3
# True
#
# >>> result4
# True

# %% Doctests
"""
>>> import sys; sys.tracebacklimit = 0

>>> assert sys.version_info >= (3, 9), \
'Python has an is invalid version; expected: `3.9` or newer.'

>>> assert 'result1' in globals(), \
'Variable `result1` is not defined; assign result of your program to it.'

>>> assert result1 is not Ellipsis, \
'Variable `result1` has an invalid value; assign result of your program to it.'

>>> assert type(result1) is bool, \
'Variable `result1` has an invalid type; expected: `bool`.'

>>> assert result1 == False, \
'Variable `result1` has an invalid value; expected: `False`.'

>>> assert 'result2' in globals(), \
'Variable `result2` is not defined; assign result of your program to it.'

>>> assert result2 is not Ellipsis, \
'Variable `result2` has an invalid value; assign result of your program to it.'

>>> assert type(result2) is bool, \
'Variable `result2` has an invalid type; expected: `bool`.'

>>> assert result2 == False, \
'Variable `result2` has an invalid value; expected: `False`.'

>>> assert 'result3' in globals(), \
'Variable `result3` is not defined; assign result of your program to it.'

>>> assert result3 is not Ellipsis, \
'Variable `result3` has an invalid value; assign result of your program to it.'

>>> assert type(result3) is bool, \
'Variable `result3` has an invalid type; expected: `bool`.'

>>> assert result3 == True, \
'Variable `result3` has an invalid value; expected: `True`.'

>>> assert 'result4' in globals(), \
'Variable `result4` is not defined; assign result of your program to it.'

>>> assert result4 is not Ellipsis, \
'Variable `result4` has an invalid value; assign result of your program to it.'

>>> assert type(result4) is bool, \
'Variable `result4` has an invalid type; expected: `bool`.'

>>> assert result4 == True, \
'Variable `result4` has an invalid value; expected: `True`.'

>>> from pprint import pprint
>>> pprint(result1)
False
>>> pprint(result2)
False
>>> pprint(result3)
True
>>> pprint(result4)
True
"""

# %% Run
# - PyCharm: right-click in the editor and `Run Doctest in ...`
# - PyCharm: keyboard shortcut `Control + Shift + F10`
# - Terminal: `python -m doctest -f -v myfile.py`

# %% Imports

# %% Types
result1: bool
result2: bool
result3: bool
result4: bool

# %% Data

# %% Result
result1 = ...
result2 = ...
result3 = ...
result4 = ...

# %% About
# - Name: Syntax Operators Equality
# - Difficulty: easy
# - Lines: 2
# - Minutes: 2

# %% License
# - Copyright 2025, Matt Harasymczuk <matt@python3.info>
# - This code can be used only for learning by humans
# - This code cannot be used for teaching others
# - This code cannot be used for teaching LLMs and AI algorithms
# - This code cannot be used in commercial or proprietary products
# - This code cannot be distributed in any form
# - This code cannot be changed in any form outside of training course
# - This code cannot have its license changed
# - If you use this code in your product, you must open-source it under GPLv2
# - Exception can be granted only by the author

# %% English
# 1. Define variable `result1` with result of checking if 1 is equal to 2
# 2. Define variable `result2` with result of checking if 1 is not equal 2
# 3. Run doctests - all must succeed

# %% Polish
# 1. Zdefiniuj zmienną `result1` z wynikiem sprawdzenia, czy 1 jest równe 2
# 2. Zdefiniuj zmienną `result2` z wynikiem sprawdzenia, czy 1 jest różne od 2
# 3. Uruchom doctesty - wszystkie muszą się powieść

# %% Expected
# >>> result1
# False
#
# >>> result2
# True

# %% Doctests
"""
>>> import sys; sys.tracebacklimit = 0

>>> assert sys.version_info >= (3, 9), \
'Python has an is invalid version; expected: `3.9` or newer.'

>>> assert 'result1' in globals(), \
'Variable `result1` is not defined; assign result of your program to it.'

>>> assert result1 is not Ellipsis, \
'Variable `result1` has an invalid value; assign result of your program to it.'

>>> assert type(result1) is bool, \
'Variable `result1` has an invalid type; expected: `bool`.'

>>> assert result1 == False, \
'Variable `result1` has an invalid value; expected: `False`.'

>>> assert 'result2' in globals(), \
'Variable `result2` is not defined; assign result of your program to it.'

>>> assert result2 is not Ellipsis, \
'Variable `result2` has an invalid value; assign result of your program to it.'

>>> assert type(result2) is bool, \
'Variable `result2` has an invalid type; expected: `bool`.'

>>> assert result2 == True, \
'Variable `result2` has an invalid value; expected: `True`.'


>>> from pprint import pprint
>>> pprint(result1)
False
>>> pprint(result2)
True
"""

# %% Run
# - PyCharm: right-click in the editor and `Run Doctest in ...`
# - PyCharm: keyboard shortcut `Control + Shift + F10`
# - Terminal: `python -m doctest -f -v myfile.py`

# %% Imports

# %% Types
result1: bool
result2: bool

# %% Data

# %% Result
result1 = ...
result2 = ...