Python self,init,对象属性

self关键字的作用
__init__初始化

# coding=utf-8 支持中文


class Human(object):
    laugh = 'Ha'

    def show_laugh(self):
        print self.laugh

    def laugh_100th(self):
        for i in range(100):
            self.show_laugh()


li_lei = Human()
li_lei.laugh_100th()

类属性与对象属性

# coding=utf-8 支持中文


class Human(object):

    def __init__(self,input_gender):
        self.gender = input_gender

    def print_gender(self):
        print self.gender


li_lei = Human('男')
li_lei.print_gender()
原文地址:https://www.cnblogs.com/jiqing9006/p/10591027.html