易百教程

37、Python中print() 函数的end的目的是什么?

Python 的 print() 函数总是在最后打印一个换行符。 print() 函数接受一个称为end的可选参数。默认情况下,它的值是 。可以使用此参数将打印语句中的结束字符更改为选择的值。

# Example: Print a  instead of the new line in the end.
print("Let's learn" , end = ' ')  
print("Python") 

# Printing a dot in the end.
print("Learn to code from yii\bai" , end = '.')  
print("com", end = ' ')

运行结果如下:

Let's learn Python
Learn to code from yii\bai.com