Day.31
变量类型:
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