1. 使用元组(tuple):
```python
def multiple_returns():
return 1, 2, 3
a, b, c = multiple_returns()
print(a) 输出:1
print(b) 输出:2
print(c) 输出:3
2. 使用列表(list):
```python
def list_returns():
return [1, 2, 3]
results = list_returns()
for result in results:
print(result)
3. 使用字典(dict):
```python
def dict_returns():
return {'a': 1, 'b': 2, 'c': 3}
results = dict_returns()
for key, value in results.items():
print(key, value)
4. 使用`print()`函数直接输出多个值,用逗号隔开:
```python
x = 10
y = "Hello"
z = 3.14
print(x, y, z) 输出:10 Hello 3.14
```python
x = 10
y = "Hello"
z = 3.14
print("x = {}, y = {}, z = {:.2f}".format(x, y, z)) 输出:x = 10, y = Hello, z = 3.14
6. 使用`print()`函数的`end`参数控制输出后的字符,默认是换行符`\n`,可以设置为空格或其他字符:
```python
for i in range(10):
print(i, end=' ')
print() 输出:0 1 2 3 4 5 6 7 8 9
以上方法都可以用来在Python中输出多个结果