MCQ-Python revision Tour-qb-cpy
MCQ-Python revision Tour-qb-cpy
https://www.pathwalla.com/2020/10/python-revision-tour-multiple-choice.html
1. Which of the following is an invalid 6. What will be the value of the expression?
variable? 14 +13 % 15
(a) my_day_2 (a) 14
(b) 2nd_day (b) 27
(c)Day_two (c) 12
(d) _2 (d) 0
2. Which of the following is not a keyword? 7. Evaluate the expression given below if A
(a) eval = 16 and B = 15. A%B//A
(b) assert (a) 0.0
(c) nonlocal (b) 0
(d) pass (c) 1.0
(d) 1
3. Which of the following cannot be a
variable? 8. What is the value of x?
(a) __init__ x = int(13.25 4/2)
(b) in (a) 17
(c) it (b) 14
(d) on (c) 15
(d) 23
4. Which of these is not a core data type?
(a) Lists 9. The expression 8/4/2 will evaluate
(b) Dictionary equivalent to which of the following
(c) Tuples expressions:
(d) Class (a) 8/(4/2)
(b) (8/4)/2
5. How would you write xy in Python as an
expression? 10. Which among the following list of
(a) x^y operators has the highest precedence?
(b) x**y + , -, **, %, /, << , >>, |
(c) x^^y (a) <<, >>
(d) none of these (b) **
Page 1 of 18
S.Shunmuga Sundaram , M.E.,A.M.I.E., Telegram : https://t.me/cbsecomputerscience
(c) |
(d) % Select all of the function calls that result in
this output
11. Which of the following expressions (a)
results in an error? print('''Eina
(a) float('12') \nMina
(b) int('12') \nDika''')
(c) float('12.5') (b) print('''EinaMinaDika''')
(d) int('12.5') (c) print('Eina\nMina\nDika')
(d)
12. Which of the following statement prints print('Eina
the shown output below? Mina
hello\example\test.txt Dika')
(a) print("hello\example\test.txt")
(b) print("hello\\example\\test.txt") 16. Which of the following is valid
(c) print("hello\"example \"test.txt") arithmetic operator in Python:
(d) print("hello"\example"\test.txt") (a) //
(b) ?
13. Which value type does input() return? (c) <
(a) Boolean (d) and
(b) String
(c) Int 17. The numbered position of a letter in a
(d) Float string is called _____.
(a) position
14. Which two operators can be used on (b) integer position
numeric values in Python? (c) index
(a) @ (d) location
(b) %
(c) + 18. The operator _____ tells if an element is
(d) # present in a sequence or not.
(a) exists
15. Which of the following four code (b) in
fragments will yield following output? (c) into
Eina (d) inside
Mina
Dika 19. The keys of a dictionary must be of
Page 2 of 18
S.Shunmuga Sundaram , M.E.,A.M.I.E., Telegram : https://t.me/cbsecomputerscience
_____ types. (d) dictionary
(a) Integer
(b) mutable 24. What is the value of the following
(c) immutable expression?
(d) any of these 3 + 3.00, 3**3.0
(a) (6.0, 27.0)
20. Following set of commands is executed (b) (6.0, 9.00)
in shell, what will be the output? (c) (6, 27)
>>>str = "hello" (d) [6.0, 27.0]
>>>str[ : 2] (e) [6, 27]
>>>
(a) he 25. List AL is defined as follows:
(b) lo AL = [1, 2, 3, 4, 5]
(c) olleh Which of the following statements removes
(d) hello the middle element 3 from it so that the list
AL equal [1, 2, 4, 5]?
21. What data type is the object below? (a) del a[2]
L = [1, 23, 'hello', 1] (b) a[2 : 3] = []
(a) list (c) a[2:2] = []
(b) dictionary (d) a[2] = []
(c) array (e) a.remove(3)
(d) tuple
26. Which two lines of code are valid strings
22. What data type is the object below? in Python?
L = 1, 23, 'hello', 1 (a) This is a string
(a) list (b) 'This is a string'
(b) dictionary (c) (This is a string)
(c) array (d) "This is a string"
(d) tuple
27. You have the following code segment:
23. To store values in terms of key and String1 = "my"
value, what core data type does Python String2 = "work"
provide? print(String1 + string2)
(a) list What is the output of this code?
(b) tuple (a) my work
(c) class (b) work
Page 3 of 18
S.Shunmuga Sundaram , M.E.,A.M.I.E., Telegram : https://t.me/cbsecomputerscience
(c) mywork
(d) my 32. Which is the correct form of declaration
of dictionary?
28. You have the following code segment (a) Day = {1 : 'Monday', 2 : 'Tuesday', 3 :
String1 = "my" 'wednesday'}
String2 = "work" (b) Day = {1 ; 'Monday', 2 ; 'Tuesday', 3 ;
print(String1 + string2.upper()) 'wednesday'}
What is the output of this code? (c) Day = [1 : 'Monday', 2 : 'Tuesday', 3 :
(a) mywork 'wednesday']
(b) MY Work (d) Day = {1 'Monday', 2 'Tuesday',
(c) myWORK 3 'wednesday'}
(d) My Work
33. Identify the valid declaration of L:
29. Which line of code produces an error? L = [1, 23, 'hi', 6]
(a) "one" + 'two' (a) list
(b) 1+ 2 (b) dictionary
(c) "one"+ "2" (c) array
(d) '1' + 2 (d) tuple
30. What is the output of this code? 34. Which of the following is not considered
>>> int("3" + " 4") a valid identifier in Python?
(a) "7" (a) two2
(b) "34" (b) _main
(c) 34 (c) hello_rsp1
(d) 24 (d) 2 hundred
31. Which line of code will cause an error? 35. What will be the output of the following
1. num = [5, 4, 3, [2], 1] code-print("100+200")?
2. print(num [0]) (a) 300
3. print(num[3][0]) (b) 100200
4. print (num[5]) (c) 100+200
(a) Line 3 (d) 200
(b) Line 2
(c) Line 4 36. Which amongst the following is a
(d) Line 1 mutable data type in Python?
Page 4 of 18
S.Shunmuga Sundaram , M.E.,A.M.I.E., Telegram : https://t.me/cbsecomputerscience
(a) int (c) 11 15 15
(b) string (d) 16 11 15
(c) tuple
(d) list 41. The process of arranging the array
elements in a specified order is termed as:
37. pow() function belongs to which library? (a) Indexing
(a) math (b) Slicing
(b) string (c) Sorting
(c) random (d) Traversing
(d) maths
42. Which of the following Python functions
38. Which of the following statements is used to iterate over a sequence of
converts a tuple into a list? number by specifying a numeric end value
(a) len(string) within its parameters?
(b) list(string) (a) range()
(c) tup(list) (b) len()
(d) dict(string) (c) substring()
(d) random()
39. The statement: bval = str i > str2 shall
return..... As the output if two strings str1 43. What is the output of the following?
and str2 contains "Delhi" and "New Delhi". d = {0: 'a', 1: 'b', 2: 'c'}
(a) True for i in d:
(b) Delhi print(i)
(c) New Delhi (a)
(d) False 0
1
40. What will be the output generated by 2
the following snippet? (b)
a = [5, 10, 15, 20, 25] a
k=1 b
i = a[1] + 1 c
j = a[2] +1 (c)
m = a[k+1] 0
print (i, j, m) a
(a) 11 15 16 1
(b) 11 16 15 b
Page 5 of 18
S.Shunmuga Sundaram , M.E.,A.M.I.E., Telegram : https://t.me/cbsecomputerscience
2 47. What is the output of the following
c statement?
(d) print ("xyyzxyzxzxyy".count ('yy', 1))
2 (a) 2
a (b) 0
2 (c) 1
b (d) Error
2
c 48. Suppose list1 [0.5 * x for x in range(0,
4)], list1 is:
44. What is the output of the following? (a) [0, 1, 2, 3]
x = 123 (b) [0, 1, 2, 3, 4]
for i in x: (c) [0.0, 0.5, 1.0, 1.5]
print(i) (d) [0.0, 0.5, 1.0, 1.5, 20]
(a) 1 2 3
(b) 123 49. Which is the correct form of declaration
(c) error of dictionary?
(d) infinite loop (a)
Day={1:'monday',2:'tuesday',3:'wednesday'}
45. Which arithmetic operators cannot be (b)
used with strings? Day=(1;'monday',2;'tuesday',3;'wednesday')
(a) + (c)
(b) * Day=[1:'monday',2:'tuesday',3:'wednesday']
(c) - (d) Day={1 monday',2 tuesday',3
(d) all of the above wednesday']
46. What will be the output when the 50. Identify the valid declaration of L: L = [1,
following code is executed? 23, 'hi', 6]
>>> str1="helloworld" (a) list
>>> stri[:-1] (b) dictionary
(a) dlrowolleh (c) array
(b) hello (d) tuple
(c) world
(d) helloworld Answer =
1. b
Page 6 of 18
S.Shunmuga Sundaram , M.E.,A.M.I.E., Telegram : https://t.me/cbsecomputerscience
2. a 38. b
3. b 39. d
4. d 40. b
5. b 41. c
6. b 42. a
7. b 43. a
8. c 44. c
9. b 45. c
10. b 46. a
11. d 47. a
12. b 48. c
13. b 49. a
14. b, c 50. a
15. c
16. a
Revision Tour Python || Fill in the Blanks
17. c
|| Class 12
18. b
19. c
20. a 1. The smallest individual unit in a program
21. a is known as a _____.
22. d
23. d 2. A token is also called a _____.
24. a
25. a, b, e 3. A _____ is a word having special meaning
26. b, d and role as specified by programming
27. c language.
28. c
29. d 4. The data types whose values cannot be
30. c changed in place are called _____ types.
31. c
32. a 5. In a Python expression, when conversion
33. a of a value's data type is done automatically
34. d by the compiler without programmer's
35. b intervention, it is called _____.
36. d
37. a 6. The explicit conversion of an operand to
Page 7 of 18
S.Shunmuga Sundaram , M.E.,A.M.I.E., Telegram : https://t.me/cbsecomputerscience
a specific type is called _____. true copy of a list.
7. The _____ statement is an empty 18. The _____ function is used to remove
statement in Python. an item from a list/dictionary.
8. A _____ statement skips the rest of the 19. The _____ statement can remove an
loop and jumps over to the statement individual item or a slice from a list.
following the loop.
20. The _____ function removes all the
9. The _____ statement skips the rest of the elements of a list/dictionary.
loop statements and causes the next
iteration of the loop to take place. 21. Creating a tuple from a set of values is
called _____.
10. Python's _____ cannot be used as
variable name. 22. Creating individual values from a tuple's
elements is called _____.
11. Strings in Python store their individual
letters in Memory in _____ location. 23. The _____ method returns all the keys
in a dictionary.
12 Operator _____ when used with two
strings, gives a concatenated string. 24. The _____ function returns all values
from Key : value pair of a dictionary.
13. Operator _____ when used with a string
and an integer gives an error. 25. The _____ function returns all the Key :
value pairs as (key, value) sequences.
14. Part of a string containing some
contiguous characters from the string is 26. _____ is the Python operator
called _____ _____. responsible for declaring variables.
15. The _____ operator when used with a 27. The built-in function randrange()
list/string and an integer, replicates the belongs to _____ module.
list/string.
28. A _____ operator does not directly
16. _____ are not mutable while lists are. operate on data but produces a left-to-right
evaluation of expression.
17. Using _____ function, you can make a
Page 8 of 18
S.Shunmuga Sundaram , M.E.,A.M.I.E., Telegram : https://t.me/cbsecomputerscience
29. median() method belongs to _____ a specified list.
module in Python.
Page 9 of 18
S.Shunmuga Sundaram , M.E.,A.M.I.E., Telegram : https://t.me/cbsecomputerscience
32. module terminates all the nested loops in one go.
33. .py
11. Do both the following represent the
34. library
same list.
35. type, value, id ['a', b, c']
36. true, false ['c', 'a', 'b']
37. unique
38. Bubble sort 12. A list may contain any type of objects
39. relational except another list.
40. len()
13. There is no conceptual limit to the size
of a list.
Python Revision Tour || True or False ||
Class 12 14. All elements in a list must be of the
1. The expression int(x) implies that the same type.
variable x is converted to integer.
15. A given object may appear in a list more
2. The value of the expressions 4/ (3*(2 - 1)) than once.
and 4/3*(2- 1) is the same.
16. The keys of a dictionary must be of
3. The value of the expressions 4/ (3*(4 - 2) immutable types.
and 4/3*(4-2) is the same.
17. You can combine a numeric value and a
4. The expression 2**2**3 is evaluated as: string by using the + symbol.
(2**2) **3.
18. The clear( ) removes all the elements of
5. A string can be surrounded by three sets dictionary but does not delete the empty
of single quotation marks or by three sets of dictionary.
double quotation marks.
19. The max() and min() when used with
6. Variables can be assigned only once. tuples, can work if elements of the tuple are
all of the same type.
7. In Python, a variable is a placeholder for
data. 20. A list of characters is similar to a string
type.
8. In Python, only if statement has else
clause. 21. For any index n, s [: n] + s [n :] will give
you original string s.
9. Python loops can also have else clause.
22. A dictionary can contain keys of any
10. In a nested loop, a break statement valid Python types.
Page 10 of 18
S.Shunmuga Sundaram , M.E.,A.M.I.E., Telegram : https://t.me/cbsecomputerscience
23. The two statements x int(22.0/7) and x 36. Lists and strings in Python support two-
= int(22/7.0) yield the same results. way indexing.
24. The given statement: x + 1 = x is a valid 37. Tuples can be nested and can contain
statement. other compound objects like lists,
dictionaries and other tuples.
25. List slice is a list in itself.
Page 11 of 18
S.Shunmuga Sundaram , M.E.,A.M.I.E., Telegram : https://t.me/cbsecomputerscience
31. False Q. How many ways are there in Python to
32. False
represent an integer literal?
33. True
34. False
35. True
36. True Q. What are data types? What are Python's
37. True built-in core data types?
Q. What is the difference between Q. There are two types of else clauses in
interactive mode and script mode in Python. What are these two types of else
Python? clauses?
Q. How are keywords different from Q. What do you understand by the term
identifiers? Iteration?
Q. What are literals in Python? How many Q. What is a string slice? How is it useful?
types of literals are allowed in Python?
Page 12 of 18
S.Shunmuga Sundaram , M.E.,A.M.I.E., Telegram : https://t.me/cbsecomputerscience
checks whether it is a palindrome string or in Python?
not.
Q. What is a tuple?
Q. How are lists different from strings when
both are sequences?
Q. Differentiate between lists and tuples.
Page 13 of 18
S.Shunmuga Sundaram , M.E.,A.M.I.E., Telegram : https://t.me/cbsecomputerscience
in a string. second most repeated word in a given
string.
Page 14 of 18
S.Shunmuga Sundaram , M.E.,A.M.I.E., Telegram : https://t.me/cbsecomputerscience
DoubleTheNumber = Number * 2
Print (DoubleTheNumber)
Q. Write a program to sort a dictionary’s
keys using bubble sort and produce the
sorted keys as a list. Q. Why is following code giving errors?
name = "Path Walla"
print("Greetings !!!")
Q. Write a program to perform sorting on a print("Hello", name)
given list of strings, on the basis of just the print ("How do you do?")
first letter of the strings. Ignore all other
letters for sorting purposes. Choose sorting
algorithm of yourself. Q. Which data types of Python handle
Numbers?
Page 15 of 18
S.Shunmuga Sundaram , M.E.,A.M.I.E., Telegram : https://t.me/cbsecomputerscience
expresses it in terms of many minutes and
seconds it contains.
Page 16 of 18
S.Shunmuga Sundaram , M.E.,A.M.I.E., Telegram : https://t.me/cbsecomputerscience
Q 1 = write a program to print one of the
words negative ,zero or positive . according
to whether variable x is less than 0 , 0 or
greater than 0 respectively .
Page 17 of 18
S.Shunmuga Sundaram , M.E.,A.M.I.E., Telegram : https://t.me/cbsecomputerscience
Q7 = Write a program that reads an integer
N from the keyboards computes and
displays the sum of numbers from N to
(2*N) if N is nonnegative. If N is a negative
number , then it’s the sum of the numbers
from (2*N) to N . the starting and ending
points are included in the sum .
Page 18 of 18
S.Shunmuga Sundaram , M.E.,A.M.I.E., Telegram : https://t.me/cbsecomputerscience