怎样使 Python 输出时不换行

如题所述

1、说明:
python输出时不换行,python版本不同使用方式不同:python2.x 使用print '输出内容',加一个空格即可;python3.x版本使用print('输出内容', end='')这种方式。
2、代码示例:
python2.x
print '不换行',
print '换行'
python3.x
print('不换行', end='')
print('换行')
执行结果:
python2.x

不换行 换行
python3.x
不换行换行
3、函数说明:
python2.x
print

一个'\ n'字符结尾写的,除非'print'声明以逗号结束。这是如果该语句的唯一操作只包含关键字'print'。
python3.x

print(...)
print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)
end: 字符串的最后一个值后追加,默认为新行。
温馨提示:答案为网友推荐,仅供参考
相似回答