R Day - 2 - DSIB - Ipynb - Colab
R Day - 2 - DSIB - Ipynb - Colab
print("python version")
print(sys.version)
print("version info.")
print (sys.version_info)
python version
3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0]
version info.
sys.version_info(major=3, minor=10, micro=12, releaselevel='final', serial=0)
import sys
print("python version")
p
Operators
Arithmatic operators
Assignment operators
Comparison operators
Logical operators
Identity operators
Membership operators
a=7
b=3
print("Addition", a+b)
print("Substraction",a-b)
print("Substraction",b-a)
print("Multiplication",a*b)
print("Division",a/b)
print("Modulus",a%b)
print("Exponentation", a**b) #a raise to b
print("Exponentation", b**a) #b raise to a
print("Floor Division",a//b) #Rounds up the value
Addition 10
Substraction 4
Substraction -4
Multiplication 21
Division 2.3333333333333335
Modulus 1
Exponentation 343
Exponentation 2187
Floor Division 2
In Python, we can perform floor division (also sometimes known as integer division) using the // operator.
This operator will divide the first argument by the second and round the result down to the nearest whole number, making it equivalent to the
math. floor() function
Arithmatic Operators
Arithmatic operators are used with numeric values to perform common mathematical operations.
Addition +
Substraction -
Multiplication *
Division /
Modulus %
Exponentiation **
Floor Division //
Assignments Operators
x=3
x+=4 # x=x+4
print(x)
y=6
y-=3 #y=y-3
print(y)
3
a=8
a*=4 #a=a*4
print(a)
32
b=12
b/=2 #b=b/2
print(b)
6.0
b=12
b//=2 #b=b//2
print(b)
6
c=5
c%=2 #c=c%2
print(c)
1
d=2
d**=5 #d=d**2
print(d)
32
b=12
b//=2
print(b)
6
a=7
b=5
c=a/b
print(c)
f=a//b
print(f)
1.4
1
Comparison Operators
a=5
b=6
print(a!=b)
True
a=4
b=5
print(a==b)
False
a=5
b=5
print(a>b)
False
a=4
b=5
print(a<b)
True
a=5
b=5
print(b>=4) #5>=5
True
a=4
b=5
print(b<=a)
False
Logical Operators
a=10
b=20
print(a<b and b>a)
True
a=10
b=20
print(a<b and b>a)
a=20
b=10
print(a<b and b>a)
print(a>b or b>a)
print(a<b or b<a)
print(not(a<b and b>a))
print(not(a>b or b>a))
True
False
True
True
True
False
a=10
b=20
#print(a<b and b>a)
#print(a>b or b>a)
#print(a<b or b<a)
#print(not(a<b and b>a))
print(not(a>b or b>a))
False
Identity operators
These are used to compare the objects, not if they are equal, but if they are actually the same object, with the same memory location.
These are used to compare the objects, if they are actually the same object, with the same memory location then its returns true otherwise
false.
is - Returns True if both variables are the same object with the same memory location
x is y
is not - Returns True if both variables are not the same object with not the same memory location
x is not y
is true false
is not true false
a=['a','b']
b=['a','b']
print(a is b)
False
id(a)
136156395323328
id(b)
136156395319296
a=['a','b']
c=a
print(a is c)
True
a=['a','b']
b=['a','b']
#c=a
print(a is not b)
True
a=['a','b']
c=a
print(a is not c)
False
Membership operator
in - Returns True if a sequence with the specified value is present in the object
x in y
not in - Returns True if a sequence with the specified value is not present in the object
x is not in y
in true false
not in true false