Which built-in function can be used to create a set in Python?
- create_set()
- make_set()
- new_set()
- set()
The built-in function set() is used to create a set in Python. You can use it by calling set(), and you can pass an iterable (like a list) as an argument to initialize the set with elements.
In a for loop, what does the range(3, 8, 2) function return?
- [2, 4, 6, 8]
- [3, 4, 5, 6, 7]
- [3, 5, 7]
- [3, 5]
range(3, 8, 2) generates values starting from 3 (inclusive) up to 8 (exclusive) with a step size of 2, resulting in [3, 5, 7].
What does the @property decorator do in a Python class?
- It defines a class method
- It defines a getter method
- It defines a setter method
- It defines a static method
The @property decorator defines a getter method for a class attribute, allowing you to access it as if it were an instance variable.
In OOP, what is the term for the class from which the derived class inherits?
- Base Class
- Parent Class
- Primary Class
- Superclass
The class from which a derived class inherits is known as the 'Base Class' or 'Parent Class.' In Python, it's also referred to as the superclass.
When you execute a Python script, what value does the name attribute hold by default for that script?
- "class"
- "init"
- "main"
- "module"
By default, when you execute a Python script, the 'name' attribute holds the value "main," indicating that the script is the main program.
What is the primary distinguishing feature of elements in a Python set?
- Indexed
- Sorted
- Unique
- Unordered
The primary distinguishing feature of elements in a Python set is that they are unique, meaning there are no duplicate elements in a set. Sets are also unordered, which means they don't have a specific order.
In Python, a dictionary can use immutable data types, like strings and tuples, as keys but not _______.
- Arrays
- Dictionaries
- Lists
- Sets
In Python, dictionaries can use immutable data types, such as strings and tuples, as keys because they are hashable and can be used to create unique hash values. However, lists are mutable, and their contents can change, so they cannot be used as dictionary keys.
Which of the following concepts allows a single interface to represent different methods in derived classes?
- Abstraction
- Encapsulation
- Inheritance
- Polymorphism
Polymorphism allows a single interface or method name to represent different implementations in derived classes. It enables flexibility and dynamic method dispatch in object-oriented programming.
The operator // performs _______ division.
- Division
- Float
- Integer
- Truncated
The operator '//' performs truncated division. It returns the integer part of the result of division, discarding the decimal part.
Which of the following is NOT a feature of Python?
- Dynamic Typing
- Easy-to-Read Syntax
- Interpreted Language
- Static Typing
Python is known for its dynamic typing, meaning you don't have to declare variable types. Static typing, on the other hand, requires explicit type declarations. Python's other features include easy-to-read syntax and being an interpreted language, making it different from statically typed languages.
For a property named value, the corresponding setter decorator would be _______.
- @property.setter
- @set.value
- @set.value.setter
- @value.setter
In Python, when defining a property named 'value,' the corresponding setter decorator should be '@value.setter.'
Which of the following lines will throw an indentation error in Python?
- if True:
- print("Hello, world!")
- print("Python is fun!")
- print("Python is easy!")
The correct option is 4. It lacks proper indentation, which is essential in Python to define code blocks. An indentation error would occur in this case.