Python class attribute referencing

前端 未结 2 968
时光说笑
时光说笑 2021-01-21 15:50

This is a sample code that i found from one of the python class tutorial.

class MyClass:
    i = 12345
    def f(self):
        return \'hello world\'

print MyC         


        
2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-21 16:24

    Always a function is called by its name, which is represented by (). So use MyClass.f()

提交回复
热议问题