wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

NRIT_Python_Quiz02

Total questions: 50

Worksheet time: 25mins

Name
Class
Date
1.

What is the output of print([1, 2, 3] + [4, 5, 6])?

a)

[1, 2, 3, 4, 5, 6]

b)

[5, 7, 9]

c)

[4, 5, 6, 1, 2, 3]

d)

Error

2.

What does list1.append(5) do?

a)

Adds 5 to the end of list1

b)

Inserts 5 at index 0

c)

Deletes index 5

d)

Raises an error

3.

What is the output of print(len([1, [2, 3], 4]))?

a)

3

b)

4

c)

5

d)

2

4.

How do you remove an element from a list by value?

a)

list.remove(value)

b)

list.delete(value)

c)

list.pop(value)

d)

del list[value]

5.

What is the result of list1 = [1, 2, 3] and list1 * 2?

a)

[1, 2, 3, 1, 2, 3]

b)

[1, 2, 3, 2]

c)

[1, 2, 3, 1]

d)

[2, 4, 6]

6.

What is the output of dict1 = {'a':1, 'b':2}; print(dict1['a'])?

a)

'a'

b)

1

c)

2

d)

Error

7.

How can you get all the keys of a dictionary?

a)

dict.keys()

b)

dict.values()

c)

dict.items()

d)

dict.get()

8.

Which method removes a key-value pair from a dictionary?

a)

del dict[key]

b)

dict.pop(key)

c)

dict.remove(key)

d)

Both a and b

9.

What happens when you try to access a key that doesn't exist in a dictionary?

a)

Returns None

b)

Raises KeyError

c)

Prints 0

d)

Creates the key

10.

What is the output of len({'a': 1, 'b': 2, 'c': 3})?

a)

3

b)

6

c)

2

d)

1

11.

What is a key property of a Python set?

a)

Allows duplicate values

b)

Maintains insertion order

c)

Elements are unique

d)

Can store lists

12.

What is the result of {1, 2, 3} & {3, 4, 5}?

a)

{1, 2, 3, 4, 5}

b)

{3}

c)

{}

d)

{1, 2, 4, 5}

13.

What does set1.add(5) do?

a)

Adds 5 to set1

b)

Inserts 5 at index 0

c)

Removes 5 from set1

d)

Raises an error

14.

What does set1.update([4, 5, 6]) do?

a)

Replaces elements

b)

Adds multiple elements

c)

Deletes elements

d)

Returns an error

15.

Which set operation removes elements?

a)

set.remove(value)

b)

set.discard(value)

c)

set.pop()

d)

All of the above

16.

Which of these is a keyword in Python?

a)

print

b)

input

c)

class

d)

add

17.

Which identifier is valid in Python?

a)

my_var

b)

2var

c)

my-var

d)

if

18.

How do you check reserved keywords?

a)

help("keywords")

b)

import keyword; keyword.kwlist

c)

keywords()

d)

keyword.list()

19.

Are Python identifiers case-sensitive?

a)

Yes

b)

No

20.

What will print(10 if True else 20) output?

a)

10

b)

20

c)

None

d)

Error

21.

What is the output of if 5 > 2: print("Yes")?

a)

Yes

b)

Error

c)

Nothing

d)

5

22.

What will be the output of the following code? if 10 < 20: if 5 < 10: print("Nested If Works")

a)

No output

b)

Nested If Works

c)

Error

d)

10 < 20 is True

23.

What does an if-elif-else block do?

a)

Executes all conditions

b)

Executes only one true condition

c)

Runs if all conditions are false

d)

Only works with loops

24.

What will be printed? x = 10 if x > 5: print("Greater") elif x < 5: print("Smaller") else: print("Equal")

a)

Greater

b)

Smaller

c)

Equal

d)

Error

25.

What will be the output? if 0: print("Yes") else: print("No")

a)

Yes

b)

No

c)

Error

d)

None

26.

Which statement is true about if-elif-else?

a)

It must have an else

b)

elif is mandatory

c)

It can have multiple elif conditions

d)

if must be at the end

27.

How many times does this loop execute? for i in range(5): print(i)

a)

4

b)

5

c)

Infinite

d)

6

28.

What will happen? count = 0 while count < 3: print(count) count += 1

a)

Prints 0 1 2

b)

Prints 0 1 2 3

c)

Infinite loop

d)

Error

29.

What does range(1, 10, 2) produce?

a)

[1, 3, 5, 7, 9]

b)

[1, 2, 3, 4, 5]

c)

[2, 4, 6, 8, 10]

d)

[1, 10]

30.

Which loop runs at least once?

a)

for

b)

while

c)

do-while

d)

Python does not have do-while

31.

What is the output? for i in "Python": print(i, end=" ")

a)

P y t h o n

b)

Python

c)

Error

d)

Pyt hon

32.

What does break do?

a)

Exits the entire loop

b)

Skips the next iteration

c)

Stops the program

d)

Continues to the next iteration

33.

What is the output? for i in range(5): if i == 3: break print(i)

a)

0 1 2

b)

0 1 2 3 4

c)

3 4

d)

0 1 2 3

34.

What does continue do in a loop?

a)

Exits the loop

b)

Skips the current iteration

c)

Stops execution

d)

Repeats the last iteration

35.

What is the output?

for i in range(5): if i == 2:

continue

print(i)

a)

0 1 3 4

b)

0 1 2 3 4

c)

2 3 4

d)

0 1

36.

Can break be used inside a function?

a)

Yes

b)

No

37.

What is the output? def add(x, y): return x + y print(add(2, 3))

a)

5

b)

2 3

c)

None

d)

Error

38.

How do you define a function?

a)

define func():

b)

def func():

c)

function func():

d)

void func():

39.

What will happen if a function has no return statement?

a)

Returns None

b)

Returns 0

c)

Returns an error

d)

Returns empty string

40.

What is the correct syntax for a function with a default argument?

a)

def func(a=10):

b)

def func(a: 10):

c)

def func(a == 10):

d)

def func(10=a):

41.

What is the output? def multiply(a, b=2): return a * b print(multiply(3))

a)

3

b)

6

c)

Error

d)

None

42.

What is the type of type({})?

a)

dict

b)

class

c)

tuple

d)

list

43.

What does pass do in Python?

a)

Skips execution

b)

Exits loop

c)

Stops function execution

d)

Runs return 0

44.

What is the correct syntax to get the first element of a tuple?

a)

tuple[0]

b)

tuple.get(0)

c)

tuple.first()

d)

tuple[1]

45.

Which keyword is used to create an empty set?

a)

set()

b)

{}

c)

emptyset()

d)

list()

46.

What does is do?

a)

Checks identity

b)

Checks equality

c)

Assigns values

d)

Creates a variable

47.

What will be the output? x = [5, 6, 7] y = [6, 7, 8] print(x - y)

a)

Error

b)

{6, 7}

c)

{5, 8}

d)

{5}

48.

What will be printed? print(type([]) is list)

a)

True

b)

False

c)

Error

d)

None

49.

What is the output? print("Python"[::-1])

a)

nohtyP

b)

Python

c)

Error

d)

nPhtyo

50.

What is the result of 10 == 10.0?

a)

True

b)

False

c)

Error

d)

None