class Student:
def __init__(self, name: str, student_id: int, tuition_balance: float) -> None:
self.name: str = name
self.student_id: int = student_id
self.tuition_balance: float = tuition_balance
def get_course(self, course_id: str) -> Course:
...
return course
# Use Student and Course to type hint
walker: Student = Student("Sarah Walker", 319921, 15000)
data_science: Course = walker.get_course("TDM-20100")
################## Example 2 ################
# Define an agent class with a constructor, add type hints
class Agent:
def __init__(self, codename: str, missions: int):
self.codename: str = codename
self.missions: int = missions
# Create the add_mission() method, add type hinting
def add_mission(self, location: str) -> None:
self.missions += 1
print(f"{self.codename} completed a mission in " + \
f"{location}. This was mission #{self.missions}")
# Create an Agent object, add type hints
chuck: Agent = Agent("Charles Carmichael", 37)
# Create a list of locations, add a mission for each
locations: List[str] = ["Burbank", "Paris", "Prague"]
for location in locations:
chuck.add_mission(location)