-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBoolean_Operator.py
37 lines (29 loc) · 1006 Bytes
/
Boolean_Operator.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
# Boolean variables can either be True or False
# Boolean examples in Kaggle: https://github.com/SciComp8/Python_Programming/blob/main/Kaggle/Learn_Python/Booleans_Conditionals.py
# Operator precedence: https://docs.python.org/3/reference/expressions.html#operator-precedence
out_of_donut = True
if out_of_donut:
print("Please run to the supermarket NOW!")
# Truthy values: non 0; non-empty string; non-empty list; non-empty dictionary; non-empty tuple
# Falsey valuees: 0; ""; []; {}; (); None
donut_list = []
# Check the truthiness of donut_list
print(bool(donut_list))
# False
# The highest precedence belongs to (), followed by not, and, and or.
# ==
# is True | is False
# !=
# <
# <=
# >
# >=
donut_qty == 10
# Be careful with equality comparisons of floats
x = 0.1 + 1.1
x == 2.1
# False
print(x)
# 1.2000000000000002
# Filter the exp column to include only the rows where y is False
exp_yno = df.exp[~y] # The ~ operator is a logical NOT operation. It inverts the boolean values in y.