Exam: Variables and Data Types
Instructions: Answer all questions. Each question tests your understanding of variables and
data types in programming.
1. What is a variable in programming?
Answer: A variable is a named storage that can hold a value which can be changed#$%^&*(
during
the execution of a program. *&^%
2. What are the common data types in Python?
Answer: Common data types in Python include int, float, str, bool, list, tuple, set, and dict.
3. What is the difference between an integer and a float?
Answer: An integer (int) is a whole number without a decimal point, while a float is a
number that includes a decimal point.
4. How do you declare a string variable in Python?
Answer: You declare a string variable by assigning a sequence of characters enclosed in
quotes to a variable. For example: name = 'Alice'
5. What is the output of the following code: x = 5; y = '5'; print(x + int(y))?
Answer: The output is 10. The string '5' is converted to an integer before addition.
6. What is a boolean data type and what values can it hold?
Answer: A boolean data type can hold only two values: True or False.
7. Explain the difference between a list and a tuple.
Answer: A list is mutable, meaning its elements can be changed, while a tuple is immutable
and cannot be changed after creation.
8. What will be the type of variable x if we write: x = 3.14?
Answer: The type of x will be float.
9. How can you find out the type of a variable in Python?
Answer: You can use the type() function. For example: type(x)
10. Can variable names start with a number in Python? Explain.
Answer: No, variable names cannot start with a number. They must begin with a letter or an
underscore.
Instructions: Answer all questions. Each question tests your understanding of variables and
data types in programming.
1. What is a variable in programming?
Answer: A variable is a named storage that can hold a value which can be changed#$%^&*(
during
the execution of a program. *&^%
2. What are the common data types in Python?
Answer: Common data types in Python include int, float, str, bool, list, tuple, set, and dict.
3. What is the difference between an integer and a float?
Answer: An integer (int) is a whole number without a decimal point, while a float is a
number that includes a decimal point.
4. How do you declare a string variable in Python?
Answer: You declare a string variable by assigning a sequence of characters enclosed in
quotes to a variable. For example: name = 'Alice'
5. What is the output of the following code: x = 5; y = '5'; print(x + int(y))?
Answer: The output is 10. The string '5' is converted to an integer before addition.
6. What is a boolean data type and what values can it hold?
Answer: A boolean data type can hold only two values: True or False.
7. Explain the difference between a list and a tuple.
Answer: A list is mutable, meaning its elements can be changed, while a tuple is immutable
and cannot be changed after creation.
8. What will be the type of variable x if we write: x = 3.14?
Answer: The type of x will be float.
9. How can you find out the type of a variable in Python?
Answer: You can use the type() function. For example: type(x)
10. Can variable names start with a number in Python? Explain.
Answer: No, variable names cannot start with a number. They must begin with a letter or an
underscore.