True or false: In Python, a variable name can refer first to an integer and later to a string without declaring a new variable type.
2 Variables and Data Types Online Quiz Questions
Use this free practice quiz with 20 questions to review 2 Variables and Data Types, test your knowledge, and prepare for your next test or exam.
Which proposed Python name is valid and can be used as an ordinary identifier?
- A
2nd_place
- B
place_2
- C
place-two
- D
class
What Python type does the expression 17 / 2 produce?
What is the value of 17 // 5 in Python?
- A
2
- B
3
- C
3.4
- D
4
True or false: In Python, int(-7.9) returns -8 because the value is rounded to the nearest integer.
- A
True
- B
False
What integer does len("Python") return?
Select all operations that are supported for Python strings.
- A
"Py" + "thon" - B
"ha" * 3 - C
word[0] = "p" - D
word[1:4]
Select all values that Python treats as false in a Boolean context.
- A
False - B
None - C
"0" - D
0 - E
""
Given the Python statements width = 8, height = 5, and area = width * height, what value does area refer to?
- A
40
- B
13
- C
35
- D
85
True or false: In Python, int(7.9) evaluates to 7.
- A
True
- B
False
Which expression correctly reads an age from the user and converts it to an integer so that next_year = age + 1 can be calculated?
- A
int(input("Enter your age: ")) - B
float(input("Enter your age: ")) - C
str(input("Enter your age: ")) - D
bool(input("Enter your age: "))
What integer value does the Python expression 17 // 2 produce?
Which of the following can be used as an ordinary Python variable name?
- A
student_name - B
2students - C
class - D
total-cost
Which single Python operator produces the remainder after integer division?
What value does result refer to after this code runs?
result = "" or "guest"
- A
"" - B
"guest" - C
False - D
None
What string does word[1:4] produce when word = "Python"?
- A
"Pyt" - B
"yth" - C
"thon" - D
"Python"
Which expression evaluates as false when used in a Python Boolean context?
- A
0 - B
1 - C
" " - D
"Python"
Complete both blanks: A programmer wants to exchange the values of x and y without a temporary variable. The statements x, y = y, x work because Python evaluates the right-hand side before assigning the new values. A sequential approach such as x = y; y = x fails because . The comma-separated assignment used to exchange the values is called .
Complete both blanks: Given count = 3, the augmented assignment that increases count by one is . After that statement executes, the value of count is .
Explain the difference between score = 100 and score == 100 in Python. Include what each expression does and what kind of result the comparison produces.