2.4. Type None¶
2.4.1. Definition¶
First letter capitalized, other are lower cased
Empty (null) or unknown (unset) value
It is not
False
valueWith
if
statements behaves like negative values
>>> data = None
2.4.2. Comparison (Identity Check)¶
x is None
-x
is the same object asy
x is not None
-x
is not the same object asy
>>> age = None
>>>
>>> age is None
True
>>> age is not None
False
2.4.3. Comparison (Value Check)¶
Do not use
==
or!=
to checkNone
valuesIt works, but it is a subject to change
>>> age = None
>>>
>>> age == None
True
>>> age != None
False
2.4.4. Assignments¶
"""
* Assignment: Type None
* Complexity: easy
* Lines of code: 5 lines
* Time: 3 min
English:
1. Use data from "Given" section (see below)
2. What you need to put in expressions to get the expected outcome?
3. Compare result with "Tests" section (see below)
Polish:
1. Użyj danych z sekcji "Given" (patrz poniżej)
2. Co należy podstawić w wyrażeniach aby otrzymać wartość oczekiwaną?
3. Porównaj wyniki z sekcją "Tests" (patrz poniżej)
Tests:
>>> import sys
>>> sys.tracebacklimit = 0
>>> assert result_a is not Ellipsis, 'Assignment solution must be in `result_a` instead of ... (Ellipsis)'
>>> assert result_b is not Ellipsis, 'Assignment solution must be in `result_b` instead of ... (Ellipsis)'
>>> assert result_c is not Ellipsis, 'Assignment solution must be in `result_c` instead of ... (Ellipsis)'
>>> assert result_d is not Ellipsis, 'Assignment solution must be in `result_d` instead of ... (Ellipsis)'
>>> assert result_e is not Ellipsis, 'Assignment solution must be in `result_e` instead of ... (Ellipsis)'
>>> assert type(result_a) is bool, 'Variable `result_a` has invalid type, should be bool'
>>> assert type(result_b) is bool, 'Variable `result_b` has invalid type, should be bool'
>>> assert type(result_c) is bool, 'Variable `result_c` has invalid type, should be bool'
>>> assert type(result_d) is bool, 'Variable `result_d` has invalid type, should be bool'
>>> assert type(result_e) is bool, 'Variable `result_e` has invalid type, should be bool'
>>> bool(result_a)
True
>>> bool(result_b)
False
>>> bool(result_c)
True
>>> bool(result_d)
False
>>> bool(result_e)
False
"""
# Given
a = ... # bool: True
b = ... # bool: False
c = ... # bool: True
d = ... # bool: False
e = ... # bool: False
# Do not modify following lines
result_a = a is None
result_b = b is not None
result_c = bool(bool(c) is not bool(c)) == False
result_d = bool(bool(d) is not bool(d)) == False and bool(d)
result_e = (bool(bool(e) is not bool(e)) == False and bool(e)) and (e is not None)