def example_function(x):
if x > 0:
return "x is positive"
elif x < 0:
return "x is negative"
else:
return "x is zero"
# 解释说明:
# 在这个例子中,`return` 语句用于从函数中返回一个值。
# 当函数被调用时,它会根据传入的参数 `x` 的值返回不同的字符串。
# 如果 `x` 大于 0,返回 "x is positive";
# 如果 `x` 小于 0,返回 "x is negative";
# 如果 `x` 等于 0,返回 "x is zero"。
# 调用示例
print(example_function(10)) # 输出: x is positive
print(example_function(-5)) # 输出: x is negative
print(example_function(0)) # 输出: x is zero
上一篇:python for range
下一篇:python loguru
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站