Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Beginner Python Programming Assessment

Total questions: 30

Worksheet time: 15mins

Name
Class
Date
1.

What is the correct syntax to output 'Hello, World!' in Python?

a)

print('Hello, World!')

b)

print('Hello World!')

c)

echo 'Hello, World!'

d)

println('Hello, World!')

2.

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

a)

valid_variable_name

b)

variable-name

c)

invalidVariableName!

d)

123variableName

3.

What is the purpose of the 'def' keyword in Python?

a)

The 'def' keyword is used to import modules in Python.

b)

The 'def' keyword is used to create a class in Python.

c)

The 'def' keyword is used to declare a variable in Python.

d)

The 'def' keyword is used to define a function in Python.

4.

How do you create a list in Python?

a)

You create a list in Python using curly braces, e.g., my_list = {item1, item2, item3}.

b)

You create a list in Python using angle brackets, e.g., my_list = .

c)

You create a list in Python using square brackets, e.g., my_list = [item1, item2, item3].

d)

You create a list in Python using parentheses, e.g., my_list = (item1, item2, item3).

5.

What will be the output of the following code: print(type(5))?

a)

5

b)

int

c)

<class 'int'>

d)

None

6.

What is the difference between a local variable and a global variable?

a)

Local variables persist for the entire program, whereas global variables are temporary.

b)

Local variables are scoped to their function, while global variables are accessible throughout the program.

c)

Local variables can be accessed globally, while global variables are limited to their function.

d)

Local variables are defined outside functions, while global variables are defined inside functions.

7.

How do you define a function that takes two parameters in Python?

a)

my_function(param1; param2)

b)

def my_function(param1, param2, param3):

c)

def my_function(param1, param2):

d)

function my_function(param1, param2)

8.

Which library would you use to perform mathematical operations in Python?

a)

numpy

b)

pandas

c)

math

d)

scipy

9.

What is the correct way to handle exceptions in Python?

a)

Implement error handling with switch cases.

b)

Use if-else statements to manage errors.

c)

Use try-except blocks to handle exceptions.

d)

Ignore exceptions and let the program crash.

10.

What data structure would you use to store key-value pairs in Python?

a)

dictionary

b)

tuple

c)

list

d)

set

11.

How do you concatenate two strings in Python?

a)

Use the '+' operator to concatenate strings.

b)

Use the '*' operator to join strings.

c)

Apply the 'concat()' method for strings.

d)

Utilize the '&' operator for string merging.

12.

What is the output of the expression: 3 * 'Python'?

a)

3 * Python

b)

PythonPythonPython

c)

Python3Python

d)

PythonPython3

13.

How can you import the 'math' library in Python?

a)

require math

b)

import mathlib

c)

import math

d)

include math

14.

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

a)

The 'return' statement is used to define a function's parameters.

b)

The 'return' statement ends the execution of a program entirely.

c)

The 'return' statement is for printing output to the console.

d)

The purpose of the 'return' statement is to provide a value from a function to its caller.

15.

Which of the following is a mutable data type in Python?

a)

tuple

b)

list

c)

set

d)

frozenset

16.

How do you access the first element of a list named 'my_list'?

a)

my_list[0]

b)

my_list.first()

c)

my_list.get(0)

d)

my_list(1)

17.

What will happen if you try to access a variable that has not been defined?

a)

The variable is initialized to zero.

b)

The program will terminate.

c)

A reference error is raised.

d)

A syntax error is raised.

18.

How do you create a dictionary in Python?

a)

A dictionary in Python is created with parentheses, for example: my_dict = ('key1', 'value1', 'key2', 'value2').

b)

You can create a dictionary in Python using curly braces, like this: my_dict = {'key1': 'value1', 'key2': 'value2'}.

c)

You can create a dictionary in Python using square brackets, like this: my_dict = ['key1': 'value1', 'key2': 'value2'].

d)

To create a dictionary in Python, use a list, like this: my_dict = ['key1', 'value1', 'key2', 'value2'].

19.

What is the output of the following code: print(10 / 2)?

a)

10 / 2

b)

5.0

c)

10

d)

5

20.

How can you check the length of a list in Python?

a)

size(my_list)

b)

count(my_list)

c)

length(my_list)

d)

len(my_list)

21.

What method would you use to remove an item from a list in Python?

a)

my_list.pop(item)

b)

my_list.erase(item)

c)

delete(my_list, item)

d)

my_list.remove(item)

22.

How can you check if a key exists in a dictionary in Python?

a)

key in my_dict

b)

my_dict.has_key(key)

c)

key.exists(my_dict)

d)

my_dict.contains(key)

23.

What is the output of the following code: print('Hello' + ' ' + 'World!')?

a)

HelloWorld!

b)

Hello + World!

c)

None

d)

Hello World!

24.

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

a)

my_set = [1, 2, 3]

b)

my_set = {1, 2, 3}

c)

my_set = (1, 2, 3)

d)

my_set = <1, 2, 3>

25.

How do you convert a string to an integer in Python?

a)

int('123')

b)

str(123)

c)

convert('123')

d)

integer('123')

26.

What is the output of the following code: print(2 ** 3)?

a)

2

b)

9

c)

6

d)

8

27.

How do you create a tuple in Python?

a)

You create a tuple using square brackets, e.g., my_tuple = [item1, item2].

b)

You create a tuple using parentheses, e.g., my_tuple = (item1, item2).

c)

You create a tuple using curly braces, e.g., my_tuple = {item1, item2}.

d)

You create a tuple using angle brackets, e.g., my_tuple = .

28.

How do you add an item to the end of a list in Python?

a)

my_list.add(item)

b)

my_list.push(item)

c)

my_list.insert(item)

d)

my_list.append(item)

29.

What is the correct way to define a class in Python?

a)

MyClass class:

b)

define MyClass:

c)

class MyClass:

d)

class: MyClass

30.

How do you remove the last item from a list in Python?

a)

my_list.delete()

b)

my_list.pop()

c)

my_list.remove_last()

d)

my_list.erase()