Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Workshop Quiz

Total questions: 15

Worksheet time: 8mins

Name
Class
Date
1.
  1. Which keyword is used to declare a variable in Python?

a)

var

b)

declare

c)

define

d)

none of the above

2.
  1. What is the output of the following code snippet?

  2. my_tuple = ("apple", "banana", "cherry")

    print(my_tuple[1])

a)

"banana"

b)

"apple"

c)

"cherry"

d)

TypeError:

'tuple' object has no attribute '1'

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

a)
  1. int

b)
  1. float

c)
  1. string

d)
  1. character

4.
  1. What is the output of the following code snippet?

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

print(my_list[1:3])

a)

[1, 2]


b)

[2, 3]

c)

[3, 4]

d)

[1, 2, 3]

5.
  1. How do you check the number of elements in a set in Python?

a)
  1. elements(my_set)

b)
  1. len(my_set)

c)
  1. count(my_set)

d)
  1. size(my_set)

6.
  1. What does the append() method do in Python?

a)
  1. Removes an element from a list

b)
  1. Adds an element to the start of a list

c)
  1. Adds an element to the end of a list

d)

Reverses the order of elements in a list

7.
  1. How do you remove an item from a list in Python?

a)
  1. discard(item)

b)
  1. delete(item)

c)
  1. pop(item)

d)

remove(item)

8.
  1. What is the output of the following code snippet?

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

    print(my_list[-1])

a)

1

b)

2

c)

5

d)

4

9.
  1. Can a tuple be modified after it is created?

a)
  1. Yes, you can add or remove elements from a tuple

b)
  1. No, tuples are immutable and cannot be modified

c)
  1. Only if the tuple contains string elements

d)
  1. Only if the tuple contains numeric elements.

10.
  1. Which operator is used for exponentiation in Python?

a)

**

b)

^

c)

%

d)

*

11.
  1. What is the purpose of the ' pass' statement in Python?

a)
  1. It terminates the program

b)
  1. It raises an exception

c)
  1. It skips the current iteration of a loop

d)
  1. It defines a new function

12.

What is the output of following code snippet?

def Yes():

No()

def No():

Yes()

ans= Yes()

Ans = ("yes")

print (Ans)

a)

Ans

b)

Yes

c)

error

d)

infinte loop

13.
  1. What is the output of the following code snippet?

  2. x = 5

    y = 2

    result = x // y

    print(result)

a)

2.5

b)

2.0

c)

2.5 (with a warning)

d)

2

14.
  1. Which of the following is NOT a valid way to comment a single line of code in Python?

a)
  1. // Comment

b)
  1. # Comment

c)
  1. ''' Comment '''

d)
  1. """ Comment """

15.
  1. What is the output of the following code snippet?

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

    print(mylist[-1])

a)
  1. 1

b)
  1. 2

c)
  1. 5

d)
  1. none of the above