WorksheetsTIU Quiz-10
Total questions: 10
Worksheet time: 5mins
Which of the following is the correct way to connect to an SQLite3 database in Python?
db = sqlite3.connect('database_name')
db = sqlite3.connection('database_name')
db = sqlite3.Connection('database_name')
db = sqlite3.database('database_name')
What method is used to commit changes to the database in SQLite3?
How can you create a new table named students with columns id, name, and age?
cursor.execute("CREATE TABLE students (id INT, name TEXT, age INT)")
cursor.execute("NEW TABLE students (id INT, name TEXT, age INT)")
cursor.execute("CREATE students (id INT, name TEXT, age INT)")
cursor.execute("TABLE students (id INT, name TEXT, age INT)")
What is method overriding in OOP?
Defining a method with the same name but different parameters in the same class
Defining a method with the same name and parameters in a derived class
Using multiple methods with different names
Redefining a method with different parameters in the same class
Which statement about class and object is incorrect?
A class is a blueprint for objects.
An object is an instance of a class.
Classes can have attributes and methods.
Objects can inherit classes.
How do you create an instance of a class named Car?
Car = new Car()
my_car = Car()
my_car = Car.create()
Car my_car = Car()
What is the purpose of the init method in a Python class?
To initialize a class attribute
To initialize an instance of a class
To define a class method
To delete an instance of a class
What is the output of the following code: matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]; [row[0] for row in matrix]?
[1, 4, 7]
[1, 2, 3]
[1, 5, 9]
[3, 6, 9]
How do you ensure a SQLite3 connection is properly closed in Python?
db.close()
db.end()
db.terminate()
db.stop()
Which list comprehension correctly generates the Cartesian product of lists [1, 2] and [3, 4]?
[(x, y) for x in [1, 2] for y in [3, 4]]
[(x, y) for x in [1, 2], y in [3, 4]]
[(x, y) in ([1, 2], [3, 4])]
[(x, y) from [1, 2] to [3, 4]]
