forked from inspirezonetech/TeachMePythonLikeIm5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbooleans.py
62 lines (48 loc) · 1.83 KB
/
booleans.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# ------------------------------------------------------------------------------------
# Tutorial: Understanding Boolean variables
# ------------------------------------------------------------------------------------
# Boolean variables are defined by the True and False keywords
# eg: a = True
# We can check type of variables by printing : type(var_name)
# If it is of type boolean it will return : <class 'bool'>
# bool() method can be used to convert value to boolean value
# It returns True if the parameter or value passed is True
# It returns False if the parameter or value passed is False with some exceptions such as
# If False value is passed, None is passed, an empty sequence is passed such as (), [], ”, etc, or if Zero is passed in any numeric type such as 0, 0.0, etc.
def Boolean():
# Returns True as x is True
x = True
print(bool(x))
# Returns False as x is False
x = False
print(bool(x))
# Returns False as x is not equal to y
x = 15
y = 18
print(bool(x == y))
# Returns False as x is None
x = None
print(bool(x))
# Returns False as x is an empty sequence
x = ()
print(bool(x))
# Returns False as x is an emty mapping
x = []
print(bool(x))
# Returns False as x is 0
x = 0.00
print(bool(x))
# Returns True as x is a non empty string
x = 'This is Boolean Tutorial'
print(bool(x))
Boolean()
# any expression in Python is True or False
print("Basic boolean:", 5 == 5, type(5 == 5))
def Challenge(arg1, arg2, arg3):
print("Challenge:")
print(bool(arg1))
print(bool(arg2))
print(bool(arg3))
Challenge([], 125, True)
# --------------------------------------CHALLENGE----------------------------------------------
# Challenge: call the Challenge function and pass the values '0.00', '{1, 341, 56}' and 'False' to the function