Python Interview Questions
Python - Expressions & Variables
|1. What is the result of the following code segment: 1/2
C) - 0.5
Explanation: a / corresponds to regular division
|2. What is the value of x after the following lines of code:
Explanation: The value x=x+2 changes the value of x, if x is assigned to its self. It's helpful to replace the value of x with its current value in this case 2 or x=2+2.
|3. What is the result of the following operation 3+2*2?
Explanation: Python follows the standard mathematical conventions
|4. In Python 3, what is the type of the variable x after the following: x=2/2
Explanation: In Python 3, regular division always results in a float
|5. Data that is assigned a name is called what?
A) Data type
|6. A variable name can start with what 2 characters?
A) A letter or underscore
B) A letter or number
C) A upper or lowercase letter
Answer: A letter or underscore
|7. Is the following valid Python code:
i_am_string = "hello world"
i_am_string = 73
i_am_string = True
Explanation: Python is dynamically typed, meaning that variables can change type!
|8. True or False: Variables must be assigned before they can be used.
|9. Variables can be:
A) assigned to other variables
B) reassigned at any time
C) assigned at the same time as other variables
D) all of the above
Answer: all of the above
|10. Is 24hrs a valid variable name?
Explanation: Variables can't start with a number in Python.
|11. Is my_1st_variable a valid variable name?
Explanation: Numbers can be used as long as they aren't at the beginning.
|12. Python programmers prefer to name most variables using...