開始使用免費開始

在自訂類別中使用型別提示

在這個練習中,你會使用內建的型別關鍵字、typing 函式庫,以及你自己的自訂類別來練習型別提示。List 已從 typing 函式庫匯入。開始動手吧!

本練習屬於課程

Python 物件導向程式設計進階

檢視課程

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Define an agent class with a constructor, add type hints
class Agent:
  def __init__(self, ____: ____, ____: ____):
    self.____: ____ = codename
    self.____: int  = ____
編輯並執行程式碼