Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

ProgrammingwithPython(MockTestObjectives)

Total questions: 55

Worksheet time: 18mins

Name
Class
Date
1.

What is the data type of the result of the expression 10 / 5?

a)

int

b)

float

c)

complex

d)

string

2.

What is the output of the expression 5 + 3 * 2?

a)

16

b)

11

c)

10

d)

13

3.

Which operator is used for floor division ?

a)

/

b)

//

c)

%

d)

**

4.

What will be the output of type(None)?

a)

<class 'Nonetype'>

b)

<class 'None'>

c)

<class 'null'>

d)

<class 'object'>

5.

What is the value of the expression 2**3**2?

a)

64

b)

512

c)

36

d)

81

6.

What does the logical operator ( not ) do in Python?

a)

Returns the opposite boolean value.

b)

Returns the value if it's not zero.

c)

Converts the value to a string.

d)

Checks for inequality.

7.

What is the result of the comparison 5 < 10 and 20 > 15 ?

a)

5

b)

False

c)

True

d)

None

8.

Which of the following is a valid Python variable name?

a)

9variable

b)

my-variable

c)

_myVariable

d)

for

9.

Which Python keyword is used to define a function?

a)

func

b)

function

c)

def

d)

define

10.

Which statement is used to do nothing, serving as a placeholder?

a)

none

b)

return

c)

pass

d)

continue

11.

Which two operators in Python can be chained together for comparison, e.g., a < b < c ?

a)

Arithmetic

b)

Bitwise

c)

Assignment

d)

Comparision

12.

What is the output of the following loop?

a)

0 2

b)

0 1

c)

0 2 4

d)

1 2

13.

How many times will the following code print "Hello"?

a)

5

b)

0

c)

1

d)

Infinite

14.

Which statement is used to terminate the entire loop immediately?

a)

pass

b)

continue

c)

stop

d)

break

15.

If an if condition is False, which block of code is executed next if it exists?

a)

else if

b)

finally

c)

except

d)

elif or else

16.

In a Python for loop, what does the in keyword typically iterate over?

a)

A function

b)

An integer

c)

An iterable

d)

A keyword

17.

What is the output of the following code?

a)

python

b)

pyt

c)

p y t h

d)

p y t o n

18.

What is the index of the character 'o' in the string "Hello World"?

a)

3

b)

4

c)

7

d)

0

19.

What is the length of the string "Python\n" (where \n is a newline character)?

a)

6

b)

7

c)

8

d)

5

20.

What is the result of the string slice "Hello"[1:4] ?

a)

"ell"

b)

"ello"

c)

"hel"

d)

"HI"

21.

Which string method converts all characters in a string to uppercase?

a)

capitalize()

b)

title()

c)

upper()

d)

casefold()

22.

The operation 'Py' * 3 results in:

a)

'PyPyPy'

b)

'3Py'

c)

'Py + Py + Py'

d)

Error

23.

What will be the output of 'abc'.startswith('a')?

a)

True

b)

False

c)

'a'

d)

0

24.

Which of the following is NOT a method that can be used on a string?

a)

strip()

b)

count()

c)

append()

d)

replace()

25.

Which method is used to remove a specific item by value from a list?

a)

pop()

b)

delete()

c)

remove()

d)

discard()

26.

Given my_list = [10, 20, 30], what is the result of my_list[1] = 25?

a)

Error, lists are immutable.

b)

[10, 20, 30]

c)

[10, 25, 30]

d)

[25, 20, 30]

27.

Which built-in function returns the number of items in a list or tuple?

a)

size()

b)

count()

c)

len()

d)

length()

28.

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

a)

Lists can hold multiple types, tuples cannot.

b)

Lists are mutable, tuples are immutable.

c)

Tuples are always shorter than lists.

d)

Lists use parentheses () and tuples use square brackets [].

29.

Which method is used to add all the elements of an iterable (like another list) to the end of a list?

a)

append()

b)

insert()

c)

merge()

d)

extend()

30.

What will be the output of (1, 2, 3) + (4, 5)?

a)
  • (1, 2, 3, 4, 5)

b)

(5, 7, 3)

c)

Error

d)

[1, 2, 3, 4, 5]

31.

In a Python dictionary, what are the elements stored as?

a)

Values only

b)

Indexed positions

c)

Key-Value points

d)

Ordered sequences

32.

Which method is the safer way to access a dictionary value, as it returns a default value instead of raising a KeyError if the key is not found?

a)

dict['key']

b)

dict.get('key')

c)

dict.find('key')

d)

dict.lookup('key')

33.

What characteristic of a set's elements ensures that each element is unique?

a)

They must be mutable.

b)

They must be indexed.

c)

They must be hashable.

d)

They must be integers.

34.

Which operation is used to find the common elements between two sets?

a)

Union (|)

b)

Difference (-)

c)

Intersection (&)

d)

Concatenation (+)

35.

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

a)

6

b)

3

c)

0

d)

Error

36.

What is the term for a function that does not explicitly use a return statement?

a)

Void function

b)

Generator function

c)
  • Non-fruitful function

d)

Lambda function

37.

What are the variables defined inside a function called?

a)

Global variables

b)

Local variables

c)

Function variables

d)

Module variables

38.

Which keyword is used within a function to assign a value to a variable defined outside of the function's local scope?

a)

this

b)

outer

c)

global

d)

var

39.

What is the default mode when opening a file using the open() function if no mode is specified?

a)

Write (w)

b)

Read (r)

c)

Append (a)

d)

Read and write (r+)

40.

When should the with open(...) construct be used for file handling?

a)

Only for reading binary files.

b)

To automatically close the file, even if errors occur.

c)

To prevent users from writing to the file.

d)

It is only required for network file access.

41.

What is the output of the following code?

a)

0 1 2 3 4

b)

0 1 2 3

c)

1 2 3 4

d)

Error

42.

What is the final value of my_list after running the following code?

a)

[1, 2, 3, 4, 5]

b)

[1, 2, 8]

c)

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

d)

[1, 2, 3, 4]

43.

What is the output of the following code?

a)

gram

b)

ogrm

c)

ramm

d)

gramm

44.

How many times is the asterisk (*) printed by the following code?

a)

2

b)

3

c)

5

d)

6

45.

What is the output of the following code?

a)

3

b)

4

c)

3.333

d)

1

46.

What is the value of result after the following code runs?

a)

'P'

b)

'h'

c)

Error

d)

4

47.

What is the output of the following loop?

a)

30 40

b)

10 20

c)

10 20 30 40

d)

10 20 40

48.

What is the output of the following code?

a)

0

b)

10

c)

None

d)

KeyError

49.

What will happen when you run the following code?

a)
  • (1, 5, 3)

b)

(1, 2, 3, 5)

c)

A TypeError is raised.

d)

(1, 5, 3) is printed, but a warning is issued.

50.

What is the output of the following code?

a)

True

b)

False

c)

Error

d)

0

51.

What is the output of the following code?

a)

15

b)

510

c)

'510'

d)

Error

52.

What is the final value of numbers?

a)

[1, 9, 9, 5]

b)

[1, 9, 9, 4, 5]

c)

[1, 9, 5]

d)
  • [1, 9, 9]

53.

What is the output of the following code?

a)

5 End

b)

End

c)

5

d)

Nothing is printed

54.

What is the output of the following code?

a)

Alice Hello

b)

Hello Alice

c)

Error: message not provided

d)

Hello

55.

What is the final value of result?

a)

{1, 2, 3, 4, 5}

b)

{3}

c)

{1, 2, 4, 5}

d)

{1, 2, 3}, {3, 4, 5}