热线电话:13121318867

登录
2019-03-07 阅读量: 852
python如何修改语句结束字符?

默认情况下,python的print()函数以换行符结束。具有C / C ++背景的程序员可能想知道如何在没有换行的情况下进行打印。

Python的print()函数带有一个名为'end'的参数。默认情况下,此参数的值为'\ n',即新行字符。您可以使用此参数结束包含任何字符/字符串的print语句。

# This Python program must be run with

# Python 3 as it won't work with 2.7.

# ends the output with a <space>

print("Welcome to" , end = ' ')

print("GeeksforGeeks", end = ' ')

输出 :

Welcome to GeeksforGeeks

还有一个程序用于演示end参数的工作。

# This Python program must be run with

# Python 3 as it won't work with 2.7.

# ends the output with '@'

print("Python" , end = '@')

print("GeeksforGeeks")

输出 :

Python@GeeksforGeeks
10.0796
0
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子