Tag:python return static method class method
#!/usr/bin/python#-*- coding: utf-8 -*-class pizza (object): a= "AA" def __init__ (self): self.name = ' Leon ' def cook (self): return self.mix_ingredients (Self.cheese, self.vegetables) @staticmethod def mix_ingredients (x, y): print Pizza.a #print Pizza.name return x + y @classmethod def hi (cls, x): print cls.a * xprint pizza.mix_ingredients (2,3) print Pizza.hi (3)
Difference:
Both class and static methods can be called by class and class instances, and class instance methods can only be called by class instances
The implied invocation parameter of a class method is a class, and the implied invocation parameter of a class instance method is an instance of the class, and the static method does not implicitly invoke the argument
Neither class method nor static method can access instance properties (Self.name)
can access static properties
---------------------------------------------------------------------------------------------------------
Taken from the online provision, collation.
This article is from the "Goooood" blog, make sure to keep this source http://goooood.blog.51cto.com/5060201/1693441
Python static methods and class methods