a = 1+3jcomplex(str(a))Why does this not work ? It should 解决方案Says who?By normal conventions in Python, "str" attempts only to make a "nice"human readable representation. The function "repr" is usually expectedto provide output that can be parsed back into the original object.(Although for the numeric complex type the two produce identical results.)Further, constructors are rarely expected to parse a stringrepresentation to return an object. The function "eval" is usuallyexpected to provide that functionality.So, putting them together, you could expecteval(repr(a))to reproduce a, and in fact it does so.Gary Herron 这篇关于复杂的评估错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-28 21:15