3. Logical Types

3.1. bool

3.1.1. Defining bool values

  • First letter capitalized, other are lower cased

  • Positive value - True

  • Negative values - False

  • Defining bool:

    my_var = True
    my_var = False
    
    my_var: bool = True
    my_var: bool = False
    

3.1.2. Type casting to bool

bool('José')          # True
bool('')              # False

3.1.3. Negative values

  • False
  • 0
  • () - empty tuple
  • {} - empty dict
  • [] - empty list
  • '' - empty str
  • set() - empty set
  • None

3.1.4. Using and

'José' and ''         # False
'José' and 'Иван'     # True

3.1.5. Using or

'José' or ''          # True
'José' or 'Иван'      # True

3.2. None

3.2.1. Defining None values

  • First letter capitalized, other are lower cased

  • Empty value (null)

  • It is not False value, although in if it behaves like False

  • With if statements behaves like negative values

  • Used for unknown (unset) values:

    my_var = None
    

3.3. Assignments

3.3.1. Bool

  1. Wprowadzono zmienne:

    a = False
    b = True
    c = None
    d = ''
    e = ' '
    f = 'a'
    g = '.'
    h = 0
    i = 0.0
    j = '0'
    k = '0.0'
    l = -0
    m = -0.0+0.0j
    n = int('0')
    o = float('0')
    
  2. Które zmienne mają wartość True, None, False?

  3. Czym się różni None od False?

About:
  • Filename: types_bool.py
  • Lines of code to write: 15 lines
  • Estimated time of completion: 10 min
The whys and wherefores:
 
  • Definiowanie zmiennych
  • Konwersja typów
  • Typy logiczne