-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOperators.py
47 lines (47 loc) · 2.12 KB
/
Operators.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
#-----------------------------------------
# Conditional Operators
#-----------------------------------------
# They are operators that are used to perform conditional operations.For example
# 1. Less than (<)
# 2. Greater than (>)
# 3. Less than or equal to (<=)
# 4. Greater than or equal to (>=)
# 5. Equal to (==)
# 6. Not equal to (!=)
# For example
# x = 10
# y = 20
# if x > y:
# print("x is greater than y") # This stage confirms if x is greater than y (which means it is true)
# else:
# print("x is less than or equal to y") #This stage confirms if x is less than or equal to y (which means it is false)
# In the above example, the condition x > y is false, so the statement "x is less than or equal to y" is printed.
#-----------------------------------------
# Boolean Operators
#-----------------------------------------
# They are used to perform boolean operations like AND, OR, NOT, etc.
# 1. AND in python is represented by the symbol 'and'
# 2. OR in python is represented by the symbol 'or'
# 3. NOT in python is represepythonnted by the symbol 'not'
# For example
# x = 10
# y = 20
# if x > 5 and y == 10:
# print("Both conditions are true") # This stage confirms if both conditions are true
# else:
# print("At least one condition is false") #This stage confirms if at least one condition is false
# In the above example, both conditions x > 5 and y > 10 are true, so the statement "Both conditions are true" is printed.
#-----------------------------------------
# Membership Operators
#-----------------------------------------
# They are used to test if a sequence is presented in an object.
# 1. in in python is used to test if a sequence is presented in an object
# 2. not in in python is used to test if a sequence is not presented in an object
# For example
# x = [1, 2, 3, 4, 5]
# if 1 in x:
# print("1 is in the list") # This stage confirms if 1 is in the list
# else:
# print("1 is not in the list") #This stage confirms if 1 is not in the list
# In the above example, the value 1 is in the list x, so the statement "1 is in the list" is printed.
#-----------------------------------------