Python入门之类(class)

Python入门之类(class)

学习网址:https://www.cnblogs.com/chengd/articles/7287528.html

 

class Foo:
    """初始化实例属性"""
    def __init__(self, name, age):#构造函数,类实例化是自动执行
        self.name = name
        self.age = age

    def detail(self):
        print(self.name)
        print(self.age)
obj1=Foo('gina',18)

obj1.detail()

obj2=Foo('gaokexin',18)
obj2.detail()

  

posted @ 2021-01-29 14:20  yongqi-911  阅读(24)  评论(0编辑  收藏  举报