0% found this document useful (0 votes)
11 views

Python MCQs

The document consists of multiple-choice questions (MCQs) covering various topics in Python, including SQLite, Tkinter, XML parsing, CGI, email handling, multiprocessing, and threading. Each question presents several options related to the respective topic, testing knowledge on Python libraries, commands, and concepts. The questions are designed for a quiz format, likely for educational purposes.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Python MCQs

The document consists of multiple-choice questions (MCQs) covering various topics in Python, including SQLite, Tkinter, XML parsing, CGI, email handling, multiprocessing, and threading. Each question presents several options related to the respective topic, testing knowledge on Python libraries, commands, and concepts. The questions are designed for a quiz format, likely for educational purposes.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 52

Question 1 (1 point)

Saved
What is the primary purpose of the sqlite3 module in Python?
Question 1 options:

To create HTML pages

To work with JSON files

To interact with SQLite databases

To perform network requests

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:

Closes the database connection

Rolls back the last transaction

Saves changes made in the current transaction

Fetches data from the database


Question 1 (1 point)

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:

Selecting a single item

Selecting multiple items one at a time


Selecting a range of items

Selecting non-continuous items

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

Serverless and single file

High configuration requirement

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

Concurrent Write Access

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:

Rolls back changes

Executes a command

Saves changes

Closes the connection


WEEK 13 PYTHON MCQS-9/10

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

Submit Quiz10 of 10 questions saved


Question 1 (1 point)

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

Which HTTP status code indicates a successful request?

Question 1 options:

200

404

500

403

Question 2 (1 point)

Saved

What is the purpose of the FieldStorage class in the cgi module?

Question 2 options:

To handle cookies

To process form data

To manage sessions

To read environment variables

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

What is the default port for an HTTP server in Python?

Question 4 options:

21

22

80

443

Question 5 (1 point)

Saved

Which method in cgi is used to retrieve form values in a CGI script?

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

High memory consumption

Slow performance due to process creation

Lack of portability

Question 10 (1 point)
Saved

Which server-side technology is an alternative to CGI for Python developers?

Question 10 options:

Django

Flask

FastAPI

All of the above

Submit Quiz10 of 10 questions saved


Python Week-10 MCQ

Quiz

Question 1 (1 point)

Saved

Which module in Python is used for fetching emails via POP3?

Question 1 options:

`smtplib`

`poplib`

`imaplib`

`email`

Question 2 (1 point)

Saved

What does FTP stand for?

Question 2 options:

File Transfer Program

File Transfer Protocol

File Transfer Process

File Transmission Protocol

Question 3 (1 point)

Saved

Which method in `ftplib` is used to upload a file to an FTP server?

Question 3 options:

`retrbinary()`

`storbinary()`

`login()`
`cwd()`

Question 4 (1 point)

Saved

What is the default port used by SMTP?

Question 4 options:

21

80

110

25

Question 5 (1 point)

Saved

Which method is used in `smtplib` to start a TLS session?

Question 5 options:

`starttls()`

`login()`

`sendmail()`

`quit()`

Question 6 (1 point)

Saved

Which of the following is NOT a MIME type?

Question 6 options:

`text/plain`

`multipart/mixed`

`application/json`

`audio/xyz`
Question 7 (1 point)

Saved

What is the role of `getpass` module in FTP scripting?

Question 7 options:

To read files

To handle login credentials securely

To execute FTP commands

To list files in a directory

Question 8 (1 point)

Saved

Which Python module would you use to send an email?

Question 8 options:

`ftplib`

`poplib`

`imaplib`

`smtplib`

Question 9 (1 point)

Saved

What is the purpose of the `MIMEText` class in Python's `email` package?

Question 9 options:

To create text-based emails

To parse email headers

To handle binary attachments

To send emails

Question 10 (1 point)
Saved

Which of the following protocols is primarily used for receiving emails?

Question 10 options:

SMTP

FTP

IMAP

HTTP

Submit Quiz10 of 10 questions saved


Question 1 (1 point)

Saved

What happens to the child process when the parent process exits in a forked
environment?

Question 1 options:

The child process continues to run independently.

The child process automatically exits.

The child process becomes a zombie process.

The child process takes over the parent's resources.

Question 2 (1 point)

Saved

How does Python handle thread exits?

Question 2 options:

Threads are forcibly killed when the main program exits.

Threads continue to run even after the main program exits.

Python waits for all non-daemon threads to complete before exiting the main program.

Python immediately terminates all threads when any thread exits.

Question 3 (1 point)

Saved

What is the purpose of the zope.interface module in Python?

Question 3 options:

To implement graphical user interfaces.

To define contracts or interfaces that classes must adhere to.


To provide tools for parallel processing.

To manage database connections in Python.

Question 4 (1 point)

Saved

In zope.interface, how do you declare that a class implements a specific interface?

Question 4 options:

By using the @implements decorator.

By inheriting from the Interface class.

By using the @implementer decorator.

By defining the interface as a subclass.

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)

Which of the following best describes the concept of multiprocessing in Python?

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)

What is the main advantage of using multiprocessing over threading in Python?

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)

What does the fork system call do in a Unix-like operating system?


Question 4 options:
Creates a new thread.
Replaces the current process with a new program.
Duplicates the current process.
Executes a program in the background.

Question 5 (1 point)

What is the primary purpose of the exec family of functions in Unix?

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)

What is a deadlock in the context of thread synchronization?

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)

Which of the following is true about TCP in socket programming?

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)

In Python, which synchronization primitive is often used to protect global shared


data from race conditions?

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)

What does the os.walk() function do?


Question 4 options:
Lists files in a directory.
Walks through all subdirectories and files in a directory tree.
Changes the current directory.
Deletes all files in a directory.

Question 5 (1 point)

Which function in the os module returns the current working directory?


Question 5 options:
os.chdir()
os.getcwd()
os.listdir()
os.path()

Question 6 (1 point)

What does os.getenv() do in Python?

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)

Which os module function can be used to rename a file?


Question 7 options:
os.rename()
os.remove()
os.replace()
os.unlink()

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)

What does the os.path.join() function do?

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)

What does the math.sqrt(16) function return?


Options:

 4.0
 8.0
 16.0
 2.0

Question 4 (1 point)

What does math.log(100, 10) return?


Options:

 10
 2
 4
 100

Question 5 (1 point)

What is the primary purpose of the try statement in Python?


Options:

 To create loops in Python code


 To execute a block of code without errors
 To test a block of code for errors and handle them if they occur
 To convert data types automatically

Question 6 (1 point)

Which block of code is executed regardless of whether an error occurs or not?


Options:

 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:

 It should only be caught in the outermost try block.


 It can be caught in any try block that handles that specific exception.
 Custom exceptions cannot be used with nested try statements.
 It must be caught in the innermost try block.

Question 9 (1 point)

What is the main purpose of creating user-defined exceptions in Python?


Options:

 To replace all built-in exceptions


 To create custom error types that better represent specific error conditions in your
program
 To handle only syntax errors
 To automatically fix errors in the code

Question 10 (1 point)

What happens if a user-defined exception is not handled in a try-except block?


Options:

 The program will automatically handle it


 The program will terminate and display an error message
 The exception will be ignored
 The program will enter an infinite loop
Week 5 - MCQ's | Python
1. What is the primary purpose of abstraction in object-oriented
programming?
a. To inherit properties from a parent class
b. To hide the implementation details and expose only essential
features
c. To override methods from a superclass
d. To create multiple instances of a class

2. Which module in Python provides the functionality to create


abstract classes?
a. Abc
b. Os
c. Sys
d. math

3. Which of the following is not a principle of object-oriented


programming?
a. Encapsulation
b. Abstraction
c. Compilation
d. Polymorphism

4. What is encapsulation in Python?


a. The process of inheriting properties from a parent class
b. The process of hiding the implementation details
c. The process of wrapping data and methods into a single unit
d. The process of creating multiple instances of a class
5. Which of the following statements about abstract methods is true?
a. Abstract methods must have an implementation in the
abstract class
b. Abstract methods can be called directly from the abstract
class
c. Abstract methods must be implemented by derived classes
d. Abstract methods cannot be overridden

6. In Python, how do you denote a private variable?


a. By prefixing the variable name with a single underscore (_)
b. By prefixing the variable name with double underscores (__)
c. By suffixing the variable name with a single underscore (_)
d. By suffixing the variable name with double underscores (__)

7. What is the role of the __init__ method in a Python class?


a. To delete an object
b. To initialize the instance variables
c. To call a superclass method
d. To define a class method

8. What will be the output of the following code?


a. Base class Method
b. Derived class Method
c. Error
d. None of the above

9. What is method overriding?


a. Defining a method in the superclass
b. Defining a method in the subclass with the same name and
parameters as in the superclass
c. Inheriting properties from a parent class
d. Hiding the implementation details
10.Which function is used to call a method from the superclass in a
subclass
a. super()
b. base()
c. parent()
d. ancestor()
Week 4 - MCQ's | Python

1. What keyword is used to define a class in Python?


a. def
b. class
c. object
d. method

2. What is an instance attribute?


a. A variable shared among all instances of a class
b. A function defined inside a class
c. A variable unique to each instance of a class
d. A class-level function

3. Which method is called when a new object is instantiated?


a. str
b. init
c. repr
d. call

4. What is the purpose of the @classmethod decorator?


a. To define a static method
b. To define a method that operates on an instance of the class
c. To define a method that operates on the class itself
d. To define a method that can only be called by external code

5. Which of the following is true about class attributes?


a. They are unique to each instance of the class
b. They can only be accessed within the class
c. They are shared among all instances of the class
d. They are defined in the __init__ method
6. Which of the following methods does not take self as the first
parameter?
a. Instance method
b. Static method
c. Class method
d. None of the above

7. What is encapsulation in Python?


a. The ability to inherit attributes and methods from another
class
b. Hiding the internal state of an object and allowing access only
through public methods
c. Defining multiple methods with the same name
d. None of the above

8. Which of the following concepts is achieved by method overriding?


a. Inheritance
b. Polymorphism
c. Encapsulation
d. Abstraction

9. In Python, which special method is used to add two objects of a


custom class?
a. add
b. sub
c. mul
d. div

10. Which keyword is used to define a base class in Python?


a. base
b. super
c. class
d. None of the above
Week 3 - MCQ's | Python

1. Which keyword is used to define a function in Python?


a. def
b. func
c. lambda
d. function

2. What will be the output of the following code?

def add(a, b):


return a + b
print(add(2, 3))

a. 2
b. 5
c. 3
d. None

3. What does the following lambda function do?

square = lambda x: x * x

a. Adds two numbers


b. Multiplies two numbers
c. Squares a number
d. Finds the square root of a number

4. Which of the following is true about lambda functions in Python?


a. They can have multiple expressions
b. They must have a return statement
c. They can have any number of arguments but only one expression
d. They cannot be used with higher-order functions
5. How do you define a function with default parameters in Python?
a. def func(a, b=10):
b. def func(a=10, b):
c. def func(a, b):
d. def func(a=10, b=20, c):

6. What will be the output of the following code?

def greet(name, greeting="Hello"):


return f"{greeting}, {name}!"
print(greet("Alice"))

a. Hello, Alice!
b. Hi, Alice!
c. Alice, Hello!
d. NameError

7. Which of the following is NOT a characteristic of lambda functions in


Python?
a. They are anonymous
b. They can have multiple expressions
c. They can be passed as arguments to other functions
d. They are defined using the lambda keyword

8. What is the purpose of the return statement in a function?


a. To stop the function execution and exit
b. To output a value from the function
c. To create a function
d. Both A and B

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

1. What does the `pass` statement do in Python?


a. Ends a loop
b. Skips the current iteration of a loop
c. Does nothing
d. Throws an error

2. What is the output of `print(hello.upper())`?


a. HELLO
b. Hello
c. Hello
d. ERROR

3. Which of the following is used to create a string in Python?


a. Hello
b. 'Hello'
c. "Hello"
d. All of the above

4. What is the correct syntax to define a function in Python?


a. `function myFunc()`
b. `def myFunc():`
c. `define myFunc():`
d. `func myFunc():`

5. How do you add a comment in Python


a. // This is a comment
b. <!-- This is a comment →
c. # This is a comment
d. /* This is a comment */
6. What is the output of the following code? x = Python print(x[1:4])
a. Pyt
b. ytho
c. yth
d. ython

7. Which keyword is used to create a function in Python?


a. function
b. func
c. def
d. define

8. How do you insert comments in Python code?


a. //
b. #
c. <!-- →>
d. **

9. What is the correct file extension for Python files?


a. .pyth
b. .py
c. .pt
d. .pyt

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

1. What is the primary purpose of indentation in Python?


a. To improve performance
b. To define code blocks
c. To make the code look neat
d. To comment the code

2. Which of the following is a mutable collection type in Python?


a. List
b. Tuple
c. Set
d. Dictionary

3. What keyword is used to define a function in Python?


a. func
b. def
c. define
d. function

4. How do you start a comment in Python?


a. //
b. *
c. #
d. \

5. Which of the following is not a standard Python data type?


a. List
b. Set
c. Array
d. Tuple
6. What does the open() function in Python do?
a. Open a file
b. Create a directory
c. Start a program
d. Open a socket

7. What is the output of the following code?


x = 5
y = 2.0
z = x + y
print(z)

a. 7
b. 7.0
c. 5.2
d. 52

8. Which of the following statements creates a tuple?


a. tuple = [1, 2, 3]
b. tuple = (1, 2, 3)
c. tuple = {1, 2, 3}
d. tuple = <1, 2, 3>

9. How can you create a dictionary in Python?


a. dict = {1, 2, 3}
b. dict = [1: 'a', 2: 'b']
c. dict = {1: 'a', 2: 'b'}
d. dict = (1, 'a', 2, 'b')

10.What will be the output of the following code?


a. [1, 2, 3]
b. [1, 2, 3, 4]
c. [4]
d. Error

You might also like