Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

An is b is True,a = = b must be True?

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces "an is b is True,a = b must be True". In daily operation, I believe that many people have doubts on the question that an is b is True,a = = b must be True. The editor consulted all kinds of materials and sorted out a simple and easy-to-use method of operation. I hope it will be helpful to answer the doubt that "an is b is True,a = = b must be True"! Next, please follow the editor to study!

When we use Python on a daily basis, you may have the following understanding:

A = = b is True,an is b may not be True

If an is b is True, then a = = b must be True

> a = 'ABCs' > b = 'abcesses' > a = = b True > an is b False > c = a > an is c True > a = = c True

This is because = = only compares values, while is compares both values and memory addresses. To put it simply: there is a person on your left hand and a person on your right hand, and two people look exactly the same, so the person on the left hand = = the person on the right hand; there is a person on your left hand, and this person walks to your right hand a minute later, so the person on the left hand is is now the person on the right hand.

But there is always an accident, the following code:

Why is this happening? an is b is True,a = = b but False.

You can stop here and guess what the values in an and b are.

Now to uncover the answer, let's take a look at two lines online:

The values of an and b are nan, which means Not a Number, not a number.

Nan compares with any number, including itself, and the result is False, which is specified by IEEE-754:

When Python implements this data, it also makes restrictions according to the requirements of IEEE-754:

At this point, the study of "an is b is True,a = b must be True" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report