Hi Loay I agree with all but I want to add some to your comment, for avoiding a possible misunderstanding.
The case when we let
x = n
y = n
With n a number and not another variable (this is important), if our n is any integer between -5 and 256, so "x is y" returns true because they REALLY are the same object and will always have the same id for every number in there. But any other integer will return false for "x is y" because they will be different objects. Examples:
i = 256
j = 256
i is j
x = 257
y = 257
x is y
a = 300
b = a
a is b
(I know, that says "long" but the explanation is inside :P)
Plz if I have some mistake I'm very thankful if someone corrects me, keep coding!
Two similar pens.
Same color, same shape.
in other words
pen1 looks as same as pen2
But, when we broke pen1 is pen2 broken too???
Of course not!
So is pen1 the same pen as pen2?
They are different objects
Equal Values of two variables can't make them same.......
like age of A and age of B are equal but that doesn't mean that A and B are same person ....like this value of a and value of b are same but they are still having different identity (address).....so they're not same !!!
When we let
x = 1
y = 1
both x== y & x is y return true
as immutable objects in python
share the same memory
Like definig y as a reference for x in other languages but they are not a reference just when they share the same value memory management tends to link them to point to one shared address
x = 1, y= x
x = 3
y still equal to 1
To make that clear
(1, 2, 3) is (1, 2, 3) return true
But for list which is mutable each created list is nothing but a linkedList object have different pointers in memory blindly can't see other objects that share their same value but in other addresses
You can use id(x), id(y) that will help you see each object memory address
By human language, I think it can be translated as something like this:
I have two hands. `a = [1, 2, 3, 4]`
You have two hands. `b = [1, 2, 3, 4]`
We both have two hands. `a == b`
But my hands are not your hands. `a is not b`
Sebastián Zapata nothing is wrong with your comment but note, the OP is talking about a list so this condition will always return falsey and otherwise for integer.
a = n
b = n
a is b => false (for list irrespective of the range of each items in the list)
I am not here to add an answer but to address the downvoting on certain answers. I won't call you out directly, but will just say that you have 24 hours to either justify your downvotes, or remove them, or face an account ban.
EDIT: Accounts have been been banned associated with the downvoting
Think of a variable as a specific container where you put stuff in.
In blue container a that is shaped like a star you put 1,2,3,4 as integers in them.
In red container b that is shaped like a heart you put 1,2,3,4 as integers in them.
Now you show these containers other persons and ask them discribe both containers
They’ll answer. They look totally different. Then they open the container and say. Both are identical content wise (1,2,3,4).