wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python Programming Quiz Unit 2

Total questions: 70

Worksheet time: 35mins

Name
Class
Date
1.

In Python, strings are:

a)

Mutable

b)

Immutable

c)

Changeable

d)

Partially mutable

2.

Which of these creates a multi-line string in Python?

a)

Triple quotes

b)

Double quotes

c)

Single quotes

d)

Curly braces

3.

What does len("Python") return?

a)

5

b)

6

c)

7

d)

Error

4.

In Python, lists are:

a)

Immutable

b)

Mutable

c)

Static in size

d)

Immutable but sortable

5.

Which method is used to add a single element at the end of a list?

a)

append()

b)

extend()

c)

insert()

d)

add()

6.

Which operator is used to repeat a string in Python?

a)

+

b)

*

c)

%

d)

**

7.

What is the output of "Hello" + "World"?

a)

HelloWorld

b)

Hello World

c)

Hello+World

d)

Error

8.

Which method splits a string into a list of words by default?

a)

split()

b)

partition()

c)

break()

d)

divide()

9.

What does "Python"[::-1] produce?

a)

nohtyP

b)

Pytho

c)

nothyP

d)

Error

10.

Which method removes all items from a list?

a)

clear()

b)

remove()

c)

pop()

d)

del()

11.

Which statement will remove the element at index 2 from fruits?

a)

fruits.remove(2)

b)

del fruits[2]

c)

fruits.pop("2")

d)

fruits.delete(2)

12.

Which list method adds elements from another iterable?

a)

append()

b)

extend()

c)

insert()

d)

concat()

13.

What is the output of fruits[-1] if fruits = ["apple","banana","cherry"]?

a)

apple

b)

banana

c)

cherry

d)

Error

14.

Which of these methods returns the index of the first occurrence of an element?

a)

find()

b)

search()

c)

index()

d)

locate()

15.

What will "apple" in ["apple","banana"] return?

a)

True

b)

False

c)

None

d)

Error

16.

Which slicing returns the first 3 characters of s?

a)

s[:3]

b)

s[3:]

c)

s[0:2]

d)

s[1:3]

17.

Which function returns the length of a list?

a)

count()

b)

length()

c)

len()

d)

size()

18.

What will list("abc") return?

a)

['abc']

b)

['a','b','c']

c)

('a','b','c')

d)

Error

19.

Which of the following methods inserts an element at a given position?

a)

append()

b)

extend()

c)

insert()

d)

add()

20.

Which of these can store mixed data types in Python?

a)

List

b)

String

c)

Integer

d)

Boolean

21.

What will "Python".upper() return?

a)

python

b)

PYTHON

c)

Python

d)

Error

22.

What is the output of "banana".count("a")?

a)

1

b)

2

c)

3

d)

4

23.

Which operator checks if an element exists in a list?

a)

==

b)

is

c)

in

d)

has

24.

In Python, negative indexing starts from:

a)

0

b)

-1

c)

-2

d)

Depends on length

25.

Which statement will remove the first occurrence of "apple" from a list?

a)

list.delete("apple")

b)

list.remove("apple")

c)

list.pop("apple")

d)

list.clear("apple")

26.

Output of: s = "Python" print(s[1:4])

a)

Pyt

b)

yth

c)

ytho

d)

yth

27.

Which creates a shallow copy of a list?

a)

copy.copy()

b)

list()

c)

[:]

d)

All of the above

28.

"apple" < "Banana" returns:

a)

True

b)

False

c)

Depends on length

d)

Error

29.

Result of ["a","b"] * 2:

a)

['a','b','a','b']

b)

['a','a','b','b']

c)

['aa','bb']

d)

Error

30.

Which is NOT a valid way to create a string?

a)

"Hello"

b)

'Hello'

c)

'''Hello'''

d)

Hello

31.

Which method returns a new list without modifying the original?

a)

sorted()

b)

sort()

c)

reverse()

d)

pop()

32.

Output of: nums = [1,2,3,4] print(nums[::2])

a)

[1,3]

b)

[2,4]

c)

[1,2,3,4]

d)

Error

33.

Which operation causes a TypeError?

a)

"2" + "3"

b)

"2" * 3

c)

[1,2] + [3,4]

d)

"2" - "3"

34.

"python".capitalize() returns:

a)

PYTHON

b)

Python

c)

python

d)

Error

35.

Method to remove and return the last element of a list:

a)

remove()

b)

pop()

c)

clear()

d)

del()

36.

Method to remove and return the last element of a list:

a)

remove()

b)

pop()

c)

clear()

d)

del()

37.

Value of fruits after: fruits = ["a","b","c"] fruits[1:2] = ["x","y"]

a)

['a','x','y','c']

b)

['a','x','c']

c)

['a','y','x','c']

d)

Error

38.

Strings in Python are:

a)

Mutable

b)

Allow item assignment

c)

Immutable

d)

Can be changed in place

39.

"banana".replace("a","A",2) returns:

a)

bAnAna

b)

bAnana

c)

BanAna

d)

Error

40.

"abc".isalpha() returns:

a)

True

b)

False

c)

None

d)

Error

41.

Output of: s = "Hello" print(s[-1])

a)

H

b)

o

c)

l

d)

Error

42.

Output of: fruits = ["apple","banana"] fruits.append(["cherry","date"]) print(len(fruits))

a)

2

b)

3

c)

4

d)

Error

43.

Output of: s = "Python" print(s[::-1])

a)

Python

b)

nohtyP

c)

Error

d)

nothyP

44.

Output of: lst = [1,2,3] lst.extend([4,5]) print(lst)

a)

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

b)

[1,2,3,4,5]

c)

[4,5,1,2,3]

d)

Error

45.

Output of: s = "banana" print(s.count("na"))

a)

1

b)

2

c)

3

d)

Error

46.

Output of: lst = [1,2,3,4] print(lst.pop())

a)

4

b)

3

c)

None

d)

Error

47.

Output of: words = "one two three".split() print(words[1])

a)

one

b)

two

c)

three

d)

Error

48.

Output of: lst = [1,2,3] lst.insert(1,"a") print(lst)

a)

[1,"a",2,3]

b)

[1,2,"a",3]

c)

["a",1,2,3]

d)

Error

49.

Output of: s = "apple" print(s*2)

a)

appleapple

b)

apple apple

c)

[apple,apple]

d)

Error

50.

Output of: colors = ["red","blue","green"] del colors[1] print(colors)

a)

["red","green"]

b)

["blue","green"]

c)

["red","blue"]

d)

Error

51.

A Python dictionary stores data in:

a)

Ordered list of values

b)

Key-value pairs

c)

Sequential indexes

d)

Nested lists

52.

Which of the following creates a tuple?

a)

my_tuple = (1, 2, 3)

b)

my_tuple = [1, 2, 3]

c)

my_tuple = {1, 2, 3}

d)

my_tuple = dict()

53.

In a Python dictionary, keys must be:

a)

Mutable

b)

Immutable

c)

Lists

d)

Variables only

54.

What is the output of len((1, 2, 3))?

a)

2

b)

3

c)

4

d)

Error

55.

Which method returns all keys in a dictionary?

a)

values()

b)

keys()

c)

items()

d)

get()

56.

Which method is used to get the value for a key, with a default if the key is missing?

a)

keys()

b)

values()

c)

get()

d)

default()

57.

Tuples are:

a)

Mutable

b)

Immutable

c)

Changeable

d)

Copyable

58.

What does dict.items() return?

a)

List of keys

b)

List of values

c)

List of key-value pairs as tuples

d)

None

59.

Which operator is used to check if a key exists in a dictionary?

a)

==

b)

in

c)

is

d)

has

60.

Which function can convert a list of tuples into a dictionary?

a)

convert()

b)

dict()

c)

map()

d)

tuple()

61.

What is the result of: my_dict = {"a": 1, "b": 2} print(my_dict.get("c", 5))

a)

None

b)

Error

c)

5

d)

"c"

62.

Which statement about tuples is False?

a)

Tuples can contain lists

b)

Tuples can be nested

c)

Tuples support indexing

d)

Tuples are immutable

63.

What is the result of: t = (1, 2, 3) t[0] = 4

a)

(4, 2, 3)

b)

Error

c)

None

d)

[4, 2, 3]

64.

Which will create an empty dictionary?

a)

{}

b)

()

c)

[]

d)

dict([])

65.

What will be the output? t = (1,) print(type(t))

a)

tuple

b)

int

c)

list

d)

dict

66.

Output of: d = {"x": 1, "y": 2} d["z"] = 3 print(len(d))

a)

2

b)

3

c)

4

d)

Error

67.

Output of: t = (1, 2, (3, 4)) print(t[2][1])

a)

3

b)

4

c)

(3, 4)

d)

Error

68.

Output of: d = {"a": 1} d.update({"b": 2, "c": 3}) print(sorted(d.keys()))

a)

['a', 'b', 'c']

b)

['c', 'b', 'a']

c)

dict_keys(['a', 'b', 'c'])

d)

Error

69.

Output of: d = {"p": 5, "q": 10} print(d.pop("q"))

a)

5

b)

10

c)

None

d)

Error

70.

Output of: t = (1, 2) + (3, 4) print(t)

a)

(1, 2, (3, 4))

b)

(1, 2, 3, 4)

c)

[1, 2, 3, 4]

d)

Error