OOP Python Seb
What is the correct way to declare an empty tuple
()
Which of the following can be used to unpack a tuple
*tuple
What is the output of 'my_dict = {'a': 1, 'b': 2}; print(my_dict['a'])'
1
What is the output of 'list1 = [1, 2, 3]; print(list1[-1])'
3
What is the output of 'my_tuple = (1, 2, 3); print(len(my_tuple))'
3
What is the output of 'len([1, 2, 3, 4])'
4
What is the concept of 'composition' in OOP
A class containing objects of other classes
What is multiple inheritance
A class inheriting from multiple parent classes
What is an interface in OOP
A class that defines methods without implementation
What is a mixin in Python
A class used to define methods that can be reused in other classes
What is a constructor in Python
A function that initializes objects
What does the 'keys()' method return for a dictionary
A list of keys
What is a property in Python
A method that can be accessed like an attribute
What is a static method in Python
A method that doesn't require an instance
What is an abstract method in Python
A method that must be overridden in a subclass
What does the 'append()' method do for a list
Adds a new item to the end
What is an abstract class
All of the above
What is an object in Python
An instance of a class
What is the difference between a class method and an instance method
Class methods do not require an instance of the class
What is the difference between a class and an object
Classes are blueprints, objects are instances
What is inheritance in OOP
Creating a new class from an existing class
What is polymorphism in OOP
Defining multiple methods with the same name
What is method overloading
Defining multiple methods with the same name but different arguments
Which of the following is a key difference between dictionaries and lists
Dictionaries are key-value pairs, lists are not
Which of the following is a feature of OOP
Encapsulation
What is the output of 'd = {1: 'a', 2: 'b'}; print(d[3])'
Error
What is the output of 'my_tuple = (1, 2); my_tuple[0] = 3'
Error
What is encapsulation in OOP
Hiding data implementation
What is abstraction in OOP
Hiding implementation details
What does the 'isinstance()' function check
If an object is an instance of a class
What is a tuple in Python
Immutable ordered collection
What does 'from math import sqrt' do in Python
Imports only the sqrt function
What is the purpose of the '__init__.py' file in a Python package
Indicate that the directory is a package
What is the main benefit of inheritance
It allows for code reuse
What does the 'pass' keyword do in a method
It does nothing
What happens if you try to change an item in a tuple
It will raise an error
What does the 'items()' method return for a dictionary
Key-value pairs as tuples
Which of the following is a mutable data type
List
Which of the following is a mutable object
List
What is the key difference between lists and tuples
Lists are mutable, tuples are immutable
What is the difference between a module and a package in Python
Modules are single files, packages are directories
What is the main concept of Object-Oriented Programming
Objects and classes
How do you define a class-level variable in Python
Outside any methods but inside the class
What is method overriding
Redefining a method in a subclass
What does the 'pop()' method do in a list
Removes the last item
What does the 'index()' method do for a list
Returns the index of a value
What does 'cls' refer to in a class method
The class itself
What does 'self' refer to in a method of a class
The current instance of the class
What does 'private' mean in OOP
The method can only be accessed by the class itself
What does 'len()' return when applied to a dictionary
The number of key-value pairs
What is the output of 'print(obj)' if the __str__ method is not defined
The object's memory address
What is method resolution order (MRO)
The order in which methods are inherited in a hierarchy
Which of the following is true about Python functions
They can have variable-length arguments
What is the concept of 'inheritance' in OOP used for
To allow one class to inherit methods and properties from another
What is the purpose of inheritance in OOP
To avoid redundant code
What is the purpose of 'super()' in Python
To call a parent class method
What is the purpose of the 'in' operator in Python
To check for inclusion in a collection
What does it mean to instantiate a class
To create an object from a class
What is the purpose of 'def' in Python
To define a function
What is the purpose of a destructor in OOP
To delete an object
What is the purpose of the '__str__' method in a class
To return a string representation of an object
What is the purpose of a class variable
To store data shared among all instances
What is the output of 'isinstance(obj, ClassName)' if obj is an instance of ClassName
True
Which of the following is immutable
Tuple
Which statement is correct about tuples
Tuples can contain duplicate elements
What is the output of 'print([1, 2] + [3, 4])'
[1, 2, 3, 4]
What will 'list1 = [1, 2]; list2 = list1; list2.append(3); print(list1)' output
[1, 2, 3]
What is the result of 'list1 = [1, 2]; list1.append([3, 4]); print(list1)'
[1, 2, [3, 4]]
What will 'my_list = [1, 2]; my_list.insert(1, 5); print(my_list)' output
[1, 5, 2]
What will 'list1 = [1, 2, 3]; list2 = list1; list2[0] = 10; print(list1)' output
[10, 2, 3]
How do you create an empty list in Python
[]
What is the default constructor in Python
__init__
Which of the following is used to create a package in Python
__init__.py
Which of the following defines a class in Python
class ClassName:
Which keyword is used to create a function
def
Which of the following is a private method in Python
def __method(self):
What is the correct way to create a function that takes a list as input
def func(list):
Which of the following defines a method in a class
def method_name(self):
What is the correct way to define a function in Python
def myFunc()
How can you remove a key-value pair from a dictionary
dict.pop(key)
Which method is used to remove a key-value pair from a dictionary
dict.pop(key)
How do you update a key-value pair in a dictionary
dict.update()
How can you access a specific value from a dictionary
dict[key]
How can you import a specific function from a module
from module import function
How do you check if a key exists in a dictionary
if key in dict
Which of the following is used to import a module
import module
What is the correct way to access a package after installation
import package
Which of the following methods is used to remove all elements from a list
list.clear()
How do you access the second element of a list in Python
list[1]
Which of the following is a correct way to create an instance of a class
obj = ClassName()
What is the correct way to install a package in Python
pip install package-name
How do you install a specific version of a package using pip
pip install package==version
How do you install a package using pip
pip install package_name
What is the difference between 'remove()' and 'pop()' in a list
remove() removes by value, pop() removes by index
What is the correct way to return a value from a function
return value
Which method adds an item to a dictionary
update()
Which method is used to combine two dictionaries
update()
What is the result of 'd = {'a': 1, 'b': 2}; d['c'] = 3; print(d)'
{'a': 1, 'b': 2, 'c': 3}
What is the output of 'd = {1: 'a', 2: 'b'}; d[1] = 'c'; print(d)'
{1: 'c', 2: 'b'}
How do you create an empty dictionary in Python
{}