Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Mastering Python: Data Types & Functions

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

What is the data type of the variable `x` in the following Python code snippet? ```python x = 3.14 ```

a)

int

b)

float

c)

str

d)

bool

2.

Which of the following is a valid way to define a function in Python?

a)

`def my_function:`

b)

`function my_function()`

c)

`def my_function():`

d)

`my_function() = function`

3.

What will be the output of the following code? ```python x = "Hello" y = "World" z = x + " " + y print(z) ```

a)

`HelloWorld`

b)

`Hello World`

c)

`Hello, World`

d)

`World Hello`

4.

Which of the following is NOT a built-in data type in Python?

a)

list

b)

tuple

c)

array

d)

dict

5.

What is the output of the following code? ```python def add(a, b): return a + b result = add(3, 4) print(result) ```

a)

7

b)

34

c)

`add(3, 4)`

d)

None

6.

Which of the following statements is used to import a module in Python?

a)

`import module_name`

b)

`include module_name`

c)

`require module_name`

d)

`using module_name`

7.

What is the result of the following expression in Python? ```python 5 // 2 ```

a)

2.5

b)

2

c)

3

d)

2.0

8.

Which of the following is the correct way to access the value associated with the key `'name'` in a dictionary `person`? ```python person = {'name': 'Alice', 'age': 25} ```

a)

`person.name`

b)

`person['name']`

c)

`person(name)`

d)

`person->name`

9.

What will be the output of the following code? ```python def multiply(x, y=2): return x * y result = multiply(5) print(result) ```

a)

10

b)

5

c)

25

d)

Error

10.

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

a)

tuple

b)

string

c)

list

d)

int