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

Python 25 MCQs Final

The document contains a series of questions and answers related to Python programming concepts, including string manipulation, object-oriented programming, inheritance, and data types. Each question is followed by multiple-choice options, with the correct answer indicated. The content serves as a quiz or review material for individuals learning Python.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views6 pages

Python 25 MCQs Final

The document contains a series of questions and answers related to Python programming concepts, including string manipulation, object-oriented programming, inheritance, and data types. Each question is followed by multiple-choice options, with the correct answer indicated. The content serves as a quiz or review material for individuals learning Python.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

1.

Output of the code below:


text = 'Python'
print(text[0:4])

a) Pytho
b) Pyth
c) on
d) Py

Answer: b

2. Code that reverses a string s:

a) s[::-1]
b) s[::1]
c) s[-1:0]
d) reverse(s)

Answer: a

3. Result after running:


word = 'PYTHON'
print(word[2:])

a) PY
b) THON
c) YTH
d) HO

Answer: b

4. Correct slice for the first 3 characters of 'HelloWorld':

a) s[0:2]
b) s[:3]
c) s[3:]
d) s[1:4]

Answer: b

5. Result of print('Python'[::2]):
a) Pytho
b) Pto
c) Pyo
d) Pth

Answer: b

6. Keyword used to define a new class:

a) object
b) class
c) def
d) struct

Answer: b

7. First parameter of any instance method:

a) this
b) self
c) cls
d) obj

Answer: b

8. Correct way to create an object of class Student:

a) Student()
b) Student.create()
c) new Student()
d) class Student()

Answer: a

9. Special method used to initialize object properties:

a) __start__()
b) __init__()
c) __construct__()
d) __begin__()
Answer: b

10. What is an object in Python OOPs?

a) A copy of a class
b) An instance of a class
c) A global variable
d) A built-in function

Answer: b

11. Which keyword is used for inheritance in Python?

a) extends
b) inherits
c) class Child(Parent)
d) super

Answer: c

12. How do you call the parent class constructor inside a child class?

a) Parent.__init__(self)
b) super().__init__()
c) Both a and b
d) None

Answer: c

13. Which attribute shows the Method Resolution Order (MRO)?

a) __dict__
b) __mro__
c) __bases__
d) __class__

Answer: b

14. In multiple inheritance, Python resolves methods using:

a) Depth-first search
b) Breadth-first search
c) Method Resolution Order (MRO)
d) Random order

Answer: c

15. Which function checks if an object belongs to a class or subclass?

a) issubclass()
b) isinstance()
c) type()
d) id()

Answer: b

16. An example of method overriding:

a) Writing two methods in the same class with the same name
b) A child class redefining a method from its parent class
c) A method calling itself recursively
d) A method with variable-length arguments

Answer: b

17. Main benefit of polymorphism:

a) Increases execution time


b) Reduces memory usage
c) Improves flexibility and code reusability
d) Makes debugging harder

Answer: c

18. Polymorphism in Python is implemented through:

a) Method overloading and overriding


b) Multiple constructors only
c) Inheritance only
d) Encapsulation only

Answer: a
19. Output of the following code:
class A:
def show(self):
return 'Class A'

class B(A):
def show(self):
return 'Class B'

obj = B()
print(obj.show())

a) Class A
b) Class B
c) Error
d) None

Answer: b

20. Immutable type in Python among the following:

a) list
b) dict
c) tuple
d) set

Answer: c

21. Common feature between list and tuple in Python:

a) Ordered collection
b) Mutable collection
c) Unordered collection
d) Hashable collection

Answer: a

22. Type of keys allowed in Python dictionary:

a) Mutable only
b) Immutable only
c) Both mutable and immutable
d) None

Answer: b

23. Shared property between set and dictionary in Python:

a) Both allow duplicate elements


b) Both unordered in nature
c) Both preserve insertion order
d) Both use indexing

Answer: b

24. Data type resulting from division 5 / 2 in Python 3:

a) int
b) float
c) decimal
d) complex

Answer: b

25. Output of the code:

nums = [10, 20, 30, 40]


print(nums[-2] // 10)

a) 2
b) 3
c) 4
d) Error

Answer: b

You might also like