原创

```python

温馨提示:
本文最后更新于 2024年07月24日,已超过 252 天没有更新。若文章内的图片失效(无法正常加载),请留言反馈或直接联系我

```python def greet(name): """ Greets a person by name.

Args: name: The name of the person to greet.

Returns: A greeting message. """ return f"Hello, {name}!"

def add(x, y): """ Adds two numbers together.

Args: x: The first number. y: The second number.

Returns: The sum of x and y. """ return x + y

def factorial(n): """ Calculates the factorial of a non-negative integer.

Args: n: The non-negative integer.

Returns: The factorial of n. """ if n == 0: return 1 else: return n * factorial(n - 1)

if name == "main": print(greet("World")) print(add(2, 3)) print(factorial(5)) ```

文件说明

该文件包含三个 Python 函数:

  • greet(name):接受一个姓名作为参数,并返回一个问候语。
  • add(x, y):接受两个数字作为参数,并返回它们的和。
  • factorial(n):接受一个非负整数作为参数,并返回该整数的阶乘。

该文件还包含一个简单的示例,演示了如何使用这些函数。

函数文档

每个函数都有一个文档字符串,描述了它的功能、参数和返回值。

示例

```python

greet("Alice") 'Hello, Alice!'

add(2, 3) 5

factorial(5) 120 ```

正文到此结束