☑ MCQ PRACTICE

Python Programming Unit 5

Practice objective questions for quick revision and examination preparation. Try answering each question before revealing the answer.

📚 Python Programming
📖 Unit 5
🎯 MCQs
Python Programming MCQs - Unit 5

Python Programming MCQs - Unit 5

1

Mandatory arguments required to connect any database from Python

A Username, Password, Hostname, Database Name, Port.
B Username, Password, Hostname
C Username, Password, Hostname, Database Name
D Username, Password
Correct Answer Username, Password, Hostname, Database Name
2

Which method of cursor class is used to insert or update multiple rows using a single query?

A cursor.executemany(query, rows)
B cursor.execute(query, rows)
C cursor.executmultiple(query, rows)
D cursor.executAll(query, rows)
Correct Answer cursor.executemany(query, rows)
3

Which method is used to Commit pending transaction to the database in Python?

A connection.commit()
B cursor.commit()
C connection.cursor.commit()
D commit()
Correct Answer connection.commit()
4

Which of the following code snippets creates and connects to a new MySQL Database?

A conn=MySQLdb.connect(host="localhost",user="root",pwd="root",databse="Sampledb")
B conn=MySQLdb.connect("localhost","root","root","Sampledb")
C conn=MYSQLDB.connect("localhost","root","root","Sampledb")
D conn=connect("localhost","root","root","Sampledb")
Correct Answer conn=MySQLdb.connect("localhost","root","root","Sampledb")
5

Which of the following is valid Cursor methods used to retrieve all rows as query results?

A cursor.execute ()
B cursor.fetchall()
C cursor.fecthone()
D cursor.run()
Correct Answer cursor.fetchall()
6

What is the type of the results variable in the following code snippet? cursor.execute("SELECT * FROM People") results = cursor.fetchall()

A tuple
B dictionary
C list
D set
Correct Answer list
7

In Object Relational Mapping (ORM) database table treated as ____________ ?

A Object
B Method
C Class
D Variable
Correct Answer Class
8

In Object Relational Mapping (ORM) data in table is mapped with ____________ ?

A Object
B Class
C Method
D Variable
Correct Answer Object
9

In Object Relational Mapping (ORM) ___________ function is used to create engine?

A createengine()
B engine()
C create_engine()
D create()
Correct Answer create_engine()
10

The Correct Syntax for create engine in SQLALchemy with MySQL _______________

A create_engine('mysql+mysqlconnector://root:root@localhost/Collegedb')
B create_engine('mysqlmysqlconnector://root:root@localhost/Collegedb')
C create_engine('mysql:mysqlconnector://:root@localhost/Collegedb')
D create_engine('mysql+mysqlconnector://:@localhost/Collegedb')
Correct Answer create_engine('mysql+mysqlconnector://root:root@localhost/Collegedb')
11

What is the use of session object in SQLALchemy?

A To Insert
B To Update
C To Delete
D All The Above
Correct Answer All The Above
12

Which method of session object is used to insert multiple rows at a time in SQLALchemy?

A add()
B update()
C add_all()
D All the above
Correct Answer add_all()
13

Which method of session object is used to select rows from database table in SQLALchemy?

A add()
B query()
C update()
D add_all()
Correct Answer query()
14

Which method of session object is used to select rows from database table with condition in SQLALchemy?

A execute()
B query()
C filter()
D add_all()
Correct Answer filter()
15

Which synchronization method is used to guard the resources with limited capacity, e.g. a database server?

A Condition
B Lock
C Event
D Semaphore
Correct Answer Semaphore
16

Which method of cursor class is used to fetch limited rows from the table?

A cursor.fetchsize(SIZE)
B cursor.fetchmany(SIZE)
C cursor.fetchonly(SIZE)
D cursor.fetchall(SIZE)
Correct Answer cursor.fetchmany(SIZE)
← Back to All MCQs