How can you write a multiline string in Python?
Using backslash ()
Using triple single quotes (''') or triple double quotes (""")
Using single quotes (')
Using double quotes (")
What is the primary purpose of decorators in Python?
To improve the performance of a function.
To define a function within another function.
To create recursive functions.
To change the behavior of a function without modifying its source code.
Which method is used to write a single line of text to a file in Python?
writeln()
write()
writeline()
put()
Which data structure from the collections module is best suited for efficiently keeping track of element frequencies?
collections
defaultdict
OrderedDict
Counter
deque
What is the purpose of the 'r' prefix in a regular expression pattern?
It treats the pattern as a raw string, ignoring escape sequences.
It makes the pattern case-insensitive.
It enables multiline matching.
It performs a greedy match.
What will the following code snippet print?
def my_decorator(func): def wrapper(): print("Before function call") func() print("After function call") return wrapper @my_decorator def say_hello(): print("Hello!") say_hello()
Hello!
Before function call Hello! After function call
Before function call After function call
Error
Which module would you use to interact with the operating system, like creating directories?
datetime
math
os
sys
Which principle of OOP allows objects of different classes to be treated as objects of a common type?
Polymorphism
Inheritance
Abstraction
Encapsulation
Which collection module class is most suitable for implementing a queue data structure in Python?
Which keyword is used to explicitly raise an exception in Python?
catch
raise
throw
try