Compare commits
2 Commits
05487357f0
...
f915ffb79b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f915ffb79b | ||
|
|
4f9d111e2a |
@@ -2,7 +2,9 @@ def all_thing_is_obj(object: any) -> int:
|
|||||||
# https://docs.python.org/3.10/library/functions.html?highlight=type#type
|
# https://docs.python.org/3.10/library/functions.html?highlight=type#type
|
||||||
ofType = type(object)
|
ofType = type(object)
|
||||||
|
|
||||||
|
# https://docs.python.org/3.10/tutorial/controlflow.html#match-statements
|
||||||
match object:
|
match object:
|
||||||
|
# class patterm : check against a class (check if instance when empty arguments) https://docs.python.org/3/reference/compound_stmts.html#class-patterns
|
||||||
case list():
|
case list():
|
||||||
print("List : ", ofType)
|
print("List : ", ofType)
|
||||||
case tuple():
|
case tuple():
|
||||||
|
|||||||
21
d00/ex03/NULL_not_found.py
Normal file
21
d00/ex03/NULL_not_found.py
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
def NULL_not_found(object: any) -> int:
|
||||||
|
nullType = type(object)
|
||||||
|
|
||||||
|
match object:
|
||||||
|
case None:
|
||||||
|
print("Nothing:", object, nullType)
|
||||||
|
# using a guard https://docs.python.org/3/reference/compound_stmts.html#guards
|
||||||
|
# (NaN == NaN) = false https://docs.python.org/3.10/reference/expressions.html#value-comparisons "A counter-intuitive implication is that not-a-number values are not equal to themselves"
|
||||||
|
case float() if object != object:
|
||||||
|
print("Cheese:", object, nullType)
|
||||||
|
case bool() if object == False :
|
||||||
|
print("Fake:", object, nullType)
|
||||||
|
case int() if object == 0 :
|
||||||
|
print("Zero:", object, nullType)
|
||||||
|
case str() if object == '' :
|
||||||
|
print("Empty:", object, nullType)
|
||||||
|
case _:
|
||||||
|
print("Type not Found")
|
||||||
|
return 1
|
||||||
|
|
||||||
|
return 0
|
||||||
21
d00/ex03/tester.py
Normal file
21
d00/ex03/tester.py
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
from NULL_not_found import NULL_not_found
|
||||||
|
|
||||||
|
Nothing = None
|
||||||
|
Garlic = float("NaN")
|
||||||
|
Garlic2 = float("2")
|
||||||
|
Zero = 0
|
||||||
|
Empty = '' # ’’
|
||||||
|
Fake = False
|
||||||
|
Right = True
|
||||||
|
|
||||||
|
NULL_not_found(Nothing)
|
||||||
|
NULL_not_found(Garlic)
|
||||||
|
NULL_not_found(Zero)
|
||||||
|
NULL_not_found(Empty)
|
||||||
|
NULL_not_found(Fake)
|
||||||
|
print(NULL_not_found("Brian"))
|
||||||
|
|
||||||
|
print("--")
|
||||||
|
NULL_not_found(Garlic2)
|
||||||
|
NULL_not_found(Right)
|
||||||
|
print(NULL_not_found(""))
|
||||||
Reference in New Issue
Block a user