python定义类的操作符__plus__示例,python__plus_,class adder:
文章由Byrx.net分享于2019-03-23 07:03:42
python定义类的操作符__plus__示例,python__plus_,class adder:
class adder: def __init__(self, value=0): self.data = value # initialize data def __add__(self, other): self.data += other # add other in-placeclass addrepr(adder): # inherit __init__, __add__ def __repr__(self): # add string representation return 'addrepr(%s)' % self.data # convert to string as codex = addrepr(2) # runs __init__x + 1 # runs __add__print x # runs __repr__addrepr(3)print x # runs __repr__addrepr(3) print str(x), repr(x) # run ___repr__
相关内容
- python的类和对象,python对象,# Demonstrat
- __getattr__ demo,__getattr_demo,class empty:
- python实现连接两个url,python实现url,import urlpa
- dns反向解析,根据ip获得域名方法,dns域名,import sys,
- Virtual function in Python,virtualpython,class Super:
- python的iterator object,pythoniterator,class Square
- python获得系统中所有的挂载点,python获得系统挂载,#
- Class method: __init__ and __call__,__init___call_,class Prod:
- Python调用system命令,python调用system,import osos.
- python http上传文件处理示例,python上传文件,<HTML>
评论关闭