wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python Programming Quiz 1

Total questions: 30

Worksheet time: 15mins

Name
Class
Date
1.

What is the output of print(10 // 3)?

a)

3.33

b)

3

c)

4

d)

Error

2.

Which of the following is a valid Python function definition?

a)

def func:

b)

def func()

c)

function func()

d)

func def()

3.

What does type([]) return?

a)

list

b)

c)

[]

d)

type

4.

Which operator is used for exponentiation in Python?

a)

^

b)

**

c)

exp()

d)

^^

5.

What is the output of bool([])?

a)

True

b)

False

c)

None

d)

Error

6.

What does 'hello'.capitalize() return?

a)

'Hello'

b)

'hello'

c)

'HELLO'

d)

'Hello '

7.

Which method checks if a string ends with a specific substring?

a)

ends()

b)

finish()

c)

endswith()

d)

close()

8.

What is the result of 'abc'.find('b')?

a)

0

b)

1

c)

2

d)

-1

9.

What is the output of [1, 2, 3] + [4]?

a)

[1, 2, 3, 4]

b)

[5, 6, 7]

c)

[1, 2, 3][4]

d)

Error

10.

Which method removes a specific item from a list?

a)

delete()

b)

remove()

c)

pop()

d)

discard()

11.

What is the output of list(range(3))?

a)

[0, 1, 2]

b)

[1, 2, 3]

c)

[0, 1, 2, 3]

d)

range(3)

12.

What does my_list[::-1] do?

a)

Reverses the list

b)

Sorts the list

c)

Removes duplicates

d)

Returns first item

13.

Which method adds multiple items to a list?

a)

append()

b)

extend()

c)

insert()

d)

add()

14.

What is the output of {'a': 1, 'b': 2}['b']?

a)

1

b)

2

c)

'b'

d)

Error

15.

Which method returns all key-value pairs in a dictionary?

a)

items()

b)

values()

c)

keys()

d)

pairs()

16.

What does dict.get('x', 0) return if 'x' is not a key?

a)

None

b)

'x'

c)

0

d)

Error

17.

Which method merges two dictionaries?

a)

combine()

b)

update()

c)

append()

d)

merge()

18.

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

a)

1

b)

2

c)

3

d)

0

19.

What is the output of lambda x: x + 2 when called with 3?

a)

5

b)

6

c)

3

d)

Error

20.

Which keyword is used to return a value from a function?

a)

yield

b)

return

c)

output

d)

send

21.

What is a default parameter in a function?

a)

Always required

b)

Must be last

c)

Has no value

d)

Can be skipped

22.

Which of these is a valid function call?

a)

func[]

b)

func{}

c)

func()

d)

func<>

23.

What is the output of tuple([1, 2])?

a)

(1, 2)

b)

[1, 2]

c)

{1, 2}

d)

1, 2

24.

Which of these is an immutable data type?

a)

List

b)

Dictionary

c)

Tuple

d)

Set

25.

How do you access the second item in a tuple t = (10, 20, 30)?

a)

t[2]

b)

t[1]

c)

t(1)

d)

t{1}

26.

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

a)

2

b)

3

c)

1

d)

0

27.

Which method is used to count occurrences in a tuple?

a)

count()

b)

index()

c)

find()

d)

search()

28.

What is the output of set([1, 2, 2, 3])?

a)

{1, 2, 3}

b)

[1, 2, 3]

c)

(1, 2, 3)

d)

{1, 2, 2, 3}

29.

Which operation checks membership in a set?

a)

in

b)

has()

c)

contains()

d)

exists()

30.

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

a)

{1, 3}

b)

{2}

c)

{1, 2, 3}

d)

{}