2019-06-07:类的方法练习

#encoding=utf-8
"""
实现同时具备类方法、静态方法和实例子方法的一个类
"""
class Play(object):
    def __init__(self,what):
        self.what=what

    def toDo(self):
        return self.what

    @classmethod
    def getPlace(cls,where):
        cls.where=where
        return cls.where

    @staticmethod
    def goWays():
        ways=input("which way would you like to go ?:")
        return ways
p=Play("tour")
print(p.toDo())
print(Play.getPlace("chongqing"))
print(Play.goWays())
print(p.goWays())
print(p.getPlace("shanghai"))
print(p.goWays())

猜你喜欢

转载自blog.csdn.net/sinat_18722099/article/details/91129888