def example_function(x):
if x > 0:
return "x is positive"
elif x < 0:
return "x is negative"
else:
return "x is zero"
# 调用函数并打印结果
print(example_function(10)) # 输出: x is positive
print(example_function(-5)) # 输出: x is negative
print(example_function(0)) # 输出: x is zero
return
语句用于从函数中返回一个值。当 Python 执行到 return
语句时,它会立即退出函数,并将指定的值返回给调用者。example_function
函数根据传入的参数 x
的值返回不同的字符串。x
是正数,返回 "x is positive"
;如果 x
是负数,返回 "x is negative"
;如果 x
是零,返回 "x is zero"
。print
函数调用 example_function
并输出返回的结果。上一篇:python打包exe
下一篇:python sqlite3
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站