Python Programming - Tricky Questions

Exercise : Tricky Questions - General Questions
  • Tricky Questions - General Questions
21.
What is the purpose of the is keyword in Python?
It is used to compare values for equality.
It is used to compare object identity.
It is used to create instances of a class.
It is used to define conditional statements.
Answer: Option
Explanation:
The is keyword checks if two objects refer to the same memory location.

22.
What is the output of the following Python code?
def some_function(x, y, z):
    return x + y ** z

result = some_function(x=1, y=2, z=3)
print(result)
9
7
8
1
Answer: Option
Explanation:
The exponent has higher precedence than addition, so the result is 1 + (2 ** 3) = 9.

23.
What is the output of the following Python code?
x = 5
y = 2
result = x / y
print(result)
2.5
2
2.0
This code will result in an error.
Answer: Option
Explanation:
Division (/) in Python 3 returns a floating-point result.

24.
What will be the output of the following Python code?
string1 = "Python"
string2 = "Python"
result = string1 is string2
print(result)
True
False
This code will result in an error.
Undefined
Answer: Option
Explanation:
String interning in Python makes identical string literals refer to the same memory location.

25.
What will be the output of the following Python code?
def func(x):
    x += 1
    return x

x = 5
result = func(x)
print(x, result)
5 6
6 6
5 5
This code will result in an error.
Answer: Option
Explanation:
The function modifies its local copy of x, and the global x remains unchanged.