變量類型:
name: str = "Alice"
age: int = 30
height: float = 1.75
is_student: bool = False
注解:
def add(a: int, b: int) -> int:
? ? return a + b
def greet(name: str) -> None:
? ? print(f"Hello, {name}")
定義矩形類:
class Rectangle:
? ? width: float? ? ??
? ? height: float? ? ?
? ? def __init__(self, width: float, height: float):
? ? ? ? self.width = width
? ? ? ? self.height = height
? ? def area(self) -> float:@浙大疏錦行
? ? ? ? return self.width * self.height