python self
2017-08-16 21:00
162 查看
首先明确的是self只有在类的方法中才会有,独立的函数或方法是不必带有self的。self在定义类的方法时是必须有的,虽然在调用时不必传入相应的参数。
__init__中self有一部分是从外面传来的参数,需要实例化时就传入
类中self带的参数相当于类的属性,没带的是局部变量,可能是类的局部变量,也可能是类中方法的局部变量。这些局部变量是不能通过实例去访问的,只有带self的参数即类的属性才可以访问。
类中的方法,带self的是类方法,不带self是 。实例只能访问类中的类方法,不能访问这些其他函数。
在一个类中定义函数时,如果你要使用另外一个函数或者另外一个函数中的参数,都必须带self,即类方法或者属性,当然还可以是一个全局的局部变量
相关文章推荐
- simple dynamic web server with self defined framework (python)
- Python中:self和__init__的含义 + 为何要有self和__init__
- python 参数列表中的self 显式不等于冗余
- Python 爬虫 raise self._value IndexError: list index out of range
- Python要self的理由
- Python魔术师--self
- 如何理解Python的web框架tornado文档里面的用户认证的self.current_user?
- python的类中为什么要引入self
- python中的self
- python self 问题
- Python Class System,Python self,面向对象和过程的一致性
- python self,cls,decorator的理解
- python 函数 之 self
- Self Describing Numbers自描述数字问题(Python版)
- Python-self
- Python:XXX missing X required positional argument: 'self'
- 深入理解python之self
- python之self
- Python 方法中变量加self和不加的区别
- 理解python中的self