[英]When does Python do automatic type conversion?
When does Python do automatic type conversion? Python何时进行自动类型转换?
-- -
Update: 更新:
I asked this after reading this post: In praise of Go or : "Why I moved from Python and C++ to Go" . 在阅读这篇文章后,我问了这个问题: 赞美Go或:“为什么我从Python和C ++转到Go” 。 The one of the points the poster makes is that: 张贴者指出的要点之一是:
- It is statically typed, so it is more explicit and the code of a third party is more readable. 它是静态类型的,因此它更明确,并且第三方代码更易读。 Also it eliminates the risk of unwanted automatic type conversions (unlike Python). 而且,它消除了不必要的自动类型转换的风险(与Python不同)。
I had no idea what he meant by "unwanted automatic type conversions". 我不知道他所说的“不需要的自动类型转换”是什么意思。 Now, I think he's talking about implicit numeric conversions . 现在,我认为他正在谈论隐式数值转换 。 Of course, Python has these as 1.0 + 2
will convert 2
to 2.0
and return 3.0
. 当然,Python具有这些,因为1.0 + 2
会将2
转换为2.0
并返回3.0
。
It doesn't - it has duck typing instead. 它不是-它有鸭子输入 。
(I may have misunderstood what you meant by automatic type conversion, though, so it would help if you give more detail in your question.) (不过,我可能会误解了自动类型转换的含义,因此,如果您在问题中提供更多详细信息,这将有所帮助。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.