码迷,mamicode.com
首页 > 编程语言 > 详细

Python基础指随笔

时间:2019-02-26 13:46:18      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:print   def   erro   recent   std   cal   function   class   ror   

>>> 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基础指随笔

标签:print   def   erro   recent   std   cal   function   class   ror   

原文地址:https://www.cnblogs.com/Mengchangxin/p/10436529.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!