In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "is Python a dynamic language?" the content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "is Python a dynamic language?"
The definition of dynamic language
Dynamic programming language is a category of high-level programming languages, which has been widely used in the field of computer science. It is a language that can change its structure at run time: for example, new functions, objects, and even code can be introduced, existing functions can be deleted, or other structural changes. Dynamic languages are very dynamic at present. For example, JavaScript is a dynamic language, in addition, such as PHP, Ruby, Python and so on are also dynamic languages, while C, C++ and other languages are not dynamic languages.
Bind (add) attributes to an object
Here, we define a class Car, in which we define two initial properties, Carname and CarMoney, but people still have gender! If you didn't write this class, would you try to access the gender attribute?
> C.user = "Technology Big Bang" > P.user' Technology Bang ">
At this time, we found that the problem is that there is no sex attribute in the class we defined. What's going on? This is the charm and pit of dynamic language! This is actually dynamically binding properties to the instance!
Bind (add) attributes to a class
We tried to print C1.user and found that C1 does not have the attribute user!-binding property to C does not work on C1! What if we add a user attribute to all instances of Car? The answer is to bind properties directly to Car!
# if there is no user attribute in C1 instance object, then its class property None will be accessed
# you can see that no exception occurred >
Bind (add) attributes to a class
We bind the attribute user directly to Car, and after re-instantiating C1, C1 has the attribute user! What about function? How to bind?
Since you add a method to a class, use the class name. Method name = xxxx, then adding a method to an object is a similar object. Method name = xxxx
The complete code is as follows:
Delete properties, methods
Method of deletion:
Del object. Property name delattr (object, property name)
From the above examples, we can draw a conclusion: compared with dynamic languages, static languages are rigorous! So, when playing with dynamic languages, beware of dynamic pitfalls!
So how to avoid this situation? Please use _ _ slots__
Thank you for your reading, the above is the content of "is Python a dynamic language?" after the study of this article, I believe you have a deeper understanding of the question of whether Python is a dynamic language, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.