class User(object):
def __init__(self, username, password):
self.username = username
self.password = password
def login(self, uname, pwd):
if self.username == uname and self.password == pwd:
return True
else:
return False
u1 = User("尝试了就好", "123")
ret = u1.login(input("username:").strip(), input("password:").strip())
print(ret)
class Animal(object):
def run(self):
print("----run----")
class Cat(Animal):
pass
cat = Cat()
cat.run() # ----run----
class Animal(object):
def run(self):
print("Animal is running...")
class Dog(Animal):
def run(self):
print("Dog is running...")
class Cat(Animal):
def run(self):
print("Cat is running...")
class Observer():
def observe(self, animal):
animal.run()
dg = Dog()
ct = Cat()
ob = Observer()
ob.observe(dg)
ob.observe(ct)
结果:
Dog is running...
Cat is running...