-
Notifications
You must be signed in to change notification settings - Fork 0
/
operators.py
143 lines (110 loc) · 3.88 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# # Type of operators in python
# 1. Arithmetic Operators
# 2. Assignment Operators
# 3. Comparison Operators
# 4. Logical Operators
# 5. Identity Operators
# 6. Membership Operators
# 7. Bitwise Operators
# 1. Assignment Operators
# assignment operators are used to do numeric caculation
# examples of assignment operators are :- +, -, *, **, /, //, %
# add operator "+" = gives addition of numbers
# subtraction operator "-" = gives substraction of numbers
# multiplication operator "*" = gives multiplied value of numbers
# exponent operator "**" = gives exponential value
# divide operator "/" = gives divided value
# divide operator "//" = gives divided value in integer
# modulus operator "%" = gives reminder of the dividion operation
# print("5+6 =",5+6)
# print("5-6 =",5-6)
# print("5*6 =",5*6)
# print("5**3 =",5**3)
# print("5/6 =",5/6)
# print("5//6 =",5//6)
# print("5%6 =",5%6)
# 2. Assignment Operators
# assignment operators are used to assign values to variables
# example of assignment operators are :- =, +=, -=, *=, /=, %=, //=, **=
# equals to assignment operator "=" = assign values to variables
# "+=" assignment operator = example:- x+=5("+=" stands for "x = x+5")
# "-=" assignment operator = example:- x-=5("-=" stands for "x = x-5")
# "*=" assignment operator = example:- x*=5("*=" stands for "x = x*5")
# "/=" assignment operator = example:- x/=5("/=" stands for "x = x/5")
# "%=" assignment operator = example:- x%=5("%=" stands for "x = x%5")
# "//=" assignment operator = example:- x//=5("//=" stands for "x = x//5")
# "**=" assignment operator = example:- x**=5("**=" stands for "x = x**5")
# x = 5
# print(x)
# x+=6
# print(x)
# x-=6
# print(x)
# x*=6
# print(x)
# x/=6
# print(x)
# x%=6
# print(x)
# x//=6
# print(x)
# x**=6
# print(x)
# 3. Comparison Operators
# comparision operators are used to compare between two numbers
# examples of comparison operators are:- ==, >, <, >=, <=, !=
# "==" = equals to
# ">" = greater than
# "<" = smaller than
# ">=" = greater than equals to
# "<=" = smaller than equals to
# a = 5
# b = 10
# print(a==b)
# print(a>b)
# print(a<b)
# print(a>=b)
# print(a<=b)
# print(a!=b)
# 4. Logical Operators
# logical operators are those operators used to create condition
# examples of logical operators are:- and, or, not
# "and" logical operator = True if both the operands are true
# "or" logical operator = True if either of the operands is true
# "not" logical operator = True if operands is false
# x = 5
# y = 6
# print((x==y) and (x<y))
# print((x==y) or (x<y))
# print(not(x==y))
# 5. Identity Operators
# identity operators are used to check if the two values(or variables) are located on the same part of
# the memory. Two variables that are equal does not imply that they are identical
# examples of identity operator are:- is, is not
# "is" identity operator = True if the operands are identical(refer to the same object)
# "is not" identity operator = True if the operands are not identical(do not refer to the same object)
# a = 5
# b = 10
# c = a
# print(a is b)
# print(a is c)
# print(a is not b)
# 6. Membership Operators
# membership operators are used to test whelther a value or variable is found in a sequence(string, list, tuple,
# set and dictionary)
# example of membership operators are:- "in" and "not in"
# "in" membership operators = True if value/variable is found in the sequence
# "not in" membership operators = True if value/variable is not found in the sequence
# ls = [1, 2, 3, 4, 5]
# print(5 in ls)
# print(100 in ls)
# print(100 not in ls)
# 7. Bitwise Operators
# bitwise operators act on operands as if they were strings of binary digits. They operate bit by bit
# examples of bitwise operators are :- "&", "|", etc.
# "&" bitwise AND
# "|" bitwise OR
x = 10
y = 4
print(x & y)
print(x|y)