- 论坛徽章:
- 0
|
Python provides a feasible way to define static method in class called staticmethod, just as following code:
class MyClass:
@staticmethod
def Hello(name):
print "Hello, %s" % (name)
The "@staticmethod" form is a function decorator used to denote the function Hello will act as a static method for class MyClass.
Now you can call the method Hello with two ways,
MyClass.Hello("world")
or
MyClass().Hello("world")
which will output same result.
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/48729/showart_463056.html |
|