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.14. NoneType Type Definition
data = None

2.4.2. Comparison

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

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

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

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

age == None             # True
age != None             # False
Listing 2.16. Use identity checking for None values
age = None

age is None             # True
age is not None         # False

2.4.3. Assignments

2.4.3.1. Type None

  • Assignment name: Type None

  • Last update: 2020-10-01

  • Complexity level: easy

  • Lines of code to write: 5 lines

  • Estimated time of completion: 3 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