Lecture 10
Lecture 10
LECTURE 10
QUIZ 2- Test Your Skills
A. 31 characters
B. 63 characters
C. 79 characters
D. none of the mentioned
Correct Answer: D
QUIZ 2- Test Your Skills
A. Class
B. List
C. Str
D. Tuple
Correct Answer: A
QUIZ 2- Test Your Skills
A. hel
B. he
C. Lo
D. olleh
Correct Answer: B
QUIZ- Test Your Skills
A. int
B. float
C. bool
D. dict
Correct Answer: A
QUIZ- Test Your Skills
Correct Answer: C
QUIZ- Test Your Skills
A. k = 2 + 3j
B. k = complex(2)
C. k = 2 + 3I
D. k = 2 + 3J
Correct Answer: C
QUIZ- Test Your Skills
A. k = 0b101
B. k= 0x4f5
C. k = 19023
D. k = 0o3964
Correct Answer: D
QUIZ- Test Your Skills
A. False
B. True
C. SyntaxError
D. 0
Correct Answer: B
QUIZ- Test Your Skills
A. List
B. Tuple
C. Both
D. None
Correct Answer: A
QUIZ- Test Your Skills
A. Yes
B. No
Correct Answer: A
QUIZ- Test Your Skills
A. Yes
B. No
Correct Answer: B
QUIZ- Test Your Skills
A. Yes
B. No
Correct Answer:B
QUIZ- Test Your Skills
A. include math
B. import math
C. #include<math.h>
D. using math
Correct Answer: B
QUIZ- Test Your Skills
A. chr
B. char
C. str
D. None Of The Above
Correct Answer: D
QUIZ- Test Your Skills
Correct Answer: C
Today’s Agenda
• Operators In Python
• Types Of Operators
• Arithmetic Operators
• Arithmetic Operators
• Relational or Comparison Operators
• Logical Operators
• Assignment Operator
• Bitwise Operators
• Identity Operators
• Membership Operators
Arithmetic Operators
In Python
+
(Arithmetic Addition)
-
(Subtraction)
*
(Arithmetic Multiplication)
/
(Float Division)
%
(Modulo Division)
//
(Floor Division)
**
(Power or Exponentiation)
The 5 Basic Arithmetic
Operators
mymath.py
a=10
b=4
print("sum of",a,"and",b,"is",a+b)
print("diff of",a,"and",b,"is",a-b)
print("prod of",a,"and",b,"is",a*b)
print("div of",a,"and",b,"is",a/b)
print("rem of",a,“and",b,"is",a%b)
The 5 Basic Arithmetic
Operators
The Output:
Two Special
Operators // and **
• Example: • Example:
a=10.0
a=10
b=4
b=4 print(a//b)
print(a//b)
• Output:
• Output: 2.0
2
• Example: • Example:
a=97
a=97
b=10.0
b=10 print(a//b)
print(a//b)
• Output:
• Output: 9.0
9
The Floor Division Operator
• Example: • Example:
a=19
a=-10
b=-2
b=4 print(a//b)
print(a//b)
• Output:
• Output: -10
-3
The Floor Division Operator
• Example: • Example:
a=-19
a=-10
b=-2
b=-4 print(a//b)
print(a//b)
• Output:
• Output: 9
2
An Important Point
• Example: • Example:
a=10
a=10
b=0.0
b=0 print(a/b)
print(a/b)
• Output:
• Output: ZeroDivisionError
ZeroDivisionError
Division By 0
• Example: • Example:
a=10
a=10
b=0.0
b=0 print(a//b)
print(a//b)
• Output:
• Output: ZeroDivisionError
ZeroDivisionError
Division By 0
• Example: • Example:
a=10
a=10
b=0.0
b=0 print(a%b)
print(a%b)
• Output:
• Output: ZeroDivisionError
ZeroDivisionError
The power (**)Operator
• For example:
a=10
b=3
print(a**b)
• Output:
1000
Double Role Of The
Operator +
• For example:
a=10
a=“Good”
b=5 b=“Evening”
print(a+b) print(a+b)
Output: Output:
GoodEvening
15
Double Role Of The
Operator +
• Example: • Example:
a=“Good”
a=“Good”
b=“10”
b=10 print(a+b)
print(a+b)
• Output:
• Output: Good10
TypeError
Double Role Of The
Operator *
• For example:
a=10 a=“Sachin”
b=5 b=3
print(a*b) print(a*b)
Output: Output:
50 SachinSachinSachin
The * Operator
• Example: • Example:
a=“Sachin”
a=5
b=3.0
b=4.0 print(a*b)
print(a*b)
• Output:
• Output: Type Error :
20.0 Can’t multiply
by non int
The * Operator
• Example: • Example:
a=“Sachin”
a=“Sachin”
b=“Kapoor”
b=3 print(a*b)
print(b*a)
• Output:
• Output: Type Error :
SachinSachinSachin Can’t multiply
by non int