wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

101 suraq. (by Dias Bolat)

Total questions: 101

Worksheet time: 51mins

Name
Class
Date
1.

. What is the output of the following code?

text = "Python"

for letter in text:

print(letter, end=",")

a)

a) P,y,t,h,o,n

b)

b) P y t h o n

c)

c) Python

d)

d) P,y,t,h,o,n

2.

What does the `input()` function do in Python?

a)

Prints output to the console

b)

b) Reads input from the user

c)

Imports modules

d)

Performs mathematical operations

3.

What is the result of the following code? ```python

x = 10

while x > 0:

print(x) x -= 2

a)

a) 10 8 6 4 2

b)

b) 10 9 8 7 6 5 4 3 2 1

c)

) 10 8 6 4 2 0

d)

d) 10 8 6 4

4.

Which of the following is a correct Python syntax for an if statement?

a)

if x = 5:

b)

`if x == 5`

c)

`if x equals 5:`

d)

`if x == 5 then:`

e)

`if x == 5:

5.

In Python, the break statement can only be used within loops.

a)

True

b)

False

6.

What does the `range(3, 10, 2)` function in Python represent?

a)

A range from 3 to 10 with a step of 2

b)

A range from 3 to 9 with a step of 2

c)

) A range from 3 to 10 with a step of 1

d)

A range from 3 to 11 with a step of 2

e)

A range from 2 to 10 with a step of 3

7.

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

a)

variable_name = value

b)

value = variable_name

c)

var = value

d)

value = var

e)

) All of the above

8.

What does the `print()` function do in Python?

a)

Reads input from the user

b)

Performs mathematical operations

c)

Imports modules

d)

) Prints output to the console

9.

What is the output of the following code snippet?

```python

word = "Python"

print(word[0:3])

a)

Py

b)

) Pyt

c)

pyt

d)

) P

10.

. The continue statement in Python can only be used within loops.

a)
True
b)
False
11.

Which of the following is a correct way to declare a string variable in Python?

a)

string_variable = "Hello"

b)

string variable = "Hello"

c)

stringVariable = "Hello"

d)

) STRING_VARIABLE = "Hello"

12.

. In Python, which loop is used when the number of iterations is known?

a)

while loop

b)

for loop

c)

nested loop

d)

do-while loop

13.

What is the result of the following code?

```python

x = 10

while x > 0:

print(x) x -= 2

a)

10 8 6 4 2

b)

10 9 8 7 6 5 4 3 2 1

c)

10 8 6 4 2 0

d)

) 10 8 6 4

14.

. Which of the following is a correct Python syntax for an if statement?

a)

`if x = 5:`

b)

`if x == 5`

c)

`if x equals 5:`

d)

`if x == 5 then:`

e)

`if x == 5:

15.

. In Python, a string can be enclosed in single quotes (`'`) or double quotes (`"`).

a)

True

b)

False

16.

What does IDE stand for?

a)

Integrated Design Environment

b)

Integrated Development Environment

c)

Intelligent Design Execution

d)

Interface Development Environment

17.

Which of the following is NOT a valid Python variable name?

a)

my_variable

b)

1st_variable

c)

variable_one

d)

_variable_two

18.

What is the result of "Python"[::-1] in Python?

a)

Python

b)

nohtyP

c)

n

d)

Error

19.

What is the result of `"hello" + "world"` in Python?

a)

hello world

b)

helloworld

c)

hello+world

d)

Error

20.

. In Python, a variable name must start with a letter or an underscore.

a)

True

b)

False

21.

Which of the following is NOT a comparison operator in Python?

a)

==

b)

!=

c)

<>

d)

>=

22.

What will be the output of the following code?

```python

x = 5

if x > 10:

print("Greater than 10")

else:

print("Less than or equal to 10")

```

a)

Greater than 10

b)

Less than or equal to 10

c)

Error

d)

None

23.

What does the `str()` function do in Python?

a)

Converts a number to a string

b)

Converts a string to a number

c)

Checks if a string contains only alphabetic characters

d)

Returns the length of a string

24.

What is the result of `"Hello"[-1:]` in Python?

a)

Hello

b)

H

c)

o

d)

olleH

25.

. The range() function in Python generates a list of integers starting from 1 by default.

a)

True

b)

False

26.

What is the result of the expression `3 * "Python"` in Python?

a)

PythonPythonPython

b)

9

c)

Error

d)

none

27.

What does the `break` statement do in Python?

a)

Exits the loop completely

b)

Skips the rest of the code block and moves to the next iteration of the loop

c)

Allows the loop to continue to the next iteration

d)

None of the above

28.

What is the result of `"hello".upper()` in Python?

a)

"hello"

b)

"HELLO"

c)

"Hello"

d)

Error

29.

. How many times will the following loop iterate?

```python

for i in range(5):

print(i)

```

a)

4

b)

5

c)

6

d)

0

30.

The else statement can be used without an if statement in Python

a)

True

b)

False

31.

. What will be the output of the following code?

list_1 = [1, 2, 3]

list_2 = list_1 * 2

print(list_2)2)

a)

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

b)

[2, 4, 6]

c)

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

d)

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

32.

What is the purpose of recursion in programming?

a)

Repeating a process until a specific condition is met

b)

Implementing iterative loops

c)

Breaking down a problem into smaller, similar sub-problems

d)

Generating random numbers

33.

. In a 2D list in Python, how would you access the element in the second row and third column?

a)

list[2][3]

b)

list[1][2]

c)

list[3][2]

d)

list[1][3]

34.

Which of the following operations can be performed on sets in Python?

a)

Union

b)

Intersection

c)

Subtraction

d)

All of the above

35.

. What is the output of the following code snippet?

my_dict = {"apple": 2, "banana": 3, "orange": 1}

print(my_dict["banana"])

a)

"banana"

b)

KeyError

c)

2

d)

3

36.

. What will be the output of the following code snippet?

my_list = [1, 2, 3, 4]

print(my_list[2])

a)
1
b)
4
c)
5
d)
3
37.

Which of the following methods can be used to add an element at the end of a list in Python?

a)

append()

b)

add()

c)

insert()

d)

extend()

38.

What is the purpose of a return statement in a function?

a)

To halt the execution of the function

b)

To print a value to the console

c)

To return a value from the function

d)

To define a recursive call

39.

What is the base case in a recursive function?

a)

The case where the function returns a value

b)

The case where the function calls itself

c)

The case where the function terminates without making a recursive call

d)

The case where the function has no parameters

40.

Which of the following methods can be used to initialize a 2D list in Python?

a)

[[0]*n]*m

b)

[[]]*n

c)

[[]]*m

d)

[[0]*m]*n

41.

What will be the output of the following code snippet?

matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

print(matrix[1][2])

a)
3
b)
5
c)
8
d)
6
42.

Which of the following statements about 2D lists in Python is true?

a)

All rows in a 2D list must have the same length

b)

2D lists cannot be passed as arguments to functions

c)

2D lists cannot contain lists as elements

d)

Accessing elements in a 2D list requires nested loops

43.

What is a set in Python?

a)

An ordered collection of elements

b)

A collection of key-value pairs

c)

A mutable collection of elements with duplicate values allowed

d)

An unordered collection of unique elements

44.

What is a tuple in Python?

a)

An ordered collection of elements

b)

An unordered collection of unique elements

c)

A mutable collection of elements

d)

An immutable collection of elements

45.

How do you concatenate two tuples in Python?

a)

Using the + operator

b)

Using the concat() method

c)

Using the extend() method

d)

Using the append() method

46.

.Which of the following methods can be used to add an element at the end of a list in Python?

a)

append()

b)

add()

c)

insert()

d)

extend()

47.

What does the list.pop() method do in Python?

a)

Adds an element to the end of the list

b)

Removes and returns the last element from the list

c)

Inserts an element at the specified position

d)

Retrieves the index of a specified element

48.

Consider the following code:

my_list = [1, 2, 3, 4]

del my_list[2]

print(my_list)

What will be printed?

a)

[1, 2, 4]

b)

[1, 2, 3]

c)

[2, 3, 4]

d)

[1, 3, 4]

49.

Which of the following statements about Python lists is false?

a)

Lists can contain elements of different data types

b)

Lists are mutable

c)

Lists can be nested

d)

Lists are always sorted

50.

Which of the following statements about recursion is true?

a)

Recursion is always more efficient than iteration

b)

Recursion involves a function calling itself

c)

Recursion is limited to a fixed number of iterations

d)

Recursion cannot be used in Python

51.

What is the base case in a recursive function?

a)

The case where the function returns a value

b)

The case where the function calls itself

c)

The case where the function terminates without making a recursive call

d)

The case where the function has no parameters

52.

How would you access the element in the second row and third column of a 2D list in Python?

a)

list[2][3]

b)

list[1][2]

c)

list[3][2]

d)

list[1][3]

53.

How would you add a new row to a 2D list in Python?

a)

Use the append() method with a list containing the new row

b)

Use the insert() method with the index set to the desired row number

c)

Use the extend() method with a list containing the new row

d)

Use the add() method with a list containing the new row

54.

How would you remove an element from a set in Python?

a)

Using the remove() method

b)

Using the pop() method

c)

Using the discard() method

d)

All of the above

55.

.What will be the output of the following code snippet?

set1 = {1, 2, 3}

set2 = {3, 4, 5}

print(set1.union(set2))

a)

{1, 2, 3, 4, 5}

b)

{3}

c)

{1, 2, 4, 5}

d)

{}

56.

.What is the purpose of packing and unpacking tuples in Python?

a)

Packing allows you to combine multiple values into a single tuple, while unpacking allows you to extract values from a tuple into separate variables

b)

Packing allows you to create empty tuples, while unpacking allows you to remove elements from a tuple

c)

Packing allows you to convert tuples to lists, while unpacking allows you to convert lists to tuples

d)

Packing allows you to sort tuples, while unpacking allows you to reverse the order of elements in a tuple

57.

.How would you access the last element of a tuple in Python?

a)

By using negative indexing

b)

By using positive indexing

c)

By using the last() method

d)

By converting the tuple to a list

58.

What is the difference between a tuple and a list in Python?

a)

Tuples are mutable, while lists are immutable

b)

Tuples are ordered collections, while lists are unordered collections

c)

Tuples can contain elements of different data types, while lists cannot

d)

Tuples are immutable, while lists are mutable

59.

How would you find the length of a tuple in Python?

a)

Using the count() method

b)

Using the size() function

c)

Using the length() function

d)

Using the len() function

60.

What will be the output of the following code snippet?

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

print(2 in my_list)

a)

True

b)

False

c)

[2]

d)

2

61.

Which of the following statements about Python lists is false?

a)

Lists can contain elements of different data types

b)

Lists are mutable

c)

Lists can be nested

d)

Lists are always sorted

62.

What will be the output of the following code snippet?

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

print(my_list[2:4])

a)

[1, 2]

b)

[2, 3]

c)

[3, 4]

d)

[2, 4]

63.

Which of the following methods can be used to remove an element from a list by its value?

a)

remove()

b)

delete()

c)

pop()

d)

erase()

64.

What is the purpose of packing and unpacking tuples in Python?

a)

Packing allows you to combine multiple values into a single tuple, while unpacking allows you to extract values from a tuple into separate variables

b)

Packing allows you to create empty tuples, while unpacking allows you to remove elements from a tuple

c)

Packing allows you to convert tuples to lists, while unpacking allows you to convert lists to tuples

d)

Packing allows you to sort tuples, while unpacking allows you to reverse the order of elements in a tuple

65.

.How would you reverse the elements of a list in Python?

a)

Using the reverse() method

b)

Using the invert() method

c)

Using the flip() method

d)

Using the revert() method

66.

What is the output of the following recursive function?

def factorial(n):

if n == 0:

return 1

else:

return n * factorial(n - 1) p

rint(factorial(4))

a)
12
b)
16
c)
24
d)

120

67.

What is a set in Python?

a)

An ordered collection of elements

b)

A collection of key-value pairs

c)

A mutable collection of elements with duplicate values allowed

d)

An unordered collection of unique elements

68.

How do you access the third element of a tuple in Python?

a)

By using the index 3

b)

By using the index -3

c)

By using the index 2

d)

By using the index -2

69.

What is the primary difference between a set and a tuple in Python?

a)

Sets are mutable, while tuples are immutable

b)

Sets are ordered, while tuples are unordered

c)

Sets can contain duplicate elements, while tuples cannot

d)

Sets can only contain numerical elements, while tuples can contain any data type

70.

.How do you iterate over all elements in a 2D list named matrix in Python?

a)

Using a single for loop

b)

Using nested for loops

c)

Using the map() function

d)

Using the enumerate() function

71.

Which data structure in Python is suitable for storing a collection of elements with no duplicates and no specific order requirement?

a)

List

b)

Tuple

c)

Set

d)

Dictionary

72.

.What is the purpose of the in and not in operators in Python?

a)

They are used to check if a variable is assigned a value or not

b)

they are used to check if a key exists in a dictionary

c)

They are used to check if an element is present in a sequence (such as a list, tuple, or string

d)

They are used to concatenate strings

73.

Which of the following methods can be used to convert a tuple to a list in Python?

a)

convert()

b)

list()

c)

to_list()

d)

make_list()

74.

Which keyword is used to define a function in Python?

a)

func

b)

define

c)

def

d)

function

75.

How do you call (invoke) a function named my_function in Python?

a)

invoke my_function()

b)

call my_function()

c)

my_function()

d)

execute my_function()

76.

Consider the following code:

my_list = [1, 2, 3, 4]

del my_list[2]

print(my_list)

What will be printed?

a)

[1, 2, 4]

b)

[1, 2, 3]

c)

[2, 3, 4]

d)

[1, 3, 4]

77.

What is the purpose of recursion in programming?

a)

Repeating a process until a specific condition is met

b)

Implementing iterative loops

c)

Breaking down a problem into smaller, similar sub-problems

d)

Generating random numbers

78.

Which of the following statements about recursion is true?

a)

Recursion is always more efficient than iteration

b)

Recursion involves a function calling itself

c)

Recursion is limited to a fixed number of iterations

d)

Recursion cannot be used in Python

79.

How would you reverse the elements of a list in Python?

a)

Using the reverse() method

b)

Using the invert() method

c)

Using the flip() method

d)

Using the revert() method

80.

How do you access the third element of a tuple in Python?

a)

By using the index 3

b)

) By using the index -3

c)

By using the index 2

d)

By using the index -2

81.

What is the primary difference between a set and a tuple in Python?

a)

Sets are mutable, while tuples are immutable

b)

Sets are ordered, while tuples are unordered

c)

) Sets can contain duplicate elements, while tuples cannot

d)

Sets can only contain numerical elements, while tuples can contain any data type

82.

How would you add a new row to a 2D list in Python?

a)

Use the append() method with a list containing the new row

b)

Use the insert() method with the index set to the desired row number

c)

Use the extend() method with a list containing the new row

d)

Use the add() method with a list containing the new row

83.

How would you access the element in the second row and third column of a 2D list in Python?

a)

list[2][3]

b)

list[1][2]

c)

) list[3][2]

d)

list[1][3]

84.

What will be the output of the following code snippet?

set1 = {1, 2, 3}

set2 = {3, 4, 5}

print(set1.union(set2))

a)

{1, 2, 3, 4, 5}

b)

{3}

c)

{1, 2, 4, 5}

d)

{}

85.

What will be the output of the following code snippet?

my_list = [1, 2, 3, 4]

print(my_list[2])

a)

3

b)

2

c)

4

d)

1

86.

What is a set in Python?

a)

An ordered collection of elements

b)

A collection of key-value pairs

c)

A mutable collection of elements with duplicate values allowed

d)

An unordered collection of unique elements

87.

What is the base case in a recursive function?

a)

The case where the function returns a value

b)

The case where the function calls itself

c)

The case where the function terminates without making a recursive call

d)

The case where the function has no parameters

88.

How would you find the length of a tuple in Python?

a)

Using the count() method

b)

Using the size() function

c)

Using the length() function

d)

Using the len() function

89.

Which of the following statements about Python lists is false?

a)

Lists can contain elements of different data types

b)

Lists are mutable

c)

Lists can be nested

d)

Lists are always sorted

90.

Which data structure in Python is suitable for storing a collection of elements with no duplicates and no specific order requirement?

a)

List

b)

Tuple

c)

set

d)

Dictionary

91.

What is the difference between a tuple and a list in Python?

a)

Tuples are mutable, while lists are immutable

b)

Tuples are ordered collections, while lists are unordered collections

c)

Tuples can contain elements of different data types, while lists cannot

d)

Tuples are immutable, while lists are mutable

92.

.What is the purpose of the in and not in operators in Python?

a)

They are used to check if a variable is assigned a value or not

b)

They are used to check if a key exists in a dictionary

c)

They are used to check if an element is present in a sequence (such as a list, tuple, or string)

d)

They are used to concatenate strings

93.

What will be the output of the following code?

list_1 = [1, 2, 3]

list_2 = list_1 * 2

print(list_2)

a)

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

b)

[2, 4, 6]

c)

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

d)

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

94.

What is the purpose of packing and unpacking tuples in Python?

a)

Packing allows you to combine multiple values into a single tuple, while unpacking allows you to extract values from a tuple into separate variables

b)

Packing allows you to create empty tuples, while unpacking allows you to remove elements from a tuple

c)

Packing allows you to convert tuples to lists, while unpacking allows you to convert lists to tuples

d)

Packing allows you to sort tuples, while unpacking allows you to reverse the order of elements in a tuple

95.

Which of the following operations can be performed on sets in Python?

a)

Union

b)

Intersection

c)

Subtraction

d)

All of the above

96.

What will be the output of the following code snippet?

matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

print(matrix[1][2])

a)

1

b)

2

c)

3

d)

6

97.

How do you iterate over all elements in a 2D list named matrix in Python?

a)

Using a single for loop

b)

Using nested for loops

c)

Using the map() function

d)

Using the enumerate() function

98.

What does the list.pop() method do in Python?

a)

Adds an element to the end of the list

b)

Removes and returns the last element from the list

c)

Inserts an element at the specified position

d)

Retrieves the index of a specified element

99.

What is the purpose of a return statement in a function?

a)

To halt the execution of the function

b)

To print a value to the console

c)

To return a value from the function

d)

To define a recursive call

100.

How do you concatenate two tuples in Python?

a)

Using the + operator

b)

Using the concat() method

c)

Using the extend() method

d)

Using the append() method

101.

Which of the following statements about 2D lists in Python is true?

a)

All rows in a 2D list must have the same length

b)

2D lists cannot be passed as arguments to functions

c)

2D lists cannot contain lists as elements

d)

Accessing elements in a 2D list requires nested loops