在Python中,如果你想要在输出内容后不换行,可以使用`print`函数的`end`参数。`end`参数指定了`print`函数在输出内容后添加的字符。默认情况下,`print`函数会在输出内容后自动添加换行符(`'\n'`)。
1. 使用`end=''`参数:
```python
print("Hello", end='')
print("World")
输出结果为:`HelloWorld`
2. 使用`end=','`参数(仅适用于Python 2.x版本):
```python
for i in range(11):
print(i, end=',')
输出结果为:`0,1,2,3,4,5,6,7,8,9,10,`
3. 使用`end=''`参数(适用于Python 3.x版本):
```python
print("Hello", end='')
print("World")
输出结果为:`HelloWorld`
4. 使用`from __future__ import print_function`导入模块,然后设置`end=''`参数:
```python
from __future__ import print_function
print(".", end='')
输出结果为:`.`
请注意,在Python 2.x版本中,`end=','`参数也可以实现不换行,但在Python 3.x版本中,推荐使用`end=''`参数。