开始使用免费开始使用

在自定义类中使用类型提示

在本练习中,您将结合内置类型关键字、typing 库以及您自己的自定义类来练习类型提示。List 已从 typing 库导入。现在开始吧!

本练习是课程的一部分

Python 面向对象编程进阶

查看课程

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Define an agent class with a constructor, add type hints
class Agent:
  def __init__(self, ____: ____, ____: ____):
    self.____: ____ = codename
    self.____: int  = ____
编辑并运行代码