Python Class
来源:互联网 发布:蚁群算法解决背包问题 编辑:程序博客网 时间:2024/05/16 11:47
class A(object): def __init__(self): self.x = 'Hello' def method_a(self, foo): print self.x + ' ' + foo
... the self
variable represents the instance of the object itself. Most object-oriented languages pass this as a hidden parameter to the methods defined on an object; Python does not. You have to declare it explicitly. When you create an instance of the A
class and call its methods, it will be passed automatically, as in ...
a = A() # We do not pass any argument to the __init__ methoda.method_a('Sailor!') # We only pass a single argument
The __init__
method is roughly what represents a constructor in Python. When you call A()
Python creates an object for you, and passes it as the first parameter to the __init__
method. Any additional parameters (e.g., A(24, 'Hello')
) will also get passed as arguments--in this case causing an exception to be raised, since the constructor isn't expecting them.
- python class
- Python Class
- Python Class
- Python - class
- Python class
- python Class
- python-class
- Python Class
- <python>class
- Python-Class
- python object and class
- python.struct helper class
- python Object And Class
- Python[十四]:Class
- 菜鸟学 Python-Class
- python class属性
- python class 用法
- python class 的属性
- android之layout_weight体验(实现按比例显示)
- Data Structure
- void
- linux批量备份服务器配置文件和目录的脚本
- Bash Shell中Shift用法分享
- Python Class
- Object-oriented features
- javaScript学习之路:document对象
- PHP中fwrite与file_put_contents性能测试代码
- Android入门前言(一)之------Android应用开发入门五问
- mysql 不等于 符号写法
- Bash的For循环(根据每次递增的数)
- Android入门教程(二)之------环境搭建
- shift妙用之解决shell编程中的入参问题