Python基础指随笔
Posted 独孤_败天
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python基础指随笔相关的知识,希望对你有一定的参考价值。
>>> def fn(): ... print("ok") ... >>> fn() ok >>> fn.s=123 >>> fn.s 123 >>> fn.ss Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: ‘function‘ object has no attribute ‘ss‘ >>> getattr(fn,"ss") Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: ‘function‘ object has no attribute ‘ss‘ >>> getattr(fn,"ss",2) 2 >>> b=getattr(fn,"sss",4) >>> b 4 >>>
以上是关于Python基础指随笔的主要内容,如果未能解决你的问题,请参考以下文章