Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Basics Quiz

Total questions: 12

Worksheet time: 6mins

Name
Class
Date
1.

What is the correct way to print "Hello world" in Python?

a)

print("Hello world")

b)

echo "Hello world"

c)

printf("Hello world")

d)

System.out.println("Hello world")

2.

How do you access the first item in a list called 'bikes'?

a)

bikes[1]

b)

bikes[0]

c)

bikes[-1]

d)

bikes.first()

3.

Which of the following is a correct way to create a dictionary in Python?

a)

dict = {'key': 'value'}

b)

dictionary = ['key', 'value']

c)

map = ('key', 'value')

d)

list = {'key': 'value'}

4.

What is the result of the following list comprehension: squares = [x**2 for x in range(1, 4)]?

a)

[1, 4, 9]

b)

[1, 2, 3]

c)

[1, 8, 27]

d)

[2, 4, 6]

5.

How do you add a new key-value pair to a dictionary in Python?

a)

dict.add('key', 'value')

b)

dict['key'] = 'value'

c)

dict.append('key', 'value')

d)

dict.insert('key', 'value')

6.

What is the correct syntax for an if-else statement in Python?

a)

if (condition) { } else { }

b)

if condition: else:

c)

if condition: else:

d)

if condition: else:

7.

How do you prompt a user for input in Python?

a)

input("Enter your input: ")

b)

scanf("Enter your input: ")

c)

gets("Enter your input: ")

d)

read("Enter your input: ")

8.

What is the purpose of a while loop in programming?

a)

To repeat a block of code a specific number of times

b)

To repeat a block of code as long as a certain condition is true

c)

To execute a block of code only once

d)

To handle exceptions in code

9.

What is a class in programming?

a)

A block of code that repeats

b)

A function that returns a value

c)

A blueprint for creating objects

d)

A method for handling errors

10.

What is the default mode for opening files in Python?

a)

Write mode ('w')

b)

Append mode ('a')

c)

Read mode ('r')

d)

Execute mode ('x')

11.

What is the purpose of the 'try' block in exception handling?

a)

To define a class

b)

To execute code that might cause an error

c)

To repeat a block of code

d)

To open a file

12.

What is the Zen of Python's advice when choosing between a simple and complex solution?

a)

Complex is better than simple

b)

Simple is better than complex

c)

Both are equally good

d)

Avoid both simple and complex solutions