+ 1
How do 'is statement' work?
a=[1,2,3] b=[1,2,3] Print(a is b) Why it false??
8 Antworten
+ 6
is’ operator – Evaluates to true if the variables on either side of the operator point to the same object and false otherwise.
Here is an example
a = [1,2,3]
b = a
print(a is b)
#both variables point to the same object.
#You example above does not point to the same object Hasan Zakaria Tahhan
+ 2
Ravi Kiran
I search and find more information,
a=[1,2,3]
b=a
b[2]=5
Print(a) ==> [1,2,5]
If we need to copy list from variable to another
We can use copy method
b=a.copy()
b[2]=5
Print(a) ==> [1,2,3]
+ 1
It Outputs true
+ 1
MATOVU CALEB
Thanks a lot
0
MATOVU CALEB
This give true ?
0
Thank U Hassan Zakaria Tahhan
today I learnt new thing from ur question.
0
Good
0
Is statement simply check the memory location.
That means if a and b are similar the (is) statement will print false
But if a and b are from same memory location then (is) statement will print true.