Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

python part2(36-70)

Total questions: 34

Worksheet time: 17mins

Name
Class
Date
1.

How do you write a single-line comment in Python?

a)

# comment

b)

// comment

c)

/* comment */

d)

comment

2.

What is the result of 10 % 3 in Python?

a)

 1

b)

3

c)

30

d)

0

3.

How do you handle exceptions in Python?

a)

try-except

b)

catch-throw

c)

catch-finally

d)

throw-except

4.

Which of the following is the correct way to define a class in Python?

a)

class MyClass:

b)

define MyClass:

c)

MyClass class:

d)

object MyClass:

5.

Which statement is used to exit a loop in Python?

a)

break

b)

exit

c)

end

d)

return

6.

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

a)

append()

b)

add()

c)

insert()

d)

extend()

7.

What does len() function do in Python?

a)

Returns the length of a string or list.

b)

Converts a string to lowercase.

c)

Adds two strings together.

d)

Returns the number of items in a tuple.

8.

Which of the following is the correct way to create a tuple?

a)

my_tuple = (1, 2, 3)

b)

my_tuple = [1, 2, 3]

c)

my_tuple = {1, 2, 3}

d)

my_tuple = 1, 2, 3

9.

What is the correct way to check if a value is in a list in Python?

a)

if x in list:

b)

if list.contains(x):

c)

if x in list[]:

d)

if list.includes(x):

10.

What does the range() function do in Python?

a)

Generates a list of numbers.

b)

Returns a string from a list.

c)

Reverses a list.

d)

Adds two numbers together.

11.

What is the result of the following code: print("abc" + "def")?

a)

abcdef

b)

abc def

c)

ab cdef

d)

None

12.

Which Python method is used to find the index of an element in a list?

a)

index()

b)

position()

c)

find()

d)

locate()

13.

How do you make a string lowercase in Python?

a)

lower()

b)

to_lower()

c)

downcase()

d)

case_lower()

14.

Which of the following Python functions converts a string to a number?

a)

int()

b)

float()

c)

str()

d)

number()

15.

Which keyword is used to define a function in Python?

a)

def

b)

function

c)

func

d)

define

16.

What will print(2 + 3 * 4) output?

a)

14

b)

20

c)

18

d)

12

17.

What is the output of print(2 == 2)?

a)

True

b)

False

c)

None

d)

Error

18.

Which of the following is used to define a dictionary in Python?

a)

{}

b)

[]

c)

()

d)

<>

19.

How do you access the first element of a list my_list = [10, 20, 30]?

a)

my_list[0]

b)

my_list[1]

c)

my_list.first()

d)

my_list[1, 2]

20.

How do you check if a string is empty in Python?

a)

if string == ""

b)

if string.empty()

c)

if string is ""

d)

if len(string) == 0

21.

What will print("Python" == "python") output?

a)

False

b)

 True

c)

None

d)

Error

22.

Which of the following will create a list of numbers from 1 to 10 in Python?

a)

range(1, 11)

b)

list(1, 10)

c)

range(1, 10)

d)

list(1 to 10)

23.

Which method is used to remove an item from a dictionary in Python?

a)

pop()

b)

remove()

c)

delete()

d)

discard()

24.

What does the continue statement do in a loop?

a)

Skips to the next iteration.

b)

Exits the loop completely.

c)

Repeats the current iteration.

d)

Stops the program.

25.

Which function is used to determine the type of an object in Python?

a)

type()

b)

typeof()

c)

object_type()

d)

classof()

26.

What will the following code output? print(bool(""))

a)

False

b)

True

c)

None

d)

Error

27.

How do you start a Python script file?

a)

By saving it with a .py extension.

b)

By saving it with a .python extension.

c)

By using #start as the first line.

d)

By running python init in the terminal.

28.

What will print([1, 2, 3] + [4, 5]) output?

a)

[1, 2, 3, 4, 5]

b)

12345

c)

[5, 4, 3, 2, 1]

d)

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

29.

Which operator is used to repeat a string multiple times in Python?

a)

*

b)

+

c)

&

d)

!

30.

What does the is operator do in Python?

a)

Checks if two variables point to the same object.

b)

Compares the values of two variables.

c)

Assigns a value to a variable.

d)

Tests for membership in a sequence.

31.

Which function is used to round a number in Python?

a)

round()

b)

ceil()

c)

floor()

d)

approx()

32.

How do you create an empty set in Python?

a)

set()

b)

{}

c)

[]

d)

()

33.

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

a)

1

b)

1.3333

c)

0.75

d)

Error

34.

What will print("Python".find("P")) output?

a)

0

b)

-1

c)

None

d)

Error