wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Understanding Python Variables and Data Types

Total questions: 20

Worksheet time: 10mins

Name
Class
Date
1.

Which of the following is the correct way to assign an integer value to a variable in Python?

a)

int x = 5

b)

x = 5

c)

x := 5

d)

x == 5

2.

What type of data will the variable `name` hold after the following assignment? `name = "Alice"`

a)

Integer

b)

Float

c)

String

d)

Boolean

3.

Which of the following variables is a float in Python?

a)

age = 17

b)

price = 19.99

c)

is_valid = True

d)

city = "London"

4.

Given the code `is_raining = False`, what is the data type of `is_raining`?

a)

String

b)

Integer

c)

Boolean

d)

List

5.

Which of the following is a valid way to create a list in Python?

a)

my_list = [1, 2, 3]

b)

my_list = (1, 2, 3)

c)

my_list = {1, 2, 3}

d)

my_list = "1, 2, 3"

6.

What will be the data type of the variable `result` after executing `result = 10 / 2` in Python?

a)

Integer

b)

Float

c)

String

d)

Boolean

7.

Which of the following statements correctly assigns a string value to a variable?

a)

name = "John"

b)

name = 123

c)

name = True

d)

name = [1, 2, 3]

8.

If you want to store multiple values of different data types together, which Python data type should you use?

a)

List

b)

Tuple

c)

Dictionary

d)

All of the above

9.

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

a)

Integer

b)

Character

c)

List

d)

Dictionary

10.

What is the output type of the following code? `type(3.14)`

a)

dictionary

b)

integer

c)

float

d)

string

11.

Given the following code, what will be the value and type of `x` after execution? ```python x = "5" + "7" ```

a)

12, Integer

b)

57, Integer

c)

57, String

d)

12, String

12.

You have the following variables: ```python a = 10 b = "10" ``` Which operation will result in a TypeError?

a)

a + 5

b)

b + "5"

c)

a + b

d)

b * 2

13.

Suppose you want to store the names of students in a class and ensure that no name is repeated. Which data type should you use?

a)

List

b)

Tuple

c)

Set

d)

Dictionary

14.

Given the code: ```python data = [1, "two", 3.0, True] ``` What is the type of the variable `data` and what does it contain?

a)

Tuple, contains only integers

b)

List, contains mixed data types

c)

Set, contains only strings

d)

Dictionary, contains key-value pairs

15.

If you want to associate a student's name with their grade, which data type is most appropriate?

a)

List

b)

Tuple

c)

Dictionary

d)

Set

16.

What will be the output of the following code? ```python x = 5 y = 2.0 z = x + y print(type(z)) ```

a)

``

b)

``

c)

``

d)

``

17.

You have a variable `x = [1, 2, 3]`. Which of the following statements will add the value 4 to the end of the list?

a)

x.add(4)

b)

x.append(4)

c)

x.insert(4)

d)

x[3] = 4

18.

Given the following code: ```python student = {"name": "Alice", "age": 17} student["grade"] = "A" ``` What is the data type of `student` and what does the last line do?

a)

List; adds a new element to the list

b)

Dictionary; adds a new key-value pair

c)

Tuple; changes the value of an element

d)

Set; removes a value

19.

Which of the following code snippets will result in a syntax error?

a)

x = 10

b)

y = "Hello"

c)

2name = "Bob"

d)

is_valid = True

20.

You want to store the ages of 5 students. Which of the following is the most efficient way to do this in Python?

a)

age1 = 16; age2 = 17; age3 = 16; age4 = 18; age5 = 17

b)

ages = [16, 17, 16, 18, 17]

c)

ages = "16, 17, 16, 18, 17"

d)

ages = {16, 17, 18}