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 is the result of the following code?

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

A

[1, 2, 3]

B

[1, 4, 3]

C

Error

D

[4, 2, 3]

Q62

Q62 Pseudocode:

Initialize list with values [1,2,3];
Add 4 to the end;
Print list

A

Prints [1, 2, 3]

B

Prints [1, 2, 3, 4]

C

Error

D

Prints [4, 1, 2, 3]

Q63

Q63 Pseudocode:

Given a tuple (1,2,3),
print each element multiplied by 2

A

Prints 2, 4, 6

B

Prints 1, 2, 3

C

Error

D

No output

Q64

Q64 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

Q65

Q65 Find the mistake:

myTuple = (1, 2, 3);
myTuple[1] = 4

A

Tuples are immutable

B

Wrong index used

C

Syntax error in tuple declaration

D

myTuple should be a list

Q66

Q66 What is a dictionary in Python?

A

An ordered collection of elements

B

A mutable collection of key-value pairs

C

An immutable collection of items

D

A collection of unique elements

Q67

Q67 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

Q68

Q68 What happens if you try to access a non-existent key 'k' in a dictionary 'd' using d[k]?

A

Returns None

B

Returns an empty string

C

Raises a KeyError

D

Creates a new key 'k' with value None

Q69

Q69 How can you remove a key-value pair from a dictionary?

A

Using the del statement

B

Using the remove() method

C

Using the pop() method

D

Both A and C

Q70

Q70 In Python 3.7 and later, how are elements in a dictionary ordered?

A

By the order they were added

B

In ascending order of keys

C

In descending order of keys

D

Randomly

Q71

Q71 What is the output of the following code?

d = {'a': 1, 'b': 2};
print(d['b'])

A

1

B

2

C

b

D

KeyError

Q72

Q72 What will be the result of the following code?

d = {'a': 1, 'b': 2};
d['c'] = 3;
print(len(d))

A

2

B

3

C

Error

D

1

Q73

Q73 Pseudocode:

Initialize dictionary with {'a': 1, 'b': 2};
Update 'b' value to 3;
Print dictionary

A

Prints {'a': 1, 'b': 2}

B

Prints {'a': 1, 'b': 3}

C

Error

D

No output

Q74

Q74 Pseudocode:

Given a dictionary,
print each key-value pair

A

Prints keys only

B

Prints values only

C

Prints key-value pairs

D

Error

Q75

Q75 Identify the error:
d = {['first']: 1, ['second']: 2}

A

Syntax error with the dictionary

B

Lists can't be dictionary keys

C

No error

D

Dictionary keys must be strings

Q76

Q76 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

Q77

Q77 What is a function in Python?

A

A variable

B

A module

C

A block of code

D

An operator

Q78

Q78 In Python, what is a module?

A

A data type

B

A built-in function

C

A file with definitions

D

A code block

Q79

Q79 How do you import a module in Python?

A

using the import keyword

B

using the include keyword

C

using the require keyword

D

using the module keyword

Q80

Q80 What is the difference between arguments and parameters in Python functions?

A

No difference

B

Parameters define, arguments call

C

Arguments define, parameters call

D

Based on data type

Q81

Q81 What will the following function return:

def example():
return 5+5

A

5+5

B

10

C

0

D

None

Q82

Q82 What is the output of this code:

def add(x, y):
return x + y;
print(add(3, 4))

A

3

B

4

C

7

D

Error

Q83

Q83 Pseudocode:

Define a function that multiplies two numbers and returns the result

A

Returns sum

B

Returns product

C

No return

D

Syntax error

Q84

Q84 Pseudocode:

Function that checks if a number is positive, negative, or zero

A

Prints type of number

B

Returns type of number

C

No output

D

Error

Q85

Q85 Identify the error:

def my_func(x, y):
return x + y;
my_func(1)

A

Missing argument

B

Syntax error

C

Logic error

D

No error

Q86

Q86 Find the mistake:

import math;
print(math.sqr(4))

A

Incorrect module

B

Incorrect function name

C

Wrong number of arguments

D

No error

Q87

Q87 What is the purpose of the open() function in Python?

A

To read data from URL

B

To open a new Python file

C

To open a file

D

To create a Python module

Q88

Q88 Which file mode in Python allows you to read and write to a file?

A

r+

B

w+

C

a+

D

rb+

Q89

Q89 When using with open(file) as f, what does with do?

A

Ensures file is saved

B

Automatically closes the file

C

Opens file in write mode

D

Reads entire file

Q90

Q90 What does the following code do?

with open('file.txt', 'w') as file:
file.write("Hello World")

A

Reads from file.txt

B

Writes "Hello World" to file.txt

C

Deletes file.txt

D

Creates a new file

ad vertical
ad