100+ Python challenging programming exercises 6

Question 51
Define a class named American and its subclass NewYorker.
Hints: Use class Subclass(ParentClass) to define a subclass.
定义一个名为American的类及其子类NewYorker。
提示:使用class Subclass(ParentClass)来定义子类。
Solution:
class American:
def __init__(self, name, age):
self.name = name
self.age = age
def introduce(self):
return f"Hello, my name is {self.name} and I am {self.age} years old."
class NewYorker(American):
def introduce(self):
return f"Yo, my name is {self.name} and I am from New York. I'm {self.age} years old."
anAmerican = American('Tom',8)
aN










![力扣-收集足够苹果的最小花园周长[思维+组合数]](https://img-blog.csdnimg.cn/direct/79a713892c18417a87113c8aac061719.jpeg)

![[linux]高级IO](https://img-blog.csdnimg.cn/direct/954ee1d82ee34c6d90088dab38e17db7.png)





