码迷,mamicode.com
首页 > 编程语言 > 详细

Core Python | 2 - Core Python: Getting Started | 2.6 - Objects and Types | 2.6.4 - Python's Type System

时间:2021-03-08 13:34:24      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:com   when   while   objects   lazy   until   erro   img   because   

Programming languages can be distinguished by several characteristics, but one of the most important is the nature of their type system. Python could be characterized as having a dynamic and strong type system. Let‘s investigate what that means. Dynamic typing means the type of an object reference isn‘t resolved until the program is running, and needn‘t be specified up front when the program is written. Take a look at this simple function for adding two objects. Nowhere in this definition do we mention any types. We can use add with integers, floats, strings, or indeed any type for which the addition operator has been defined. These examples illustrate the dynamism of the type system. The two arguments, a and b, of the add function can reference any type of object. The strength of the type system can be demonstrated by attempting to add types for which addition has not been defined, such as strings and floats. This produces a type error, because python will not, in general, perform implicit conversions between object types, or otherwise attempt to coerce one type to another. The exception to this rule is the conversion of if statement and while loop predicates to bool.

技术图片

 

Core Python | 2 - Core Python: Getting Started | 2.6 - Objects and Types | 2.6.4 - Python's Type System

标签:com   when   while   objects   lazy   until   erro   img   because   

原文地址:https://www.cnblogs.com/hmlhml/p/14493452.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!