python类函数调用的方法是什么
在 Python 中调用类函数有两种方法:
- 实例化类并调用实例方法:
class MyClass:
def my_function(self):
print("Hello, world!")
my_instance = MyClass()
my_instance.my_function()
- 直接调用类方法(静态方法):
class MyClass:
@staticmethod
def my_function():
print("Hello, world!")
MyClass.my_function()
相关问答