What does the following code snippet print?
def outer_func(x): def inner_func(y): return x + y return inner_func my_func = outer_func(5) print(my_func(3))
5
15
8
Error
Which data structure would be most appropriate for representing a graph in Python?
A dictionary where keys are nodes, and values are lists of their neighbors.
A set of tuples, where each tuple represents an edge between two nodes.
All of the above options can be used to represent a graph.
A list of lists, where each inner list represents a node and its connections.
How can you get the current date and time using the 'datetime' module?
datetime.datetime.now()
datetime.now
datetime.currentTime()
datetime.today()
Which collection module class is most suitable for implementing a queue data structure in Python?
deque
OrderedDict
defaultdict
Counter
In Python, what is the difference between a class variable and an instance variable?
Class variables can only store integers, while instance variables can store any data type.
Class variables are declared inside a method, while instance variables are declared outside methods.
Class variables are shared by all instances of a class, while instance variables are unique to each instance.
There is no difference; they are interchangeable terms.
Which regular expression will match any string that starts with 'a' and ends with 'z'?
'a.+z'
'^a.+z$'
'^a.*z$'
'a.*z'
Which keyword is used to explicitly raise an exception in Python?
throw
raise
catch
try
What is the primary advantage of using the with statement for file operations in Python?
with
It provides better performance for large files.
All of the above.
It improves code readability.
It automatically closes the file, even if exceptions occur.
Which method is used to write a single line of text to a file in Python?
write()
put()
writeln()
writeline()
Which module would you use to interact with the operating system, like creating directories?
sys
datetime
os
math