In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article shows you what is the difference between "is" and "=" in Python. The content is concise and easy to understand, which will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
The way Python defines variables is much simpler than strongly typed languages such as CCharpy Cure + and Java. We just need to give a variable name to the variable, not a type to the variable.
Because Python weakens the concept of types, we can assign values to variables at will. Values can be integers, floating-point numbers, strings, lists, etc.
A = 1
A = 3.33
A = 'monkey'
A = [1, 2, 3]
Everything has its pros and cons. Using weakly typed language programming, we don't need to define variable types, we can convert types at will, and the code looks very brief. However, it will cause us some confusion when judging whether the variables are equal or not.
The judgment value is equal. Did you choose "is" or "="?
When you understand the language features of Python, this problem will be easily solved. In Python, everything is an object. Each object has three properties. They are: id,type,value.
Id is the memory address of the object, and you can view the address referenced by the object through the built-in function id ().
Type represents the type of object. Python also has the concept of type. For the compiler or interpreter, the type can help ensure that the above charges and bytes are consistently understood during the run of the program. We can see the type of the object through the built-in function type ().
Value is the value of the object.
To sum up:
If we want to determine whether the values of two variables are equal, we need to use "=". It is generally used to determine whether a numeric value and a string are equal.
A = '123'
B = '123'
Print (aquib)
> > True
C = 1
D = 2
Print (caterpillar)
> > False
Is is used to determine whether the id of two variables is equal. When the id of two variables is equal, it means that the address that the two variables point to is the same, then all the attributes (including: type, value) of the two variables are the same. At the same time, Python also specifies that None, False, empty string "", 0, empty list [], empty dictionary {}, empty tuple () are all equivalent to False. So we can use is to determine whether the variable is empty or not.
Str = ""
Print (str is None)
> > False
Print (str is not None)
> > True
What is the difference between "is" and "=" in Python? have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.