Operators - 1 - Jupyter Notebook
Operators - 1 - Jupyter Notebook
Operators:
An operator is a special symbol upon which we perform some
operations on variables and values.
Assignment Operators:
Assignment operators are used to assign values to variables:
In [2]: x = 5
print(x)
In [7]: x = 5
x+=10
print(x)
15
In [8]: y = 10
y%=2
print(y)
Arithmetic Operators:
Arithmetic operators are used with numeric values to perform common m
athematical operations:
In [9]: a = 10
b = 5
print(a/b)
2.0
In [10]: a = 10
b = 5
print(a//b)
In [11]: a = 10
b = 5
print(a**b)
100000
In [12]: a = 10
b = 5
print(a%b)
Comparison Operators:
Comparison operators are used to compare two values and returns a boo
lean value:
In [13]: a = 10
b = 12
print(a>b)
False
In [14]: a = 10
b = 12
print(a==b)
False
In [15]: a = 10
b = 10
print(a==b)
True
In [16]: a = 10
b = 12
print(a!=b)
True
Logical Operators:
logical operators are used to combine conditional statements:
In [17]: print((5>4)and(6<7))
True
In [18]: print((5>4)or(5!=5))
True
In [19]: print(not(5>5))
True
Membership Operators:
in : True if var is the sequence.
False if var is not in the sequence
Out[20]: True
Out[21]: False
Out[22]: False
Out[23]: True
In [ ]: