Python对class的理解
来源:互联网 发布:mac如何切换中文输入法 编辑:程序博客网 时间:2024/04/29 23:51
我把class分为两类,一类是不带init 方法的类。具体给例子:
class Greeter(): def greet(name): print( 'Hello, %s' % (name.upper() ) )g = Greeter # Construct an instance of the Greeter classg.greet('fred') # Call an instance method; prints "Hello, Fred"
一类是带有init方法的类:
class Greeter(object): # Constructor def __init__(self, name): self.name = name # Create an instance variable # Instance method def greet(self, loud=False): if loud: print 'HELLO, %s!' % self.name.upper() else: print 'Hello, %s' % self.nameg = Greeter('Fred') # Construct an instance of the Greeter classg.greet() # Call an instance method; prints "Hello, Fred"g.greet(loud=True) # Call an instance method; prints "HELLO, FRED!"
自行体会两种区别
阅读全文
1 0
- Python对class的理解
- 对.Class的一点理解
- 对java.lang.Class类的理解
- 对jvm卸载class条件的理解
- 对Python生成器的理解
- 个人对泛型Class<T>的理解
- 面向对象 —— 对类(class)的理解
- 对python元类概念的理解
- 对python的正则表达式一点理解
- [python]对self和_init_的理解
- 我对python线程池的理解
- 对Python面向对象的理解
- 对 Python 装饰器的理解心得
- 对python装饰器的理解
- python 对工厂函数的理解
- 个人对python装饰器的理解
- 对Python协程的理解
- python学习过程对self的理解
- Android Notification 详解
- Mybatis集成Redis
- redis安装流程
- HDU 1078 FatMouse and Cheese(动态规划)
- IntelliJ IDEA快捷键
- Python对class的理解
- 中兴招聘点击登录页面 显示服务器已断开链接,且未发送任何数据
- linux 常用基本命令 cd
- 各种类型字符之间的转换(单字节char*和宽字节wchar_t*,TCHAR和string的转换)
- 90后消费新势力崛起 企业营销转向“移动门户”
- Deep learning 词向量
- appium iOS WebDriverAgent安装时注意(解决appium 报错code 65)
- 01_https和http的区别
- EnumProcessThread(枚举进程线程)