2.4. Type None

2.4.1. Type Definition

  • First letter capitalized, other are lower cased

  • Empty (null) or unknown (unset) value

  • It is not False value

  • With if statements behaves like negative values

Listing 2.13. NoneType Type Definition
data = None

2.4.2. Comparision

  • Do not use == or != to check None values (it works, but you shouldn't)

age = None

age == None             # True
age != None             # False

2.4.3. Identity

  • x is None - x is the same object as y

  • x is not None - x is not the same object as y

age = None

age is None             # True
age is not None         # False

2.4.4. Assignments

2.4.4.1. Is None or not

  • Complexity level: easy

  • Lines of code to write: 5 lines

  • Estimated time of completion: 5 min

  • Solution: solution/type_none.py

English
  1. Use data from "Input" section (see below)

  2. What you need to put in expressions to get the expected outcome?

  3. Compare result with "Output" section (see below)

Polish
  1. Użyj danych z sekcji "Input" (patrz poniżej)

  2. Co należy podstawić w wyrażeniach aby otrzymać wartość oczekiwaną?

  3. Porównaj wyniki z sekcją "Output" (patrz poniżej)

Input
a = ... is None                                                                       # True
b = ... is not None                                                                   # False
c = bool(bool(...) is not bool(...)) == False                                         # True
d = (bool(bool(...) is not bool(...)) == False and bool(...))                         # False
e = (bool(bool(...) is not bool(...)) == False and bool(...)) and (... is not None)   # False
Output
print(a)    # True
print(b)    # False
print(c)    # True
print(d)    # False
print(e)    # False
The whys and wherefores
  • Defining variables

  • Type casting

  • Logic types

Todo

Create more assignments