标签:class __init__ 方式 spl ide style 多次 asa hide
生成器:
yield的功能:
1:与return类似,都可以返回值,不一样的地方,return可以返回多次值
2:为函数封装好了__iter__和__next__方法,把函数的执行结果做成迭代器
3:遵循迭代器的取值方式obj.__next__(),触发的函数的执行,函数暂停
已字符串的形式获取对象的属性
class Teacher: school=‘oldboy‘ def __init__(self,name,age): self.name=name self.age=age def teach(self): print(‘%s teach‘ %self.name) t=Teacher(‘egon‘,18) print(hasattr(t,‘name‘)) print(getattr(t,‘name‘)) setattr(t,‘sex‘,‘male‘) print(getattr(t,‘sex‘))
标签:class __init__ 方式 spl ide style 多次 asa hide
原文地址:https://www.cnblogs.com/lxltxdy/p/8098795.html