wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python Programming Basics

Total questions: 20

Worksheet time: 10mins

Name
Class
Date
1.

What is a variable in Python?

a)

A variable in Python is a type of function.

b)

A variable in Python is a named reference to a value stored in memory.

c)

A variable in Python is a fixed value that cannot change.

d)

A variable in Python is a command used to execute code.

2.

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

a)

string

b)

boolean

c)

float

d)

int

3.

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

a)

16

b)

11

c)

8

d)

10

4.

How do you create a function in Python?

a)

function function_name(parameters) {}

b)

function_name = (parameters) => {}

c)

create function_name(parameters):

d)

def function_name(parameters): # function body

5.

What keyword is used to define a function?

a)

procedure

b)

def

c)

function

d)

method

6.

What is the purpose of the 'if' statement in Python?

a)

To execute code conditionally based on a boolean expression.

b)

To define a function in Python.

c)

To import modules in Python.

d)

To create a loop in Python.

7.

How do you create a list in Python?

a)

You create a list in Python by using the list() function, e.g., my_list = list(1, 2, 3).

b)

You create a list in Python using square brackets, e.g., my_list = [1, 2, 3].

c)

You create a list in Python using curly braces, e.g., my_list = {1, 2, 3}.

d)

You create a list in Python using parentheses, e.g., my_list = (1, 2, 3).

8.

What is the difference between a list and a tuple?

a)

A list can only contain numbers, while a tuple can contain any data type.

b)

A list is immutable and defined with [], while a tuple is mutable and defined with ().

c)

A list is defined with {}, while a tuple is defined with []

d)

A list is mutable and defined with [], while a tuple is immutable and defined with ().

9.

How do you access the first element of a list?

a)

my_list.first()

b)

my_list[0]

c)

my_list(1)

d)

first(my_list)

10.

What operator is used for exponentiation in Python?

a)

^

b)

**-

c)

**/

d)

**

11.

How do you concatenate two strings in Python?

a)

Use the '*' operator to concatenate strings.

b)

Use the 'concat()' method to join strings.

c)

Use the '+' operator to concatenate strings.

d)

Use the '&' operator to combine strings.

12.

What method would you use to add a key-value pair to a dictionary?

a)

dictionary.insert(key, value)

b)

dictionary.put(key, value)

c)

dictionary.add(key, value)

d)

dictionary[key] = value

13.

How do you create a set in Python?

a)

You can create a set using square brackets []

b)

You can create a set in Python using curly braces {} or the set() function.

c)

Sets can only be created with the list() function

d)

You must use the dict() function to create a set

14.

What is the output of len('Hello')?

a)

5

b)

4

c)

Hello

d)

6

15.

How do you import a module in Python?

a)

include module_name

b)

require module_name

c)

import module_name

d)

load module_name

16.

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

a)

To create a loop within the function.

b)

To end the function execution immediately.

c)

To define the function's parameters.

d)

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

17.

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

a)

Check the length of the dictionary to see if the key exists.

b)

Use 'dictionary.key' to access the value directly.

c)

Iterate through the dictionary and compare each key.

d)

Use 'key in dictionary' or 'dictionary.get(key)'.

18.

What is the result of the expression 'Hello' * 3?

a)

Hello3

b)

HelloHelloHello

c)

3Hello

d)

HelloHello

19.

How do you remove an item from a list?

a)

list.clear() to remove all items from a list.

b)

list.delete(index) removes an item from a list.

c)

Use list.add(value) to insert an item into a list.

d)

Use list.remove(value) or list.pop(index) to remove an item from a list.

20.

What is the difference between mutable and immutable types in Python?

a)

Mutable types include only strings and tuples, while immutable types include lists and dictionaries.

b)

Mutable types can be changed (e.g., lists, dictionaries), while immutable types cannot be changed (e.g., strings, tuples).

c)

Both mutable and immutable types can be changed at any time.

d)

Mutable types cannot be changed, while immutable types can be changed.