back to school necklace

Python MCQ Class 12 Top 100 Questions for PDF Download 2021-22

Python MCQ Class 12 Top 100 for 11, 12 of Year 2021-22

1. Which of the following are invalid identifiers in Python?
a. Total-sum
b. Error
c. Error_count
d. None of these


2. A _____________ is a sequence of one or more characters used to provide a name for
a given program element.
a. Identifier
b. Variable
c. String
d. Character


3. Identify the invalid identifier below.
a. _2017discount
b. Profit
c. Total-discount
d. Totaldiscount


4. _____________ are not allowed as part of an identifier.
a. Spaces
b. Numbers
c. Underscore
d. All of these


5. Identifiers may contain letters and digits, but cannot begin with a _____________.
a. Character
b. Digit
c. Underscore
d. Special Symbols


6. Which is not a reserved keyword in Python?
a. insert
b. except
c. import
d. yield


PARTS OF PYTHON PROGRAMMING LANGUAGE

Parts of Python Programming Language 61

7. Identify the invalid keyword below.
a. and
b. as
c. while
d. until


8. _____________ is an identifier that has predefined meaning.
a. variable
b. identifier
c. keyword
d. None of these


9. Bitwise _____________ operator gives 1 if one of the bit is zero and the other is 1.
a. or
b. and
c. xor
d. not


10. Guess the output of the following code.
1 > 2 and 9 > 6
a. True
b. False
c. Machine Dependent
d. Error


11. How many operands are there in the following arithmetic expression?
6 * 35 + 8 − 25
a. 4
b. 3
c. 5
d. 8
12. How many binary operators are there in the following arithmetic expression?
− 6 + 10 / (23 + 56)
a. 2
b. 3
c. 4
d. 5


13. Which operator returns the remainder of the operands?
a. /
b. //
c. %
d. **

62 Introduction to Python Programming

14. A _____________ is a name that is associated with a value.
a. identifier
b. keyword
c. variable
d. None of these
15. Guess the output of the following expression.
float(22//3+3/3)
a. 8
b. 8.0
c. −8.3
d. 8.333


16. What value does the following expression evaluate to?
2 + 9 * ((3 * 12) – 8) / 10
a. 27
b. 27.2
c. 30.8
d. None of these


17. _____________ and _____________ are two ways to comment in Python.
a. Single and Multilevel comments
b. Single line and Double line comments
c. One and Many line comments
d. Single line and Multiline comments


18. Single-line comments start with the _____________ symbol.
a. *#
b. #
c. *
d. &
19. Multiline comments can be done by adding _____________ on each end of the
comment.
a. “‘”‘(triple quote)
b. # (Hash)
c. $ (dollar)
d. % (modulus)
20. Python programs get structured through _____________.
a. Alignment
b. Indentation
c. Justification
d. None

Parts of Python Programming Language 63

21. In Python, Indentation is a _____________ and not a matter of style.
a. Requirement
b. Refinement
c. Not required
d. Not Refined


22. Which of the following is correct about Python?
a. Python is a high-level, interpreted, interactive and object-oriented
language.
b. Python is designed to be highly readable.
c. It uses English keywords frequently and has fewer syntactical
constructions.
d. All of the above.


23. Which of the following function is used to read data from the keyboard?
a. function()
b. str()
c. input()
d. print()


24. The one’s complement of 60 is given by _____________.
a. −61
b. −60
c. −59
d. +59


25. The operators is and is not are _____________.
a. Identity Operators
b. Comparison Operators
c. Membership Operators
d. Unary Operators


26. In Python an identifier is _____________.
a. Machine Dependent
b. Keyword
c. Case Sensitive
d. Constant


27. Which of the following operator is truncation division operator?
a. /
b. %
c. |
d. //

64 Introduction to Python Programming

28. The expression that requires type conversion when evaluated is _____________.
a. 4.7 * 6.3
b. 1.7 % 2
c. 3.4 + 4.6
d. 7.9 * 6.3
29. The operator that has the highest precedence is _____________.
a. << and >>
b. **
c. +
d. %
30. The expression that results in an error is _____________.
a. int(‘10.8’)
b. float(10)
c. int(10)
d. float(10.8)
31. Which of the following expression is an example of type conversion?
a. 4.0 + float(3)
b. 5.3 + 6.3
c. 5.0 + 3
d. 3 + 7
32. What is the output when the following statement is executed?
>>>print(‘new’ ‘line’)
a. Error
b. Output equivalent to print ‘new\nline’
c. new line
d. newline
33. What is the output when the following statement is executed?
print(0xD + 0xE + 0xF)
a. Error
b. 0XD0XE0XF
c. 0X22
d. 42
34. What is the output of print (0.1 + 0.2 == 0.3)?
a. True
b. False
c. Error
d. Machine dependent

Parts of Python Programming Language 65

35. Which of the following is not a complex number?
a. l = 4 + 5j
b. l = complex(4,5)
c. l = 4 + 5i
d. l = 4 + 5j
36. Guess the output of the expression.
x = 15
y = 12
x & y
a. 1101
b. b1101
c. 0b1101
d. 12
37. Incorrect Indentation results in _____________.
a. IndentationError
b. NameError
c. TypeError
d. SyntaxError
38. The function that converts an integer to a string of one character whose ASCII
code is same as the integer is _____________.
a. chr(x)
b. ord(x)
c. eval(x)
d. input(x)

90 Introduction to Python Programming

Multiple Choice Questions
1. _________ control statement repeatedly executes a set of statements.
a. Iterative
b. Conditional
c. Multi-way
d. All of these
2. Deduce the output of the following code.
if False and False:
print(“And Operation”)
elif True or False:
print(“Or operation”)
else:
print(“Default case”)
a. And Operation
b. Or Operation
c. Default Case
d. B and C option
3. Predict the output of the following code.
i = 1
while True:
if i%2 == 0:
break
print(i)
i += 1
a. 1
b. 12
c. 123
d. None of these
4. Which keyword is used to take the control to the beginning of the loop?
a. exit
b. break
c. continue
d. None of these
5. The step argument in range() function _________.
a. indicates the beginning of the sequence
b. indicates the end of the sequence
c. indicates the difference between every two consecutive numbers in the
sequence
d. generates numbers up to a specified value

CONTROL FLOW STATEMENTS

Control Flow Statements 91

6. The symbol that is placed at the end of if condition is
a. ;
b. :
c. &
d. ~
7. What is the keyword that is used to come out of a loop only for that iteration?
a. break
b. return
c. continue
d. if
8. Judge the output of the following code snippet.
for i in range(10):
if i == 5:
break
else:
print(i)
a. 0 1 2 3 4
b. 0 1 2 3 4 5
c. 0 1 2 3
d. 1 2 3 4 5
9. Predict the output of the following code snippet.
while True:
print(True)
break
a. True
b. False
c. None
d. Syntax error
10. The output of the below expression is
>>>10 * (1/0).
a. OverflowError
b. ZeroDivisionError
c. NameError
d. TypeError
11. How many except statements can a try-except block have?
a. Zero
b. One
c. More than one
d. More than zero

92 Introduction to Python Programming

12. When will the else part of the try-except-else be executed?
a. Always
b. When an exception occurs
c. When no exception occurs
d. When an exception occurs in a try block
13. When is the finally block executed?
a. When an exception occurs
b. When there is no exception
c. Only if some condition that has been specified is satisfied
d. always
14. The keyword that is not used as an exception handling in Python?
a. try
b. except
c. accept
d. finally
15. An exception is
a. A object
b. A special function
c. A special module
d. A module
16. The set of statements that will be executed whether an exception is thrown or not?
a. except
b. else
c. finally
d. assert
17. Predict the output of the following code snippet.
while True
print(“Hello World”)
a. Syntax Error
b. Logical Error
c. Run-time error
d. None of these
18. Gauge the output of the following statement?
int(“65.43”)
a. Import error
b. Value error
c. Type error
d. Name error

Control Flow Statements 93

19. The error that is not a standard exception in Python.
a. Name Error
b. Assignment Error
c. IO Error
d. Value Error
20. The function that generates a sequence of numbers which can be iterated through
using for loop.
a. input()
b. range()
c. list()
d. raw_input()
21. What is the output of the following code snippet?
x = ‘abcd’
for i in x:
print(i)
a. abcd
b. 0 1 2 3
c. iiiii
d. Traceback
22. The function of while loop is
a. Repeat a chunk of code a given number of times.
b. Repeat a chunk of code until a condition is true.
c. Repeat a chunk of code until a condition is false.
d. Repeat a chunk of code indefinitely.

Functions 113

Multiple Choice Questions
1. A local variable in Python is a variable that is,
a. Defined inside every function
b. Local to the given program
c. Accessible from within the function
d. All of these
2. Which of the following statements are the advantages of using functions?
a. Reduce duplication of code
b. Clarity of code
c. Reuse of code
d. All of these

FUNCTIONS

114 Introduction to Python Programming

3. The keyword that is used to define the block of statements in function?
a. function
b. func
c. def
d. pi
4. The characteristics of docstrings are
a. suitable way of using documentation
b. Function should have a docstring
c. Can be accessed by __doc()__
d. All of these
5. The two types of functions used in Python are
a. Built-in and user-defined
b. Custom function and user function
c. User function and system call
d. System function
6. ______ refers to built-in mathematical function.
a. sqrt
b. rhombus
c. add
d. sub
7. The variable defined outside the function is referred as
a. static
b. global
c. automatic
d. register
8. Functions without a return statement do return a value and it is
a. int
b. null
c. None
d. error
9. The data type of the elements in sys.argv?
a. set
b. list
c. tuple
d. string
10. The length of sys.argv is?
a. Total number of arguments excluding the filename
b. Total number of arguments including the filename
c. Only filename
d. Total number of arguments including Python Command

Functions 115

11. The syntax of keyword arguments specified in the function header?
a. * followed by an identifier
b. _ followed by an identifier
c. ** followed by an identifier
d. _ _ followed by an identifier
12. The number of arguments that can be passed to a function is
a. 0
b. 1
c. 0 or more
d. 1 or more
13. The library that is used to create, manipulate, format and convert dates, times and
timestamps in Python is
a. Arrow
b. Pandas
c. Scipy
d. NumPy
14. The command line arguments is stored in
a. os.argv
b. sys.argv
c. argv
d. None
15. The command that is used to install a third-party module in Python is
a. pip
b. pipe
c. install_module
d. pypy
16. Judge the output of the following code.
import math
math.sqrt(36)
a. Error
b. −6
c. 6
d. 6.0
17. The function divmod(10,20) is evaluated as
a. (10%20,10//20)
b. (10//20,10%20)
c. (10//20,10*20)
d. (10/20,10%20)

116 Introduction to Python Programming

18. Predict the output of the following code?
def tweet():
print(“Python Programming!”)
tweet()
a. Python Programming!
b. Indentation Error
c. Syntax Error
d. Name Error
19. The output of the following code is
def displaymessage(message, times = 1):
print(message * times)
displaymessage(“Data”)
displaymessage(“Science”, 5)
a. Data Science Science Science Science Science
b. Data Science 5
c. DataDataDataDataDataScience
d. DataDataDataDataDataData
20. Guess the output of the following code
def quad(x):
return x * x * x * x
x = quad(3)
print(x)
a. 27
b. 9
c. 3
d. 81
21. The output of the following code is
def add(*args):
x = 0
for i in args:
x += i
return x
print(add(1, 2, 3))
print(add(1, 2, 3, 4, 5))
a. 16 15
b. 6 15
c. 1 2 3
d. 1 2 3 45

Functions 117

22. Gauge the output of the following code.
def foo():
return total + 1
total = 0
print(foo())
a. 1
b. 0
c. 11
d. 00
23. The default arguments specified in the function header is an
a. Identifier followed by an = and the default value
b. Identifier followed by the default value within back-ticks
c. Identifier followed by the default value within []
d. Identifier followed by an #.

Strings 143

Multiple Choice Questions
1. The arithmetic operator that cannot be used with strings is
a. +
b. *
c. −
d. All of these
2. Judge the output of the following code,
print(r”\nWelcome”)
a. New line and welcome
b. \nWelcome
c. The letter r and then welcome
d. Error

STRINGS

144 Introduction to Python Programming

3. What is the output of the following code snippet?
print(“Sunday”.find(“day”))
a. 6
b. 5
c. 3
d. 1
4. The output of the following code is,
print(“apple is a fruit”.split(“is”)
a. [‘is a fruit’]
b. [fruit]
c. [‘apple’, ‘a fruit’]
d. [‘apple’]
5. For the given string s = “nostradamus”, which of the following statement is used to
retrieve the character t?
a. s[3]
b. s.getitem(3)
c. s.__getitem__(3)
d. s.getItem(3)
6. The output of the following:
print(“\tapple”.lstrip())
a. \tapple
b. apple'”
c. apple
d. ‘”\tapple
7. Deduce the output of the following code:
print(‘hello’ ‘newline’)
a. Hello
b. hellonewline
c. Error
d. Newline
8. What is the output of the following code?
“tweet”[2:]
a. We
b. wee
c. eet
d. Twee

Strings 145

9. What is the output of the following code?
“apple is a fruit”[7:10]
a. Apple
b. s a
c. Fruit
d. None of the above
10. Identify the output of the following code:
print(“My name is %s” % (‘Charles Darwin’))
a. My name is Charles Darwin
b. Charles
c. %Charles
d. %
11. The prefix that is used to create a Unicode string is
a. u
b. h
c. o
d. c
12. The function that is used to find the length of the string is
a. len(string)
b. length(string)
c. len[string]
d. length[string]
13. What is the output of the following code?
string = “Lion is the king of jungle”
print(“%s” %string[4:7])
a. of
b. king
c. The
d. is
14. For the statement given below
example = “\t\ntweet\n”
The output for the expression example.strip() is
a. \t\ntweet\n
b. \t\ntweet
c. tweet\n
d. ‘tweet’

146 Introduction to Python Programming

15. Deduce the output of the following code:
print(‘Data Science’.istitle())
a. True
b. False
c. Error
d. None
16. Predict the output of the following code:
print(‘200.123’.isnumeric())
a. True
b. False
c. Error
d. None

170 Introduction to Python Programming

.

Multiple-Choice Questions
1. The statement that creates the list is
a. superstore = list()
b. superstore = []
c. superstore = list([1,2,3])
d. All of the above
2. Suppose continents = [1,2,3,4,5], what is the output of len(continents)?
a. 5
b. 4
c. None
d. error
3. What is the output of the following code snippet?
islands = [111,222,300,411,546]
max(islands)
a. 300
b. 222
c. 546
d. 111

LIST

Lists 171

4. Assume the list superstore is [1,2,3,4,5], which of the following is correct syntax for
slicing operation?
a. print(superstore[0:])
b. print(superstore[:2])
c. print(superstore[:-2])
d. All of these
5. If zoo = [“lion”, “tiger”], what will be zoo * 2?
a. [‘lion’]
b. [‘lion’, ‘lion’, ‘tiger’, ‘tiger’]
c. [‘lion’, ‘tiger’, ‘lion’, ‘tiger’]
d. [‘tiger’]
6. To add a new element to a list the statement used is?
a. zoo. add(5)
b. zoo.append(“snake”)
c. zoo.addLast(5)
d. zoo.addend(4)
7. To insert the string “snake” to the third position in zoo, which of the following
statement is used?
a. zoo.insert(3, “snake”)
b. zoo. insert(2, “snake”)
c. zoo.add(3, “snake”)
d. zoo.append(3, “snake”)
8. Consider laptops = [3, 4, 5, 20, 5, 25, 1, 3], what will be the output of laptops.reverse()?
a. [3, 4, 5, 20, 5, 25, 1, 3]
b. [1, 3, 3, 4, 5, 5, 20, 25]
c. [25, 20, 5, 5, 4, 3, 3, 1]
d. [3, 1, 25, 5, 20, 5, 4, 3]
9. Assume quantity = [3, 4, 5, 20, 5, 25, 1, 3], then what will be the items of quantity list
after quantity.pop(1)?
a. [3, 4, 5, 20, 5, 25, 1, 3]
b. [1, 3, 3, 4, 5, 5, 20, 25]
c. [3, 5, 20, 5, 25, 1, 3]
d. [1, 3, 4, 5, 20, 5, 25]
10. What is the output of the following code snippet?
letters = [‘a’, ‘b’, ‘c’, ‘d’, ‘e’]
letters[::-2]
a. [‘d’, ‘c’, ‘b’]
b. [‘a’, ‘c’, ‘e’]
c. [‘a’, ‘b’, ‘d’]
d. [‘e’, ‘c’, ‘a’]

172 Introduction to Python Programming

11. Suppose list_items is [3, 4, 5, 20, 5, 25, 1, 3], then what is the result of list_items.
remove(4)?
a. 3, 5, 29, 5
b. 3, 5, 20, 5, 25, 1, 3
c. 5, 20, 1, 3
d. 1, 3, 25
12. Find the output of the following code.
matrix= [[1,2,3],[4,5,6]]
v = matrix[0][0]
for row in range(0, len(matrix)):
for column in range(0, len(matrix[row])):
if v < matrix[row][column]:
v = matrix[row][column]
print(v)
a. 3
b. 5
c. 6
d. 33
13. Gauge the output of the following.
matrix = [[1, 2, 3, 4],
[4, 5, 6, 7],
[8, 9, 10, 11],
[12, 13, 14, 15]]
for i in range(0, 4):
print(matrix[i][1])
a. 1 2 3 4
b. 4 5 6 7
c. 1 3 8 12
d. 2 5 9 13
14. What will be the output of the following?
data = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
print(data[1][0][0])
a. 1
b. 2
c. 4
d. 5

Dictionaries 193

Multiple Choice Questions
1. Which of the following statements create a dictionary?
a. dic = {}
b. dic = {“charles”:40, “peterson”:45}
c. dic = {40: “charles”, 45: “peterson”}
d. All of the above

DICTIONARIES

194 Introduction to Python Programming

2. Read the code shown below carefully and pick out the keys.
dic = {“game”:40, “thrones”:45}
a. “game”, 40, 45, and “thrones”
b. “game” and “thrones”
c. 40 and 45
d. dic = (40: “game”, 45: “thrones”)
3. Gauge the output of the following code snippet.
fruit = {“apple”:”red”, “guava”:”green”}
“apple” in fruit
a. True
b. False
c. None
d. Error
4. Consider phone_book = {“Kalpana”:7766554433, “Steffi”:4499551100}. To delete the
key “Kalpana” the code used is
a. phone_book.delete(“Kalpana”:7766554433)
b. phone_book.delete(“Kalpana”)
c. del phone_book[“Kalpana”]
d. del phone_book(“Kalpana”:7766554433)
5. Assume d = {“Guido”:”Python”, “Dennis”:”C”}. To obtain the number of entries in
dictionary the statement used is
a. d.size()
b. len(d)
c. size(d)
d. d.len()
6. Consider stock_prices = {“IBM”:220, “FB”:800}. What happens when you try to
retrieve a value using the statement stock_prices[“IBM”]?
a. Since “IBM” is not a value in the set, Python raises a KeyError exception.
b. It executes fine and no exception is raised
c. Since “IBM” is not a key in the set, Python raises a KeyError exception.
d. Since “IBM” is not a key in the set, Python raises a syntax error.
7. Which of the following statement is false about the dictionary?
a. The values of a dictionary can be accessed using keys.
b. The keys of a dictionary can be accessed using values.
c. Dictionaries are not ordered.
d. Dictionaries are mutable.

Dictionaries 195

8. What is the output of the following code?
stuff = {“book”:”Java”, “price”:45}
stuff.get(“book”)
a. 45
b. True
c. Java
d. price
9. Predict the output of the following code.
fish = {“g”: “Goldfish”, “s”: “Shark”}
fish.pop(s)
print(fish)
a. {‘g’: ‘Goldfish’, ‘s’: ‘Shark’}
b. {‘s’: ‘Shark’}
c. {‘g’: ‘Goldfish’}
d. Error
10. The method that returns the value for the key present in the dictionary and
if the key is not present then it inserts the key with default value into the
dictionary.
a. update()
b. fromkeys()
c. setdefault()
d. get()
11. Guess the output of the following code.
grades = {90: “S”, 80: “A”}
del grades
a. Method del doesn’t exist for the dictionary.
b. del deletes the values in the dictionary.
c. del deletes the entire dictionary.
d. del deletes the keys in the dictionary.
12. Assume dic is a dictionary with some key:value pairs. What does dic.popitem()
do?
a. Removes an arbitrary key:value pair
b. Removes all the key:value pairs
c. Removes the key:value pair for the key given as an argument
d. Invalid method

196 Introduction to Python Programming

13. What will be the output of the following code snippet?
numbers = {}
letters = {}
comb = {}
numbers[1] = 56
numbers[3] = 7
letters[4] = “B”
comb[“Numbers”] = numbers
comb[“Letters”] = letters
print(comb)
a. Nested dictionary cannot occur
b. ‘Numbers’: {1: 56, 3: 7}
c. {‘Numbers’: {1: 56}, ‘Letters’: {4: ‘B’}}
d. {‘Numbers’: {1: 56, 3: 7}, ‘Letters’: {4: ‘B’}}
14. Gauge the output of the following code.
demo = {1: ‘A’, 2: ‘B’, 3: ‘C’}
del demo[1]
demo[1] = ‘D’
del demo[2]
print(len(demo))
a. 0
b. 2
c. Error
d. 1
15. Assuming b to be a dictionary, what does any(b) do?
a. Returns True if any key of the dictionary is True.
b. Returns False if dictionary is empty.
c. Returns True if all keys of the dictionary are True.
d. Method any() doesn’t exist for dictionary.
16. Infer the output of the following code.
count = {}
count[(1, 2, 4)] = 5
count[(4, 2, 1)] = 7
count[(1, 2)] = 6
count[(4, 2, 1)] = 2
tot = 0

Dictionaries 197

for i in count:
tot = tot + count[i]
print(len(count)+tot)
a. 25
b. 17
c. 16
d. Error
17. The ________ function returns Boolean True value if all the keys in the dictionary
are True else returns False.
a. all()
b. sorted()
c. len()
d. any()
18. Predict the output of the following code.
>>> dic = {}
>>> dic.fromkeys([1,2,3], “check”)
a. Syntax error
b. {1: ‘check’, 2: ‘check’, 3: ‘check’}
c. ‘check’
d. {1:None, 2:None, 3:None}

19. For dictionary d = { “plum “:0.66, “pears “:1.25,”oranges “:0.49}, which of the follow-
ing statement correctly updates the price of oranges to 0.52?

a. d[2] = 0.52
b. d[0.49] = 0.52
c. d[“oranges “] = 0.52
d. d[“plum “] = 0.52
20. The syntax that is used to modify or add a new key: value pair to a dictionary is:
a. dictionary_name[key] = value
b. dictionary_name[value] = key
c. dictionary_name(key) = value
d. dictionary_name{key} = value
21. Which of the following cannot be used as a key in Python dictionaries?
a. Strings
b. Lists
c. Tuples
d. Numerical values

198 Introduction to Python Programming

22. Guess the output of the following code.
week = {1:”sunday”, 2:”monday”, 3:”tuesday”}
for i,j in week.items():
print(i, j)
a. 1 sunday 2 monday 3 Tuesday
b. 1 2 3
c. sunday monday tuesday
d. 1:”sunday” 2:”monday” 3:”tuesday”
23. Predict the output of the following code.
a = {1: “A”, 2: “B”, 3: “C”}
b = {4: “D”, 5: “E”}
a.update(b)
print(a)
a. {1: ‘A’, 2: ‘B’, 3: ‘C’}
b. Error
c. {4: ‘D’, 5: ‘E’}
d. {1: ‘A’, 2: ‘B’, 3: ‘C’, 4: ‘D’, 5: ‘E’}

222 Introduction to Python Programming

Multiple Choice Questions
1. Which of the following is a mutable type?
a. Strings
b. Lists
c. Tuples
d. Frozenset

TUPLES AND SETS

Tuples and Sets 223

2. What will be the output of the following code?
t1 = (1, 2, 3, 4)
t1.append((5, 6, 7))
print(len(t1))
a. Error
b. 2
c. 1
d. 5
3. What is the correct syntax for creating a tuple?
a. [“a”,”b”,”c”]
b. (“a”,”b”,”c”)
c. {“a”,”b”,”c”}
d. {}
4. Assume air_force = (“f15”, “f22a”, “f35a”). Which of the following is incorrect?
a. print(air_force[2])
b. air_force[2] = 42
c. print(max(air_force))
d. print(len(air_force))
5. Gauge the output of the following code snippet.
bike = (‘d’,’u’,’c’,’a’,’t’,’i’)
bike [1:3]
a. (‘u’, ‘c’)
b. (‘u’, ‘c’, ‘c’)
c. (‘d’, ‘u’, ‘c’)
d. (‘a’, ‘t’, ‘i’)
6. What is the output of the following code?
colors = (“v”, “i”, “b”, “g”, “y”, “o”, “r”)
for i in range(0, len(colors),2):
print(colors[i])
a. (‘i’, ‘b’)
b. (‘v’, ‘i’, ‘b’)
c. [‘v’, ‘b’, ‘y’, ‘r’]
d. (‘i’, ‘g’, ‘o’)
7. What is the output of the following code snippet?
colors = (“v”, “i”, “b”, “g”, “y”, “o”, “r”)
2 * colors
a. [‘v’, ‘i’, ‘b’, ‘g’, ‘y’, ‘o’, ‘r’]
b. (‘v’, ‘i’, ‘b’, ‘g’, ‘y’, ‘o’, ‘r’)
c. (‘v’, ‘v’, ‘i’, ‘i’, ‘b’, ‘b’, ‘g’, ‘g’, ‘y’, ‘y’, ‘o’, ‘o’, ‘r’, ‘r’)
d. (‘v’, ‘i’, ‘b’, ‘g’, ‘y’, ‘o’, ‘r’, ‘v’, ‘i’, ‘b’, ‘g’, ‘y’, ‘o’, ‘r’)

224 Introduction to Python Programming

8. Predict the output of the following code.
os = (‘w’, ‘i’, ‘n’, ‘d’, ‘o’, ‘w’, ‘s’)
os1 = (‘w’, ‘i’, ‘n’, ‘d’, ‘w’, ‘s’, ‘o’)
os < os1
a. True
b. False
c. 1
d. 0
9. What is the data type of (3)?
a. Tuple
b. List
c. None
d. Integer
10. Assume tuple_1 = (7,8,9,10,11,12,13) then the output of tuple_1[1:-1] is.
a. Error
b. (8,9,10,11,12)
c. [8,9,10,11,12]
d. None
11. What might be the output of the following code:
A = (“hello”) * 3
print(A)
a. Operator Error
b. (‘hello’,’hello’,’hello’)
c. ‘hellohellohello’
d. None of these
12. What is the output of the following code:
number_1 = {1,2,3,4,5}
number_2 = {1,2,3}
number_1.difference(number_2)
a. {4, 5}
b. {1, 2, 3}
c. (4, 5)
d. [4, 5]
13. Judge the output of the following code:
tuples = (7,8,9)
sum(tuples, 2)
a. 26
b. 20
c. 12
d. 3

Tuples and Sets 225

14. tennis = (‘steffi’, ‘monica’, ‘serena’, ‘monica’, ‘navratilova’)
tennis.count(‘monica’)
a. 3
b. 0
c. 2
d. 1
15. A set is an _________ collection with no ______________ items.
a. unordered, duplicate
b. ordered, unique
c. unordered, unique
d. ordered, duplicate
16. Judge the output of the following:
sets_1 = set([‘a’,’b’,’b’,’c’,’c’,’c’,’d’])
len(sets_1)
a. 1
b. 4
c. 5
d. 7
17. What is the output of the code shown below?
s = {1,2,3}
s.update(4)
print(s)
a. {1,2,3,4}
b. {1,2}
c. {1,2,3}
d. Error
18. Tuple unpacking requires
a. an equal number of variables on the left side to the number of items in the
tuple.
b. greater number of variables on the left side to the number of items in the
tuple.
c. less number of variables on the left side to the number of items in the tuple.
d. Does not require any variables.
19. The statement that is used to create an empty set is
a. {}
b. set()
c. []
d. ()

226 Introduction to Python Programming

20. The ________ functions removes the first element of the set
a. remove()
b. delete()
c. pop()
d. truncate()
21. The method that returns a new set with items common to two sets is
a. isdisjoint()
b. intersection()
c. symmetric_difference()
d. union()
22. What is the output of the following code snippet?
s1 = {‘a’,’b’,’c’}
s2 = {‘d’}
print(s1.union(s2))
a. {‘c’, ‘d’, ‘b’, ‘a’}
b. {‘a’, ‘b’, ‘c’, ‘d’}
c. {‘b’, ‘c’, ‘d’, ‘a’}
d. {‘d’, ‘a’, ‘b’, ‘c’}
23. The function that makes a sequence by aggregating the elements from each of the
iterables is
a. remove()
b. update()
c. frozenset()
d. zip()
24. Predict the output of the following code:
even = {‘2’, ‘4’, ‘6’}
odd = {‘1’, ‘5’, ‘7 ‘}
even.isdisjoint(odd)
odd.isdisjoint(even)
a. True False
b. False True
c. True True
d. False False
25. Which of the following code snippet returns symmetric difference between two
sets
a. x ^ y
b. x & y
c. x | y
d. x – y

262 Introduction to Python Programming

Multiple Choice Questions
1. Consider a file named rome.txt, then the statement used to open a file for reading,
we use
a. infile = open(“c:\rome.txt”, “r”)
b. infile = open(“c:\\rome.txt”, “r”)
c. infile = open(file = “c:\rome.txt”, “r”)
d. infile = open(file = “c:\\rome.txt”, “r”)
2. Suppose there is a file named rome.txt, then the statement used to open a file for
writing, we use
a. outfile = open(“c:\rome.txt”, “w”)
b. outfile = open(“c:\\rome.txt”, “w”)
c. outfile = open(file = “c:\rome.txt”, “w”)
d. outfile = open(file = “c:\\rome.txt”, “w”)
3. Presume a file named rome.txt, then the statement used for appending data is
a. outfile = open(“c:\rome.txt”, “a”)
b. outfile = open(“c:\\rome.txt”, “rw”)
c. outfile = open(file = “c:\rome.txt”, “w”)
d. outfile = open(file = “c:\\rome.txt”, “w”)
4. Which of the following statements are true?
a. When you open a file for reading in ‘r’ mode, if the file does not exist, an error
occurs
b. When you open a file for writing in ‘w’ mode, if the file does not exist, a new
file is created
c. When you open a file for writing in ‘w’ mode, if the file exists, the existing file
is overwritten with the new file
d. All of the mentioned
5. The code snippet to read two characters from a file object infile is
a. infile.read(2)
b. infile.read()
c. infile.readline()
d. infile.readlines()
6. If you want to read the entire contents of the file using file object infile then
a. infile.read(2)
b. infile.read()
c. infile.readline()
d. infile.readlines()

FILE

Files 263

7. Predict the output of the following code:
for i in range(5):
with open(“data.txt”, “w”) as f:
if i > 0:
break
print(f.closed)
a. True
b. False
c. None
d. Error
8. The syntax to write to a CSV file is
a. CSV.DictWriter(filehandler)
b. CSV.reader(filehandler)
c. CSV.writer(filehandler)
d. CSV.write(filehandler)
9. Which of the following is not a valid mode to open a file
a. ab
b. r+
c. w+
d. rw
10. The readline() method returns
a. str
b. a list of lines
c. a list of single characters
d. a list of integers
11. Which of the following is not a valid attribute of the file object file_handler
a. file_handler.size
b. file_handler.name
c. file_handler.closed
d. file_handler.mode
12. Chose a keyword that is not an attribute of a file.
a. closed
b. softspace
c. rename
d. mode

264 Introduction to Python Programming

13. The functionality of tell() method in Python is
a. tells you the current position within the file
b. tells you the end position within the file
c. tells you the file is opened or not
d. None of the above
14. The syntax for renaming of a file is
a. rename(current_file_name, new_file_name)
b. rename(new_file_name, current_file_name,)
c. rename(()(current_file_name, new_file_name))
d. None of the above
15. To remove a file, the syntax used is,
a. remove(file_name)
b. (new_file_name, current_file_name,)
c. remove((), file_name))
d. None of the above
16. An absolute path name begins at the
a. leaf
b. stem
c. root
d. current directory
17. The functionality of seek() function is
a. sets the file’s current position at the offset
b. sets the file’s previous position at the offset
c. sets the file’s current position within the file
d. None of the above
18. What is unpickling?
a. It is used for object de- serialization
b. It is used for object serialization
c. It is used for synchronization
d. It is used for converting an object to its string representation
19. Which of the following are basic I/O connections in the file?
a. Standard Input
b. Standard Output
c. Standard errors
d. All of the above

Files 265

20. The mode that is used to refer to binary data is
a. r
b. w
c. +
d. b
21. File type is represented by its
a. file name
b. file extension
c. file identifier
d. file variable
22. The method that returns the time of last modification of the file is
a. getmtime()
b. gettime()
c. time()
d. localtime()
23. Pickling is used for?
a. object deserialization
b. object serialization
c. synchronization
d. converting string representation

 

Download from above given link.

4 thoughts on “Python MCQ Class 12 Top 100 Questions for PDF Download 2021-22”

Leave a Comment

Your email address will not be published. Required fields are marked *

Exit mobile version