如果变量的类型仍未定义,'':'''表现为 就像''=''。它可能会在未来的代码中造成混乱,但不会破坏旧代码。 我认为这将是一个很好的功能。评论? 谢谢, - Rim 6 In reality, := would just coerce the return type of the RHS of := tothe type of the variable on the LHS of the :=, preserving the value(s)as best as it can. If the type of the variable was still undefined, '':='' would behavelike ''=''. It might create confusion in future code, but does not breakold code. I think it would be a nice feature to have. Comments? Thanks,- Rim推荐答案 分配是一种陈述,而不是一个操作员,因此不会超过。这是一个故意的设计决定,GvR将不会改变。 TJR Assignment is a statement, not an operator, and therefore notoverloadable . This is an intentional design decision that GvR willnot change. TJR 使用属性。更改赋值的语义 语句(NOT赋值运算符)不会发生。 属性是Python 2.2中的新特性(大约一年) 现在很老了。)它们让你有一个getter和setter 方法,其接口看起来像一个实例 变量。 /> John Roth Use a property. Changing the semantics of the assignmentstatement (NOT assignment operator) is not going to happen. Properties are new in Python 2.2 (which is around a yearold by now.) They enable you to have getter and settermethods with an interface that looks like an instancevariable. John Roth 作业是一个陈述,而不是操作员,因此不会过载。这是一个故意的设计决定,GvR将不会改变。 Assignment is a statement, not an operator, and therefore not overloadable . This is an intentional design decision that GvR will not change. 那么,提供另一个声明的想法是什么呢,我是原帖中建议? ''=''语句指定类型和值 '':=''语句仅指定值 Rim Well, what about the idea of providing another statement, the one Iproposed in the original post? ''='' statement assigns type and value'':='' statement assigns value only Rim 这篇关于建议重载assign运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-28 19:37