Quiz 2: Operators in Python

Hi,
This is yashaswini from DS301222…
Attended quiz operators in python and got marks deduction for correct answer and the screenshots are attached for your reference…kindly check and do the needful.


2 Likes

@yashaswini.kgowda95 In official document of python they not specify that tuple store in heap of contiguous either it can be with same memory location either it can’t but mostly prefer answer False if you tried different IDE like jupyter notebook or sometime else then answer will be False if there was any other options like Not Specify then that was perfect answer for this

2 Likes

@yashaswini.kgowda95
As conceptually I know the answer for this question comes out to be False.
If you will check in some other iDEs like jupyter notebook, Google colab you will get answer as false.

1 Like

sir,please explain conceptually so that we can learn…
and Why in vs code is shows true and why false in other platforms?

1 Like

@thaseenraza1210
Please go through this once:

In the code , the “is” operator is used to check whether two variables refer to the same object in memory. In this case, even though the values of the tuples “a” and “b” are the same, they are two distinct objects in memory.

Therefore, the expression “a is b” will evaluate to False because “a” and “b” are two different tuples with the same values, so they are not the same object in memory.

If you want to check whether the values of two tuples are the same, you can use the “==” operator instead, like this:

a = (1, 2, 3)
b = (1, 2, 3)
print(a == b) # This will output True

This will compare the values of the two tuples, and return True if they have the same values in the same order.

Hope this will help.

1 Like