We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No description provided.
The text was updated successfully, but these errors were encountered:
面向对象
class Student(): name='' age=0 //构造函数 def __init__(self,name,age): self.name=name self.age=age def print(self): print('name:'+self.name) print('age:'+str(self.age)) //私有方法,只能从内部调用,不能从实例访问 def __prints(self): print('name:'+self.name) print('age:'+str(self.age)) //类方法 @classmethod def plus_sum(cls): pass //静态方法 @staticmethod def add(x,y): pass student=Student("石敢当","20") //实例化 student.print() // 调用类下面的方法
备注:
构造函数:当实例化的时候,构造函数自动被调用,当然他也是可以被显式调用
作用:根据实例化时候的参数,初始化类的值
实例变量和类变量
实例变量:和实例对象有关的(传入参数保存的变量,在构造函数中通过self对变量进行保存)
类变量:类下面的变量
通过类去访问变量,获取的是类变量的数据
通过实例化对象去访问变量,获取的是实例变量的数据
实例方法
实例方法:和实例对象(含有self)相关的方法
实例方法中操作类变量:
通过类名直接访问变量: 方法一:Student.name 方法二:self.__class__.name
继承性
Sorry, something went wrong.
No branches or pull requests
No description provided.
The text was updated successfully, but these errors were encountered: