class Good():
def __init__(self):
self.original=100
self.discount = 0.8
@property
def price(self):
new_price=self.original*self.discount
return new_price
@price.setter
def price(self,value):
self.original=value
@price.deleter
def price(self,value):
del self.original
def __del__(self):
pass
def __call__(self, *args, **kwargs):
pass
# obj=Good()
# print(obj.price)
# obj.price = 200
# # del obj.price
# print(obj.price)
'''
1.__doc__:类的描述信息
2.__module__:当前操作的对象在哪个模块
3.__class__:当前操作的类是什么
4.__call__:对象后面加括号,触发执行
5.__dict__:类或对象中的所有成员
6.__getitem__,__setitem__,__delitem__:用于索引操作,如字典。以上分别获取、设置、删除数据
7.__del__:析构方法,当对象在内存中被释放时,自动触发执行。可以写一些,数据库或是文件的关闭操作
8.__iter__:用于迭代器,之所以列表、字典、元祖可以进行for循环,是因为类型内部定义了__iter__
'''
from copy文件 import A
class C:
'''去年买个包'''
def __init__(self):
self.name='dog'
def __call__(self, *args, **kwargs):
print('__call__')
a=A()
c=C()
C()()#执行call方法
print(c.__doc__)#去年买个包
print(C.__module__)#__main__
print(a.__module__)#copy文件
print(c.__class__)#<class '__main__.C'>
print(a.__class__)#<class 'copy文件.A'>
print(a.__dict__)#{}
print(c.__dict__)#{'name': 'dog'}
# s=str(123).__iter__()
# print(s.__next__)
def my_range(bound):
for i in range(bound):
return i
a=my_range(100)