0% found this document useful (0 votes)
80 views38 pages

Lecture 10

This document contains a quiz on Python concepts with 15 multiple choice questions. It covers topics like Python data types, operators, strings, modules, and exceptions. The questions test knowledge of maximum identifier length, mutable vs immutable objects, arithmetic operators, floor division, power operator, string concatenation vs addition, and exceptions like ZeroDivisionError.

Uploaded by

atif khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views38 pages

Lecture 10

This document contains a quiz on Python concepts with 15 multiple choice questions. It covers topics like Python data types, operators, strings, modules, and exceptions. The questions test knowledge of maximum identifier length, mutable vs immutable objects, arithmetic operators, floor division, power operator, string concatenation vs addition, and exceptions like ZeroDivisionError.

Uploaded by

atif khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 38

PYTHON

LECTURE 10
QUIZ 2- Test Your Skills

1. What is the maximum possible length of an


identifier in Python?

A. 31 characters
B. 63 characters
C. 79 characters
D. none of the mentioned
Correct Answer: D
QUIZ 2- Test Your Skills

2. Which of these in not a core data type in Python?

A. Class
B. List
C. Str
D. Tuple

Correct Answer: A
QUIZ 2- Test Your Skills

3. Following set of commands are executed in shell, what will


be the output?
>>>str="hello"
>>>str[:2]

A. hel
B. he
C. Lo
D. olleh

Correct Answer: B
QUIZ- Test Your Skills

4. What is the return type of function id ?

A. int
B. float
C. bool
D. dict

Correct Answer: A
QUIZ- Test Your Skills

5. Which of the following results in a SyntaxError ?

A. ' ''Once upon a time…'', she said. '


B. ''He said, 'Yes!' ''
C. '3\'
D. '' That's okay ''

Correct Answer: C
QUIZ- Test Your Skills

6. Which of the following is not a complex number?

A. k = 2 + 3j
B. k = complex(2)
C. k = 2 + 3I
D. k = 2 + 3J

Correct Answer: C
QUIZ- Test Your Skills

7. Which of the following is incorrect?

A. k = 0b101
B. k= 0x4f5
C. k = 19023
D. k = 0o3964
Correct Answer: D
QUIZ- Test Your Skills

8. What is the output of the code:


print(bool('False'))

A. False
B. True
C. SyntaxError
D. 0

Correct Answer: B
QUIZ- Test Your Skills

9. Out of List and Tuple which is mutable ?

A. List
B. Tuple
C. Both
D. None

Correct Answer: A
QUIZ- Test Your Skills

10. Are string references mutable ?

A. Yes
B. No

Correct Answer: A
QUIZ- Test Your Skills

11. Are string objects mutable ?

A. Yes
B. No

Correct Answer: B
QUIZ- Test Your Skills

12. Is there a do – while loop in Python ?

A. Yes
B. No

Correct Answer:B
QUIZ- Test Your Skills

13. In Python which is the correct method to load a


module ?

A. include math
B. import math
C. #include<math.h>
D. using math

Correct Answer: B
QUIZ- Test Your Skills

14. What is the name of data type for character in


Python ?

A. chr
B. char
C. str
D. None Of The Above

Correct Answer: D
QUIZ- Test Your Skills

15. Let a = "12345" then which of the following is


correct ?

A. print(a[:]) => 1234


B. print(a[0:]) => 2345
C. print(a[:100]) => 12345
D. print(a[1:]) => 1

Correct Answer: C
Today’s Agenda

• Operators In Python
• Types Of Operators

• Arithmetic Operators

• Special points about + and *

• Difference between / and //


Operators

• Operators are special symbols in that carry out


different kinds of computation on values.

• For example : 2+3

• In the expression 2+3 , + is an operator which


performs addition of 2 and 3 , which are called
operands
Types Of Operators
In Python

• Python provides us 7 types of operators:

• Arithmetic Operators
• Relational or Comparison Operators
• Logical Operators
• Assignment Operator
• Bitwise Operators
• Identity Operators
• Membership Operators
Arithmetic Operators
In Python

• In Python , we have 7 arithmetic operators and they are as below:

+
(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 **

• The operator // in Python is called as floor division.

• Means it returns the integer part and not the


decimal part.

• For example: 5//2 will be 2 not 2.5


Two Special
Operators // and **

• But there are 3 very important points to understand


about this operator

• When used with positive numbers the result is only the


integer part of the actual answer i.e. , the decimal part is
truncated

• However if one of the operands is negative, the result is


floored.

• If both the operands are integers , result will also be integer


,otherwise result will be float
The Floor Division Operator

• Example: • Example:
a=10.0
a=10
b=4
b=4 print(a//b)
print(a//b)

• Output:
• Output: 2.0
2

If both the operands are integers , the result is also


an integer . But if any of the operands is float the result
is also float
The Floor Division Operator

• 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

• There is another very important point to remember


about the 3 operators / , // and %

• The point is that if the denominator in these


operators is 0 or 0.0 , then Python will throw the
exception called 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
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

• The power operator i.e. ** performs exponential


(power) calculation on operands.

• For example:
a=10
b=3
print(a**b)

• Output:
1000
Double Role Of The
Operator +

• The operator + as discussed earlier also ,has 2 roles in


Python

• When used with numbers , it performs addition and


when used with strings it performs concatenation

• 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 *

• The operator * also has 2 roles in Python

• When used with numbers , it performs


multiplication and when used with one operand
string and other operand int it performs
repetition

• 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

You might also like