温馨提示×

python怎么打印在同一行

小亿
121
2024-09-25 23:21:07
栏目: 编程语言
Python开发者专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

在Python中,您可以使用end参数在print函数中指定行尾字符。默认情况下,end参数的值是换行符\n,这意味着每次调用print函数时,都会在输出中添加一个新行。

如果您想在同一行上打印多个项目,可以将end参数设置为空字符串''或空格' '。以下是一些示例:

使用空字符串''

print('Hello', 'world!', end='')
print('We are on the same line.')

输出:

Hello world! We are on the same line.

使用空格' '

print('Hello', 'world!', end=' ')
print('We are on the same line.')

输出:

Hello world! We are on the same line.

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读:python怎么在同一行中输入两个数

0