指定函数 参数类型

2025617

15:11

1. Python 是动态类型语言

Python 在运行时不强制检查参数类型。类型注解仅用于提示静态分析工具(如 mypy、IDE 的自动补全),但不影响代码的实际执行。

def add(a: int, b: int) -> int:
   
return a + b

add("hello", "world")  # 不会报错,运行时拼接字符串 "helloworld"

 

 

 

已使用 OneNote 创建。