美文网首页
Class学习

Class学习

作者: ThalesW | 来源:发表于2018-04-23 19:47 被阅读0次

    本文简单介绍Python 3.0中类(Class)的使用。

    一、类的结构

    class MyClass:
        i = 123
        def __init__(self, m, n):
            self.a = m
            self.b = n
        def f(self):
            return 'hello world'
        
    x = MyClass()
    print("MyClass mem", x.a, x.b, x.i)
    print("MyClass fun:", x.f())
    

    从上述代码中可以看出类的基本组成元素:类名称,成员变量,构造函数,成员函数。

    相关文章

      网友评论

          本文标题:Class学习

          本文链接:https://www.haomeiwen.com/subject/nfallftx.html