NEW
Font size
WorksheetsUnderstanding Python Variables and Data Types
Total questions: 20
Worksheet time: 10mins
Which of the following is the correct way to assign an integer value to a variable in Python?
int x = 5
x = 5
x := 5
x == 5
What type of data will the variable `name` hold after the following assignment? `name = "Alice"`
Integer
Float
String
Boolean
Which of the following variables is a float in Python?
age = 17
price = 19.99
is_valid = True
city = "London"
Given the code `is_raining = False`, what is the data type of `is_raining`?
String
Integer
Boolean
List
Which of the following is a valid way to create a list in Python?
my_list = [1, 2, 3]
my_list = (1, 2, 3)
my_list = {1, 2, 3}
my_list = "1, 2, 3"
What will be the data type of the variable `result` after executing `result = 10 / 2` in Python?
Integer
Float
String
Boolean
Which of the following statements correctly assigns a string value to a variable?
name = "John"
name = 123
name = True
name = [1, 2, 3]
If you want to store multiple values of different data types together, which Python data type should you use?
List
Tuple
Dictionary
All of the above
Which of the following is NOT a built-in data type in Python?
Integer
Character
List
Dictionary
What is the output type of the following code? `type(3.14)`
dictionary
integer
float
string
Given the following code, what will be the value and type of `x` after execution? ```python x = "5" + "7" ```
12, Integer
57, Integer
57, String
12, String
You have the following variables: ```python a = 10 b = "10" ``` Which operation will result in a TypeError?
a + 5
b + "5"
a + b
b * 2
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?
List
Tuple
Set
Dictionary
Given the code: ```python data = [1, "two", 3.0, True] ``` What is the type of the variable `data` and what does it contain?
Tuple, contains only integers
List, contains mixed data types
Set, contains only strings
Dictionary, contains key-value pairs
If you want to associate a student's name with their grade, which data type is most appropriate?
List
Tuple
Dictionary
Set
What will be the output of the following code? ```python x = 5 y = 2.0 z = x + y print(type(z)) ```
`
`
`
`
You have a variable `x = [1, 2, 3]`. Which of the following statements will add the value 4 to the end of the list?
x.add(4)
x.append(4)
x.insert(4)
x[3] = 4
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?
List; adds a new element to the list
Dictionary; adds a new key-value pair
Tuple; changes the value of an element
Set; removes a value
Which of the following code snippets will result in a syntax error?
x = 10
y = "Hello"
2name = "Bob"
is_valid = True
You want to store the ages of 5 students. Which of the following is the most efficient way to do this in Python?
age1 = 16; age2 = 17; age3 = 16; age4 = 18; age5 = 17
ages = [16, 17, 16, 18, 17]
ages = "16, 17, 16, 18, 17"
ages = {16, 17, 18}
