Python Programming - Tricky Questions
Exercise : Tricky Questions - General Questions
- Tricky Questions - General Questions
31.
What is the output of the following Python code?
def modify_list(my_list):
my_list = [0, 1, 2]
original_list = [1, 2, 3]
modify_list(original_list)
print(original_list)
Answer: Option
Explanation:
The function reassigns
my_list
to a new list, but it does not modify the original list outside the function.
32.
What will be the output of the following Python code?
x = "Python"
y = x.lower()
z = x.upper()
result = y + z
print(result)
Answer: Option
Explanation:
The
lower()
method makes the string lowercase, and upper()
makes it uppercase.
33.
What is the output of the following Python code?
x = 3
y = 2
result = x ** y
print(result)
Answer: Option
Explanation:
The double asterisk (**) is the exponentiation operator, and 3 raised to the power of 2 is 9.
34.
What is the output of the following Python code?
x = [1, 2, 3]
y = x
y[0] = 10
print(x)
Answer: Option
Explanation:
y
is assigned a reference to the same list as x
, so modifying y
also modifies x
.
35.
What will be the output of the following Python code?
string1 = "Python"
string2 = string1
string2 += " is great"
result = string1 + string2
print(result)
Answer: Option
Explanation:
Immutable strings, when concatenated, create a new string.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers