Python MCQs
Python MCQs
Saved
What is the primary purpose of the sqlite3 module in Python?
Question 1 options:
Question 2 (1 point)
Saved
Which SQL command is used to create a table in SQLite?
Question 2 options:
INSERT INTO
UPDATE
CREATE TABLE
ALTER TABLE
Question 3 (1 point)
Saved
What is the default file extension for an SQLite database?
Question 3 options:
.db
.sql
.sqlite
.data
Question 4 (1 point)
Saved
Which function is used to execute SQL queries in the sqlite3 Python library?
Question 4 options:
execute_query()
cursor.execute()
run_query()
sql.execute()
Question 5 (1 point)
Saved
In the Inventory Management application, which column uniquely identifies each
item?
Question 5 options:
name
category
price
item_id
Question 6 (1 point)
Saved
What data type would be most suitable for storing price in SQLite?
Question 6 options:
INTEGER
TEXT
REAL
BOOLEAN
Question 7 (1 point)
Saved
Which SQL command would you use to remove an item from the inventory table?
Question 7 options:
DROP
DELETE
REMOVE
UPDATE
Question 8 (1 point)
Saved
In the Inventory Management application, which Python function is used to add a
new item to the inventory?
Question 8 options:
view_inventory()
update_item()
add_item()
search_item()
Question 9 (1 point)
Saved
Which SQLite data type is used to store string data like item names?
Question 9 options:
REAL
BLOB
TEXT
INTEGER
Question 10 (1 point)
Saved
What does the commit() function do in the sqlite3 module?
Question 10 options:
Saved
Which widget in Tkinter displays a list of text items?
Question 1 options:
Textbox
Listbox
Entry
Canvas
Question 2 (1 point)
Saved
Which command links a Scrollbar to a Listbox in Tkinter?
Question 2 options:
listbox.link()
scrollbar.set()
listbox.config(yscrollcommand=scrollbar.set)
scrollbar.config()
Question 3 (1 point)
Saved
In Tkinter, what does the selectmode option 'EXTENDED' enable?
Question 3 options:
Question 4 (1 point)
Saved
What orientation can a Scrollbar widget take?
Question 4 options:
LEFT or RIGHT
UP or DOWN
HORIZONTAL or VERTICAL
INLINE or BLOCK
Question 5 (1 point)
Saved
Which SQL command is used to add new rows of data in SQLite?
Question 5 options:
ADD
INSERT INTO
PUT
ADD TO
Question 6 (1 point)
Saved
What is the main feature of SQLite as a database?
Question 6 options:
Server-based
Multi-file storage
Question 7 (1 point)
Saved
Which of the following is not a key feature of SQLite?
Question 7 options:
Serverless Architecture
Transactional Support
Self-contained
Question 8 (1 point)
Saved
In Python's sqlite3 library, which function creates a connection to the database?
Question 8 options:
connect()
open()
setup()
access()
Question 9 (1 point)
Saved
Which method is used to execute SQL commands in sqlite3?
Question 9 options:
conn.execute()
cursor.execute()
db.run()
execute.command()
Question 10 (1 point)
Saved
What does conn.commit() do in an SQLite database?
Question 10 options:
Executes a command
Saves changes
Question 1 (1 point)
Saved
Which of the following is the base window in Tkinter?
Question 1 options:
Message
Entry
Root window
Frame
Question 2 (1 point)
Saved
Which method is used to create a Top-Level window in Tkinter?
Question 2 options:
TopLevel()
Toplevel()
CreateWindow()
NewWindow()
Question 3 (1 point)
Saved
Which function is used to display a message box in Tkinter?
Question 3 options:
showerror()
message()
showinfo()
alertbox()
Question 4 (1 point)
Saved
Which widget in Tkinter is used to take input from the user in a single line?
Question 4 options:
Label
Entry
Message
Textbox
Question 5 (1 point)
Saved
Which library is Tkinter a part of?
Question 5 options:
Standard Library
Tk GUI Toolkit
PyQt5
None of the above
Question 6 (1 point)
Saved
What method is used to run the Tkinter main loop?
Question 6 options:
run()
start()
mainloop()
launch()
Question 7 (1 point)
Saved
Which widget is used to display text in a read-only format in Tkinter?
Question 7 options:
Label
Text
Message
Button
Question 8 (1 point)
Saved
How can you set the title of a Tkinter window?
Question 8 options:
setTitle()
config()
title()
setWindow()
Question 9 (1 point)
Saved
What is the correct way to create an Entry widget?
Question 9 options:
Entry(window)
Entry(root)
Entry(master)
All of the above
Question 10 (1 point)
Saved
Which of the following imports the Tkinter library?
Question 10 options:
import tkinter as tk
import Tkinter
import tk_gui
import gui.tk
Saved
What does XML stand for?
Question 1 options:
Extra Markup Language
Extensible Markup Language
Executable Markup Language
Extended Markup Language
Question 2 (1 point)
Saved
Which API is best for handling very large XML files in Python?
Question 2 options:
DOM
SAX
ElementTree
xml.dom.minidom
Question 3 (1 point)
Saved
Which Python module is a lightweight implementation of the
Document Object Model (DOM)?
Question 3 options:
xml.etree.ElementTree
xml.sax
xml.dom.minidom
lxml
Question 4 (1 point)
Saved
In SAX parsing, which method is triggered when the parser
reaches the start of an element?
Question 4 options:
startElement()
start()
beginElement()
createElement()
Question 5 (1 point)
Saved
Which of the following is a tree-based XML parser in Python?
Question 5 options:
xml.sax
xml.etree.ElementTree
xml.dom.minidom
xmltodict
Question 6 (1 point)
Saved
In xml.etree.ElementTree, what does getroot() return?
Question 6 options:
The first element in the XML document
The root element of the XML tree
A list of child elements
The document type definition (DTD)
Question 7 (1 point)
Saved
Which method in SAX is used to handle character data
between XML tags?
Question 7 options:
handleCharacters()
textData()
characters()
content()
Question 8 (1 point)
Saved
Which Python XML parsing library supports advanced features
like XPath and XSLT?
Question 8 options:
xml.etree.ElementTree
xml.sax
lxml
xmltodict
Question 9 (1 point)
Saved
Which of the following is true about the xml.sax parser?
Question 9 options:
It loads the entire document into memory.
It processes XML documents sequentially.
It supports modifying XML documents.
It provides random access to XML elements.
Question 10 (1 point)
Saved
In xml.dom.minidom, how can you retrieve elements by their
tag name?
Question 10 options:
getElementById()
getByTagName()
getElementByTag()
getElementsByTagName()
Week 11 - MCQ's _ Python
Quiz
Question 1 (1 point)
Saved
Question 1 options:
200
404
500
403
Question 2 (1 point)
Saved
Question 2 options:
To handle cookies
To manage sessions
Question 3 (1 point)
Saved
Which directive is used to specify that a Python script should be executed as a CGI script?
Question 3 options:
#!/bin/sh
#!/usr/bin/env python3
#!/usr/bin/python/cgi
#!/usr/local/bin
Question 4 (1 point)
Saved
Question 4 options:
21
22
80
443
Question 5 (1 point)
Saved
Question 5 options:
getvalue()
getparam()
formread()
readform()
Question 6 (1 point)
Saved
What content type is used in CGI scripts to send plain HTML output?
Question 6 options:
application/json
text/html
text/plain
application/octet-stream
Question 7 (1 point)
Saved
Which Python standard library is commonly used alongside CGI scripts for simple HTTP server
creation?
Question 7 options:
http.server
socket
requests
os
Question 8 (1 point)
Saved
Which environment variable is used to determine the request method in a CGI script?
Question 8 options:
CONTENT_TYPE
REQUEST_METHOD
PATH_INFO
QUERY_STRING
Question 9 (1 point)
Saved
What is the primary disadvantage of using CGI for dynamic content generation?
Question 9 options:
Complexity
Lack of portability
Question 10 (1 point)
Saved
Question 10 options:
Django
Flask
FastAPI
Quiz
Question 1 (1 point)
Saved
Question 1 options:
`smtplib`
`poplib`
`imaplib`
`email`
Question 2 (1 point)
Saved
Question 2 options:
Question 3 (1 point)
Saved
Question 3 options:
`retrbinary()`
`storbinary()`
`login()`
`cwd()`
Question 4 (1 point)
Saved
Question 4 options:
21
80
110
25
Question 5 (1 point)
Saved
Question 5 options:
`starttls()`
`login()`
`sendmail()`
`quit()`
Question 6 (1 point)
Saved
Question 6 options:
`text/plain`
`multipart/mixed`
`application/json`
`audio/xyz`
Question 7 (1 point)
Saved
Question 7 options:
To read files
Question 8 (1 point)
Saved
Question 8 options:
`ftplib`
`poplib`
`imaplib`
`smtplib`
Question 9 (1 point)
Saved
Question 9 options:
To send emails
Question 10 (1 point)
Saved
Question 10 options:
SMTP
FTP
IMAP
HTTP
Saved
What happens to the child process when the parent process exits in a forked
environment?
Question 1 options:
Question 2 (1 point)
Saved
Question 2 options:
Python waits for all non-daemon threads to complete before exiting the main program.
Question 3 (1 point)
Saved
Question 3 options:
Question 4 (1 point)
Saved
Question 4 options:
Question 5 (1 point)
Saved
Which function is used to terminate a Python program from within the code?
Question 5 options:
terminate()
exit()
quit()
sys.exit()
Question 6 (1 point)
Saved
What is the default exit code when a Python program exits normally?
Question 6 options:
1
-1
None
Question 7 (1 point)
Saved
Which Python library provides a high-level interface for parallel execution of tasks?
Question 7 options:
multiprocessing
concurrent.futures
threading
asyncio
Question 8 (1 point)
Saved
In the multiprocessing library, what is the name of the method used to start a new
process?
Question 8 options:
begin()
run()
start()
execute()
Question 9 (1 point)
Saved
Which Python library is specifically designed for distributed computing and parallel
execution across multiple machines?
Question 9 options:
multiprocessing
dask
concurrent.futures
threading
Question 10 (1 point)
Saved
Which Python library can be used for distributed machine learning and data processing
on large clusters?
Question 10 options:
scikit-learn
TensorFlow
PySpark
NumPy
Question 1 (1 point)
Question 1 options:
Executing multiple threads in a single process.
Running multiple processes simultaneously on multiple CPUs.
Using a single thread to manage multiple processes.
Running multiple threads in a single CPU.
Question 2 (1 point)
Question 2 options:
It allows better management of I/O-bound tasks.
It can bypass the Global Interpreter Lock (GIL).
It uses less memory than threading.
It is easier to implement than threading.
Question 3 (1 point)
In Python, what is the main limitation of using threads for CPU-bound tasks?
Question 3 options:
Threads cannot run in parallel.
Threads consume too much memory.
The Global Interpreter Lock (GIL) restricts parallel execution.
Threads are slower than processes.
Question 4 (1 point)
Question 5 (1 point)
Question 5 options:
To create a new process.
To execute a new program within the same process.
To terminate the current process.
To create a new thread.
Question 6 (1 point)
Which of the following is used in Python to prevent race conditions when multiple
threads access shared resources?
Question 6 options:
Multiprocessing.
Forking.
Synchronization primitives like Locks.
Global Interpreter Lock (GIL).
Question 7 (1 point)
Question 7 options:
When two or more threads run in parallel.
When a thread terminates unexpectedly.
When two or more threads are blocked forever, waiting for each other.
When a thread holds multiple locks.
Question 8 (1 point)
Question 8 options:
TCP is connectionless and unreliable.
TCP is connection-oriented and provides reliable data transfer.
TCP is used for broadcasting data to multiple clients.
TCP cannot guarantee data integrity.
Question 9 (1 point)
Which of the following issues is most associated with global shared data in
multithreading?
Question 9 options:
Data redundancy.
Data synchronization and race conditions.
Increased performance.
Improved data security.
Question 10 (1 point)
Question 10 options:
Semaphore.
Event.
Lock.
Thread pool.
Quiz
Question 1 (1 point)
Which Python module is primarily used for interacting with the operating system,
such as file manipulation and process management?
Question 1 options:
sys
os
subprocess
shutil
Question 2 (1 point)
What Python module would you use to spawn a new process and connect to its
input/output/error pipes?
Question 2 options:
os
sys
subprocess
multiprocessing
Question 3 (1 point)
Which of the following methods is used to change the current working directory
in Python?
Question 3 options:
os.listdir()
os.getcwd()
os.chdir()
os.walk()
Question 4 (1 point)
Question 5 (1 point)
Question 6 (1 point)
Question 6 options:
Sets an environment variable.
Retrieves the value of an environment variable.
Deletes an environment variable.
Lists all environment variables.
Question 7 (1 point)
Question 8 (1 point)
Which of the following methods in the os module is used to execute a shell
command in Python?
Question 8 options:
os.exec()
os.spawn()
os.system()
os.call()
Question 9 (1 point)
Question 9 options:
Creates a new directory.
Joins one or more path components intelligently.
Lists the contents of a directory.
Splits a pathname into a pair, (head, tail).
Question 10 (1 point)
Which function in the os module can be used to retrieve the process ID of the
current process?
Question 10 options:
os.getuid()
os.getpid()
os.getgid()
os.getppid()
Python Week-6 MCQ
Question 1 (1 point)
Which of the following is used to match any single character except a newline in a regular
expression?
Options:
*
.
o
?
Question 2 (1 point)
Which of the following is used to match the end of a string in a regular expression?
Options:
^
$
\w
.
Question 3 (1 point)
4.0
8.0
16.0
2.0
Question 4 (1 point)
10
2
4
100
Question 5 (1 point)
Question 6 (1 point)
try block
except block
finally block
else block
Question 7 (1 point)
If you have nested try statements and an exception occurs in the inner try block, what will
happen?
Options:
The exception is always handled by the outer try block's except statement.
The program will stop executing immediately.
The exception is handled by the except block corresponding to the inner try
statement.
The exception is ignored, and the program continues to execute.
Question 8 (1 point)
In a program with nested try statements and custom exceptions, where should the custom
exception be caught?
Options:
Question 9 (1 point)
Question 10 (1 point)
a. 2
b. 5
c. 3
d. None
square = lambda x: x * x
a. Hello, Alice!
b. Hi, Alice!
c. Alice, Hello!
d. NameError
9. Which of the following is a correct way to use a lambda function with the
map() function?
a. map(lambda x, y: x + y, [1, 2, 3])
b. map(lambda x: x * 2, [1, 2, 3])
c. map(lambda x: x - 2, 2)
d. map(lambda x, y: x * y, [1, 2], [3, 4])
10. What will be the output of the following code?
add = lambda x, y:
x + y print(add(5, 10))
a. 15
b. 50
c. Error
d. None
Week 2 - MCQ's | Python
10. What is the output of the following code? x = Hello y = World print(x
+ + y)
a. HelloWorld
b. Hello World
c. Hello
d. World
Week 1 - MCQ's | Python
a. 7
b. 7.0
c. 5.2
d. 52