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!

Q1

Q1 What data type would you use to store a whole number in Python?

A

int

B

float

C

str

D

bool

Q2

Q2 Which of the following is not a Python built-in data type?

A

dict

B

array

C

set

D

frozenset

Q3

Q3 Which of the following is an immutable data type?

A

Lists

B

Dictionaries

C

Tuples

D

Sets

Q4

Q4 Evaluate this pseudocode:

Set x = [1, 2, 3];
If x is a list, print length of x, else print "Not a list"

A

3

B

Not a list

C

Error

D

0

Q5

Q5 What will be the output of

print("Python", "Programming", sep="-")

A

Python-Programming

B

Python Programming

C

PythonProgramming

D

Python,Programming

Q6

Q6 What is the output of

print("Hello", end='@');
print("World")

A

HelloWorld

B

Hello@World

C

Hello World

D

Hello@ World

Q7

Q7 Pseudocode:

Print each element in list [1, 2, 3] with a space in between

A

123

B

37623

C

[1, 2, 3]

D

37623

Q8

Q8 Identify the error:

print("Hello World!"))

A

Missing quotation marks

B

Extra parenthesis

C

Missing parenthesis

D

No error

Q9

Q9 What will happen if the condition in an if statement in Python evaluates to False?

A

The program will stop

B

It will execute the else block

C

It will raise an error

D

It will skip to the next if

Q10

Q10 What is the outcome if the elif and else blocks are missing in an if statement?

A

Syntax error

B

The program will stop

C

Nothing, it's optional

D

Runtime error

Q11

Q11 What is the output of the following code?

x = 10;
if x > 5:
print("Greater")

A

Error

B

Greater

C

Nothing

D

Less

Q12

Q12 What will the following code print?

x = 10;
if x < 10:
print("Less");
else:
print("Not Less")

A

Less

B

Not Less

C

Error

D

Nothing

Q13

Q13 Pseudocode:

Check if a number is divisible by 2,
if yes
print "Even",
otherwise
"Odd"

A

Prints "Even"

B

Prints "Odd"

C

Error

D

No output

Q14

Q14 Identify the error:

if x > 10
print("Greater")

A

Missing parentheses around condition

B

No error

C

Missing colon after condition

D

Incorrect comparison operator

Q15

Q15 What is the use of a for loop in Python?

A

To repeat a block a fixed number of times

B

To check a condition

C

To declare variables

D

To handle exceptions

Q16

Q16 What does the continue statement do inside a loop?

A

Pauses the loop

B

Stops the loop

C

Skips the current iteration

D

Exits the program

Q17

Q17 What is the difference between a for loop and a while loop in Python?

A

for is used for fixed iterations

B

while is faster than for

C

for can't use conditional statements

D

There is no difference

Q18

Q18 What is the output of the following code?

for i in range(3):
print(i)

A

"0 1 2"

B

"1 2 3"

C

"0 1 2 3"

D

"Error"

Q19

Q19 Pseudocode:

Set x = 10;
While x > 0,
decrement x by 1,
print x

A

Prints numbers from 10 to 1

B

Prints numbers from 1 to 10

C

Prints numbers from 9 to 0

D

Infinite loop

Q20

Q20 Pseudocode:

For numbers 1 to 5,
print number
if it's odd

A

Prints 1 3 5

B

Prints 2 4

C

Prints all numbers 1 to 5

D

No output

Q21

Q21 Identify the error:
for i in range(5)
print(i)

A

Missing colon after range(5)

B

Missing parentheses around print

C

Syntax error in range

D

No error

Q22

Q22 Find the mistake:

while True:
print("Looping");
break

A

Infinite loop

B

No error

C

The loop will never break

D

Incorrect use of print statement

Q23

Q23 What is the main difference between a list and a tuple in Python?

A

Syntax

B

Data type

C

Mutability

D

Method of declaration

Q24

Q24 How do you access the last element of a list named myList?

A

myList[0]

B

myList[-1]

C

myList[len(myList)]

D

myList[-2]

Q25

Q25 In Python, how can you combine two lists, list1 and list2?

A

list1 + list2

B

list1.append(list2)

C

list1.combine(list2)

D

list1.extend(list2)

Q26

Q26 What does myList[::-1] do?

A

Reverses myList

B

Copies myList

C

Removes the last element from myList

D

Sorts myList in descending order

Q27

Q27 Identify the error:

myList = [1, 2, 3);
myList.append(4)

A

Syntax error with the list declaration

B

append() method is used incorrectly

C

No error

D

Lists cannot contain integers

Q28

Q28 How do you access the value associated with a key 'k' in a dictionary 'd'?

A

d('k')

B

d[k]

C

d.get('k')

D

All of the above

Q29

Q29 Find the mistake:

d = {'a': 1, 'b': 2};
print(d.get('c', 'Not Found'))

A

Syntax error in the dictionary

B

get() method used incorrectly

C

Key 'c' doesn't exist

D

No error

Q30

Q30 In Python, what is a module?

A

A data type

B

A built-in function

C

A file with definitions

D

A code block