wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Programming Quiz

Total questions: 31

Worksheet time: 18mins

Name
Class
Date
1.

What symbol can be used in a variable name in Python?

a)

_

b)

&

c)

$

d)

#

2.

Which of the following is a valid integer in Python?

a)

10

b)

3.14

c)

'True'

d)

1.5

3.

What function is used to determine the data type of a variable?

a)

check_type()

b)

type()

c)

data_type()

d)

var_type()

4.

How do you convert a value to a string in Python?

a)

str(value)

b)

to_str(value)

c)

string(value)

d)

convert_to_str(value)

5.

Which operator is used for floor division in Python?

a)

//

b)

**

c)

%

d)

/

6.

What does the len() function do?

a)

Returns the length of a variable

b)

Converts to a list

c)

Counts elements

d)

Finds the maximum value

7.

How do you access the first element of a string in Python?

a)

string.get(0)

b)

string.first()

c)

string[0]

d)

string[1]

8.

What does the str.upper() method do?

a)

Removes spaces

b)

Counts characters

c)

Converts string to lowercase

d)

Converts string to uppercase

9.

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

a)

str.startsWith()

b)

str.first()

c)

str.begin()

d)

str.startswith()

10.

What does the list.append() method do?

a)

Adds an element at the middle of the list

b)

Sorts the list

c)

Adds an element at the start of the list

d)

Adds an element at the end of the list

11.

Which of the following is a valid way to create a list in Python?

a)

list = (1, 2, 3)

b)

list = <1, 2, 3>

c)

list = [1, 2, 3]

d)

list = {1, 2, 3}

12.

What does the set.add() method do?

a)

Counts elements in the set

b)

Adds an element to the set

c)

Clears the set

d)

Removes an element from the set

13.

Which of the following is true about sets in Python?

a)

They allow duplicate values

b)

They can be indexed

c)

They are unordered

d)

They can be sliced

14.

What is the purpose of the break statement in loops?

a)

To continue to the next iteration

b)

To skip the current iteration

c)

To stop the loop

d)

To restart the loop

15.

Which operator is used to check if one condition is true and another is also true?

a)

Or

b)

And

c)

Xor

d)

Not

16.

What does the list.sort() method do?

a)

Clears the list

b)

Sorts the list in ascending order

c)

Reverses the list

d)

Counts elements in the list

17.

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

a)

list.remove(value)

b)

list.delete(value)

c)

list.pop(value)

d)

list.clear(value)

18.

What does the str.split() method do?

a)

Counts characters

b)

Splits a string into a list

c)

Joins strings

d)

Replaces substrings

19.

Which of the following is a valid way to create a set in Python?

a)

set = <1, 2, 3>

b)

set = (1, 2, 3)

c)

set = {1, 2, 3}

d)

set = [1, 2, 3]

20.

What does the intersection() method in sets do?

a)

Removes elements from the set

b)

Adds elements to the set

c)

Gets common values between two sets

d)

Counts elements in the set

21.

Which of the following is a valid way to take user input in Python?

a)

input('Enter your name: ')

b)

get_input('Enter your name: ')

c)

read_input('Enter your name: ')

d)

user_input('Enter your name: ')

22.

What does the list.extend() method do?

a)

Adds multiple elements from another list

b)

Removes all elements

c)

Sorts the list

d)

Adds a single element

23.

Which of the following is NOT a valid data type in Python?

a)

Integer

b)

Float

c)

Character

d)

Boolean

24.

What does the str.replace() method do?

a)

Counts occurrences of a substring

b)

Replaces all occurrences of a substring

c)

Removes spaces

d)

Converts to uppercase

25.

What is the output of the expression 5 % 2?

a)

3

b)

2

c)

1

d)

2.5

26.

Which of the following is used to create a loop that iterates a specific number of times?

a)

while loop

b)

repeat loop

c)

for loop

d)

do-while loop

27.

What does the str.strip() method do?

a)

Converts to lowercase

b)

Removes leading and trailing spaces

c)

Removes all characters

d)

Counts characters

28.

Which of the following is a valid way to define a variable in Python?

a)

var = 10

b)

var == '10'

c)

10 = var

d)

var: int = 10

29.

What does the list.pop() method do?

a)

Removes an element by value

b)

Clears the list

c)

Removes an element by index

d)

Removes the last element

30.

Which of the following is a valid way to create a float in Python?

a)

float = 5,0

b)

float = '5.0'

c)

float = 5.0

d)

float = 5

31.

At the end Draw something within 3 minutes