__init__ 构造行数的用法

#! -*- coding:utf-8 -*-

class Person(object):
    #构造函数
    def __init__(self, name):
        self.name = name
        
    def sayHi(self):
        print("Hello, my name is", self.name)

p = Person("Swaroop")
p.sayHi()

就是初始化类,把参数赋值给类上去用

D:\Anaconda3\envs\py38\python.exe F:/pyScript/webUi/ymd.py
Hello, my name is Swaroop

Process finished with exit code 0

 

 

 

继承类还要加 绑定 就需要超类super

super(B,self).__init__()
格式:
super(当前类名,self).__init__()

 

posted @ 2021-04-22 22:26  测试艺术家  阅读(54)  评论(0编辑  收藏  举报