wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Programming Quiz

Total questions: 30

Worksheet time: 15mins

Name
Class
Date
1.

Which function is used to display output in Python?

a)

display()

b)

printf()

c)

echo()

d)

print()

2.

What symbol is used for single-line comments in Python?

a)

--

b)

/* */

c)

#

d)

//

3.

Which statement is used to exit a loop prematurely?

a)

exit

b)

stop

c)

break

d)

quit

4.

What does the continue statement do in a loop?

a)

Skips the current iteration

b)

Does nothing

c)

Exits the loop

d)

Restarts the loop

5.

What is the correct way to create a string in Python?

a)

str = 'Hello'

b)

str = "Hello"

c)

str = """Hello"""

d)

All of the above

6.

What will "Python"[0] return?

a)

y

b)

P

c)

Python

d)

Error

7.

What does the escape sequence \n represent?

a)

Backspace

b)

Newline

c)

Null

d)

Tab

8.

What is a tuple in Python?

a)

Immutable sequence

b)

Dictionary type

c)

Mutable sequence

d)

Set type

9.

How do you create a tuple with a single element?

a)

t = [1]

b)

t = (1,)

c)

t = {1}

d)

t = (1)

10.

What symbol is used to create a dictionary in Python?

a)

{}

b)

[]

c)

<>

d)

()

11.

What will be the result of: 10 // 3?

a)

4

b)

3

c)

3.33

d)

3.0

12.

What will "Amazing"[1:6:2] return?

a)

"mai"

b)

"mzn"

c)

"maz"

d)

"azn"

13.

What will "hello".capitalize() return?

a)

"Hello"

b)

"HELLO"

c)

"hELLO"

d)

"hello"

14.

What will "Python".replace("Py", "Ja") return?

a)

"Jathon"

b)

"Python"

c)

"Javathon"

d)

Error

15.

How do you access a value in a dictionary?

a)

dict.get(key)

b)

Both A and B

c)

dict[key]

d)

dict->key

16.

What method returns all keys in a dictionary?

a)

keys()

b)

keyList()

c)

allKeys()

d)

getKeys()

17.

What is the difference between remove() and discard() in sets?

a)

remove() raises error if element not found

b)

discard() raises error if element not found

c)

No difference

d)

remove() is faster

18.

Which method reads one line from a file?

a)

getline()

b)

read()

c)

readline()

d)

readlines()

19.

Which exception is raised when dividing by zero?

a)

ArithmeticError

b)

ZeroDivisionError

c)

TypeError

d)

ValueError

20.

What does if name == "main": check?

a)

Function name

b)

If module is run directly

c)

Class name

d)

Variable name

21.

What does the enumerate() function return?

a)

List of indices

b)

List of values

c)

Index-value pairs

d)

Dictionary

22.

What is list comprehension?

a)

List method

b)

List sorting

c)

Elegant way to create lists

d)

List copying

23.

What will [x*2 for x in range(5)] return?

a)

[0, 2, 4, 6, 8]

b)

[1, 2, 3, 4, 5]

c)

[2, 4, 6, 8, 10]

d)

[0, 1, 2, 3, 4]

24.

What is a virtual environment in Python?

a)

Virtual machine

b)

Isolated Python environment

c)

Testing environment

d)

Cloud environment

25.

What will "-".join(["a","b","c"]) return?

a)

"a-b-c"

b)

"abc"

c)

"['a-b-c']"

d)

Error

26.

What will "{0} and {1}".format("A", "B") return?

a)

"A, B"

b)

"A and B"

c)

"0 and 1"

d)

"A or B"

27.

What does the filter() function return?

a)

Elements where function returns True

b)

Filtered dictionary

c)

Sorted list

d)

All elements

28.

What will "Python"[::-1] return?

a)

"Python"

b)

Error

c)

"Pytho"

d)

"nohtyP"

29.

What will {1, 2, 3}.intersection({2, 3, 4}) return?

a)

Error

b)

{1, 2, 3, 4}

c)

{1, 4}

d)

{2, 3}

30.

What is the DRY principle in programming?

a)

Define Run Yield

b)

Data Retrieval Yearly

c)

Do Review Yearly

d)

Don't Repeat Yourself