Predict 类实例输出
预测输出 中等
题目
什么做 这个 code print?
代码
class Dog:
def __init__(self, name):
self.name = name
def bark(self):
return f"{self.name} says Woof!"
d = Dog("Rex")
print(d.bark())
提示
__init__ 设置 self.name, bark uses 它.
解释
Dog("Rex") creates an instance with self.name = "Rex". d.bark() returns f"{self.name} says Woof!" = "Rex says Woof!". Output: Rex says Woof!
相关资源
相关课程
- 类 and 对象
类实例.
查阅不认识的术语
新手友好的术语表用大白话解释编程术语——变量、函数、DOM、Promise 等等。
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。
动手做项目
通过引导式项目应用所学,含起始代码与解决方案。