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
>>>

  

猜你喜欢

转载自www.cnblogs.com/Mengchangxin/p/10436529.html
今日推荐