an HCL GUVI product

python banner

Python Multiple Choice Questions (MCQs) and Answers

Master Python Programming with Practice MCQs. Explore our curated collection of Multiple Choice Questions. Ideal for placement and interview preparation, our questions range from basic to advanced, ensuring comprehensive coverage of Python Programming. Begin your placement preparation journey now!

Q61

Q61 What will the following Python code return?

re.search(r"\d{3}", "The code 123 is valid")

A

'123'

B

<re.Match object; span=(9, 12), match='123'>

C

None

D

'The code 123 is valid'

Q62

Q62 Identify the issue in this regex:

re.findall(r"[A-Z+]", "Python+C+Java")

A

Incorrect use of escape character

B

Wrong pattern for matching uppercase letters

C

'+' should not be escaped

D

No issue

Q63

Q63 In Python, which module is used to work with CSV files?

A

csv

B

json

C

excel

D

fileio

Q64

Q64 What does the following code do?

import json; json.loads('{"name": "John", "age": 30}')

A

Creates a JSON file

B

Parses a JSON string into a Python dictionary

C

Serializes a Python dictionary to JSON

D

Throws an error

Q65

Q65 What is the purpose of a virtual environment in Python programming?

A

Version control

B

To isolate project-specific dependencies

C

Web development

D

Data analysis

Q66

Q66 Which tool is used to install Python packages?

A

git

B

virtualenv

C

pip

D

setuptools

Q67

Q67 What is the key benefit of using requirements.txt in a Python project?

A

For documenting the code

B

To list all the packages and their versions used in the project

C

To improve the performance of the project

D

For version control

Q68

Q68 What is the primary use of the OS module in Python?

A

Networking

B

Web development

C

Interacting with the operating system

D

Data analysis

Q69

Q69 Which function in the OS module is commonly used to change the current working directory?

A

os.change_directory()

B

os.chdir()

C

os.setcwd()

D

os.update_directory()

Q70

Q70 What does os.listdir('.') do?

A

Lists all Python files in the current directory

B

Creates a new directory

C

Lists all files and directories in the current directory

D

Deletes the current directory

Q71

Q71 What is PEP in the context of Python?

A

A Python enhancement proposal

B

A Python error protocol

C

A Python environment path

D

A Python executable program

Q72

Q72 Python is known as:

A

A compiled language

B

An interpreted language

C

A machine language

D

An assembly language

Q73

Q73 Which version of Python removed the print statement?

A

Python 1.x

B

Python 2.x

C

Python 3.x

D

Python 4.x

Q74

Q74 Which of the following is a valid Python comment?

A

<!-- -->

B

/* */

C

#

D

//

Q75

Q75 Python is a:

A

Low-level language

B

High-level language

C

Middle-level language

D

Machine-level language

Q76

Q76 Which of these data types does Python not natively support?

A

Lists

B

Tuples

C

Arrays

D

Dictionaries

Q77

Q77 Which of the following is a mutable data type in Python?

A

String

B

Tuple

C

List

D

Integer

Q78

Q78 What will be the data type of the variable x after this assignment:

x = 3.5?

A

int

B

float

C

str

D

complex

Q79

Q79 What is the output of the following code snippet:

print(type("Hello, World!"))

A

<class 'str'>

B

<class 'int'>

C

<class 'list'>

D

<class 'list'>

Q80

Q80 What does the following code output:

x = [1, 2, 3];
print(type(x) == list)

A

TRUE

B

FALSE

C

Error

D

None

Q81

Q81 What will be the output of the following pseudocode?

Initialize x as 10;
If x is of type int,
print "Integer"
else
print "Not Integer"

A

Integer

B

Not Integer

C

Error

D

None

Q82

Q82 Pseudocode:

Variable
x = "Python";
Check if x is a string,
if yes
print "String",
otherwise
"Not a String"

A

String

B

Not a String

C

Error

D

None

Q83

Q83 Identify the error in this code:

x = [1, 2, 3];
print(x)

A

Syntax error in variable x

B

Missing parenthesis in print

C

Missing bracket in x

D

No error

Q84

Q84 Find the mistake:

x = (1, 2, 3);
x[1] = 4;
print(x)

A

Tuples are immutable

B

x[1] should be x[2]

C

Syntax error

D

No error

Q85

Q85 Which function is used to read input from the console in Python?

A

input()

B

read()

C

scan()

D

getInput()

Q86

Q86 What is the default type of data returned by the input() function in Python 3.x?

A

int

B

string

C

boolean

D

list

Q87

Q87 Which function in Python is used to display data as output?

A

display()

B

print()

C

show()

D

output()

Q88

Q88 What is the purpose of the end parameter in the print() function?

A

To add a space at the end

B

To end the script

C

To specify the string appended after the last value

D

To break the line

Q89

Q89 What does the sep parameter do in the print() function?

A

Separates lines

B

Specifies separator between values

C

Separates syntax errors

D

None of these

Q90

Q90 Pseudocode:

Ask user for number, multiply by 2, print result

A

Reads number, prints double

B

Reads string, prints same

C

Error in input

D

No output