实验室项目
Python
返回列表

Hello World 实验

这是最简单的 Python 实验。你可以输入你的名字,程序会向你问好。

Python 代码:
def hello(name: str) -> str:
    """向指定的人问好"""
    return f"Hello, {name}!"

# 使用示例
result = hello("World")
print(result)  # 输出: Hello, World!
试试看:
💡 学习要点:
  • 函数定义:使用 def 关键字定义函数

  • 类型注解name: str-> str 提供类型提示

  • f-string:使用 f"" 进行字符串格式化

  • API 调用:点击"调用 API"按钮会向 FastAPI 后端发送请求