CHAPTER – 3 : BRIEF OVERVIEW OF PYTHON
MULTIPLE CHOICE QUESTIONS
1. Which of the following provides special meaning to Python
A) Identifiers B) Functions
C) Keywords D) Literals
Answer : A
2. Data items that will never change and have fixed values are known as ________________
A) Identifiers B) Functions
C) Keywords D) Literals
Answer : D
3. Which of the following is default separator character for print( )
A) tab B) space
C) newline D) dot
Answer : B
4. Which of the following can be used to create comments
A) // B) '''
C) # D) ''' .... '''
Answer : C
5. Escape sequences are treated as ________?
A) Strings B) Characters
C) Integers D) None of these
Answer : A
6. To give a different separator for print( ) which of the following is used?
A) separator B) end
C) sep D) space
Answer : A
7. Which of the following function is used to convert the read value through input( ) into an integer?
A) floating( ) B) float( )
C) int( ) D) integer( )
Answer : C
8. Which of the following cannot be a variable?
A) __init__ B) in
C) it D) on
Answer: B (Explanation: in is a keyword)
-2-
9. The operator used to check if both the operands reference the same object memory, is the ________
operator
A) in B) as
C) id D) = =
Answer : C
10. A variable may be assigned a value of one type, and then later can be assigned with another type value.
This is referred as _____________?
A) Immutability B) Dynamic Typing
C) Type Conversion D) Mutability
Answer : B
11. An empty / null statement in Python is P________?
A) go B) pass
C) over D) ;
Answer : B
12. Which of the following statements will make a statement to execute repeatedly?
A) if B) if – else
C) for D) while
Answer : C, D
13. Which of the following loop(s) does not valid in Python?
A) while B) for
C) do–while D) Repeat
Answer : D
14. Which of the following will create a block in compound statement?
A) colon B) statements indented at a lower, same level
C) { } D) indentation in any form
Answer : A
15. Function range(3) is equivalent to which of the following?
A) range(1, 3) B) range(0, 3)
C) range(0, 3, 1) D) range(1, 3, 0)
Answer : B
16. Is Python case sensitive when dealing with identifiers?
A) Yes B) No
C) machine dependent D) None of the mentioned
Answer: A
17. What is the maximum possible length of an identifier?
A) 31 characters B) 63 characters
C) 79 characters D) None of the mentioned
Answer: D (Explanation: Identifiers can be of any length)
-3-
18. Which of the following is invalid?
A) _a = 1 B) __a = 1
C) __str__ = 1 D) None of the mentioned
Answer: D (Explanation: All the statements will execute successfully but at the cost of reduced readability)
19. Which of the following is an invalid variable?
A) my_string_1 B) 1st_string
C) foo D) _
Answer: B (Explanation: Variable names should not start with a number)
20. Which of the following is not a keyword?
A) eval B) assert
C) nonlocal D) pass
Answer: A (Explanation: eval can be used as a variable)
21. All keywords in Python are in _________
A) lower case B) UPPER CASE
C) Capitalized D) None of the mentioned
Answer: D (Explanation: True, False and None are capitalized while the others are in lower case)
22. Which of the following is true for variable names in Python?
A) unlimited length
B) all private members must have leading and trailing underscores
C) underscore and ampersand are the only two special characters allowed
D) none of the mentioned
Answer: A (Explanation: Variable names can be of any length)
23. Which of the following is an invalid statement?
A) abc = 1,000,000 B) a b c = 1000 2000 3000
C) a,b,c = 1000, 2000, 3000 D) a_b_c = 1,000,000
Answer: B (Explanation: Spaces are not allowed in variable names)
24. What will be the output of the following Python code?
i=1
while True:
if i%3 == 0:
break
print(i)
i+=1
A) 1 2 B) 1 2 3
C) error D) none of the mentioned
Answer: C (Explanation: SyntaxError, there shouldn’t be a space between + and = in +=)
-4-
25. What will be the output of the following Python code?
i=1
while True:
if i%2 == 0:
break
print(i)
i += 2
A) 1 B) 1 2
C) 1 2 3 4 5 6 … D) 1 3 5 7 9 11 …
Answer: D (Explanation: The loop does not terminate since i is never an even number)
26. What will be the output of the following Python code?
for i in range(2.0):
print(i)
A) 0.0 1.0 B) 0 1
C) error D) none of the mentioned
Answer: C (Explanation: Object of type float cannot be interpreted as an integer)
27. What will be the output of the following Python code snippet?
x=2
for i in range(x):
x += 1
print (x)
A) 0 1 2 3 4 … B) 0 1
C) 3 4 D) 0 1 2 3
Answer: C (Explanation: Variable x is incremented and printed twice)
28. What will be the output of the following Python code snippet?
x=2
for i in range(x):
x -= 2
print (x)
A) 0 1 2 3 4 … B1) 0 -2
C) 0 D) error
Answer: B (Explanation: The loop is entered twice)
29. What will be the output of the following Python code?
for i in range(10):
if i == 5:
break
else:
print(i)
else:
print("Here")
-5-
A) 0 1 2 3 4 Here B) 0 1 2 3 4 5 Here
C) 0 1 2 3 4 D) 1 2 3 4 5
Answer: C (Explanation: The else part is executed if control doesn’t break out of the loop)
30. What will be the output of the following Python code?
for i in range(5):
if i == 5:
break
else:
print(i)
else:
print("Here")
A) 0 1 2 3 4 Here B) 0 1 2 3 4 5 Here
C) 0 1 2 3 4 D) 1 2 3 4 5
Answer: A (Explanation: The else part is executed if control doesn’t break out of the loop)
31. What will be the output of the following Python code?
x = (i for i in range(3))
for i in x:
print(i)
A) 0 1 2 B) error
C) 0 1 2 0 1 2 D) none of the mentioned
Answer: A (Explanation: The first statement creates a generator object)
32. What will be the output of the following Python code?
x = (i for i in range(3))
for i in x:
print(i)
for i in x:
print(i)
A) 0 1 2 B) error
C) 0 1 2 0 1 2 D) none of the mentioned
Answer: A (Explanation: We can loop over a generator object only once)
33. What will be the output of the following Python code?
string = "my name is x"
for i in string:
print (i, end=", ")
A) m, y, , n, a, m, e, , i, s, , x, B) m, y, , n, a, m, e, , i, s, , x
C) my, name, is, x, C) error
Answer: A (Explanation: Variable i takes the value of one character at a time)