Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
319 views
in Technique[技术] by (71.8m points)

an irregular anomaly in python tuple

i create two identical tuples and use is operator on them the answer that should come is false but when i use it in vscode/atom/notepadd++ it comes true but when i use the same code in pthon run through cmd it comes false

a = (1,2,3)
b = (1,2,3)

print(a is b)

actual result should be false and it is false when i use python through cmd or some online python compiler but when i used vscode to write the above code and create a .py file it comes true. The following picture shows what i am trying to say.

My code in vscode and executed through terminal and directly in terminal:

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I checked it in linux terminal result is False. It is because a is b will become True when a and b are pointing to same object. is does not compare values of the tuples. If you define b=a then you will get True. You can check this discussion Python "is" statement: what is happening?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...