[go: up one dir, main page]

0% found this document useful (0 votes)
2 views6 pages

MCQ Type

The document contains a series of multiple-choice questions focused on advanced Python programming concepts. Topics include variable assignment, function behavior, error handling, data structures, and class methods. Each question presents four answer options, testing the reader's understanding of Python's functionality and syntax.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views6 pages

MCQ Type

The document contains a series of multiple-choice questions focused on advanced Python programming concepts. Topics include variable assignment, function behavior, error handling, data structures, and class methods. Each question presents four answer options, testing the reader's understanding of Python's functionality and syntax.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Type I – Multiple Choice Questions (Difficult Level)

1. What will be the output of the following code?

x = [1, 2, 3]

y=x

x = x + [4, 5]

print(y)

a. [1, 2, 3, 4, 5]
b. [1, 2, 3]
c. Error
d. None

2. Consider the following function:

def foo(a, b=[]):

b.append(a)

return b

What is the result of calling foo(1) followed by foo(2)?

a. [1], [2]
b. [1], [1, 2]
c. [2], [1, 2]
d. [1, 2], [1, 2]

3. Which of the following will raise a TypeError?


a. "abc" + str(123)
b. len([1, 2, 3])
c. "1" - "2"
d. int("123")

4. What will be the output of:

a = [1, 2, 3]
b = a[:]

a[0] = 100

print(b[0])

a. 100
b. 1
c. Error
d. None

5. Which of the following operations is invalid on sets?


a. set1.union(set2)
b. set1.intersection(set2)
c. set1[0]
d. len(set1)

6. Which of the following is a valid way to define a class constructor in Python?


a. def __constructor__(self):
b. def constructor(self):
c. def __init__(self):
d. init(self):

7. What will this code output?

print([i for i in range(3)] is [0, 1, 2])

a. True
b. False
c. [0, 1, 2]
d. Error

8. Which function will correctly check if an object x is an instance of a class MyClass?


a. type(x) == MyClass
b. x.__class__ == MyClass
c. isinstance(x, MyClass)
d. All of the above
9. What is the output of the following?

x = "hello"

y=x

x = "world"

print(y)

a. hello
b. world
c. None
d. Error

10. In file handling, what happens if we open a file with mode 'w'?
a. Reads the file
b. Appends to file
c. Overwrites file if exists
d. Raises error if file exists

11. Which of the following statements about Python lists is false?


a. Lists are mutable
b. Lists can contain mixed data types
c. Lists are implemented as linked lists
d. Lists support slicing

12. What does the following code print?

def f(a, b):

a += b

return a

print(f([1, 2], [3, 4]))


a. [1, 2, 3, 4]
b. [1, 2]
c. [3, 4]
d. Error

13. Which statement about try-except blocks is true?


a. A try block must always be followed by an else block
b. Only one except block is allowed
c. Finally block is mandatory
d. Except block can catch multiple exceptions

14. Consider the following code:

s = {1, 2, 3}

s.add([4, 5])

What happens?

a. Adds list to set


b. Adds each item of list to set
c. TypeError is raised
d. List gets converted to tuple

15. What will be the output?

def g(x, y=[]):

y.append(x)

return y

print(g(1))

print(g(2))

a. [1] [2]
b. [1] [1, 2]
c. [1, 2] [1, 2]
d. Error

16. Which of the following would create an infinite recursion?


a. Function calling itself with reduced input
b. Function calling itself with same input
c. Base case missing in recursion
d. Both b and c

17. What is the output?

print(type((1)))

print(type((1,)))

a. int, int
b. tuple, int
c. int, tuple
d. tuple, tuple

18. Which of the following modules is NOT part of Python standard library?
a. math
b. os
c. random
d. numpy

19. What happens if you try to modify a key in a dictionary?


a. Key gets updated
b. Error
c. Key gets deleted
d. New key is added

20. What does the __str__() method do in a class?


a. Converts object to list
b. Defines object print representation
c. Deletes the object
d. Handles constructor logic

You might also like