if return python
时间: 2023-12-11 17:04:03 浏览: 93
python if 语句
In Python, the `return` statement is used to exit a function and return a value back to the caller. It can also be used to return None if no value is specified. Here's an example:
```
def add_numbers(a, b):
return a + b
result = add_numbers(3, 4)
print(result) # Output: 7
```
In this example, the `return a + b` statement returns the sum of `a` and `b` back to the caller when the `add_numbers` function is called. The returned value is then stored in the `result` variable and printed.
阅读全文