带有结束参数的Python print()函数
print()功能
print()功能用于在屏幕上打印消息。
例子:
#pythonprint()函数示例
#打印文字
print("Hello world!")
print("Hello world!")
print("I\'m fine!")
#打印变量的值
a = 10
b = 10.23
c = "Hello"
print(a)
print(b)
print(c)
#打印文字 with variable's values
print("Value of a = ", a)
print("Value of b = ", b)
print("Value of c = ", c)输出
Hello world!Hello world! I'm fine! 10 10.23 Hello Value of a = 10 Value of b = 10.23 Value of c = Hello
参见上面程序的输出,print()函数以换行符结尾,下一个print()函数的结果在换行符(下一行)中打印。
print()带有结束参数的功能
end是print()函数中的可选参数,其默认值为'\n',表示print()以换行符结尾。我们可以指定任何字符/字符串作为print()函数的结束字符。
例子:
#带有结束参数示例的pythonprint()函数
#以空格结尾
print("Hello friends how are you?", end = ' ')
# ends with hash ('#')特点
print("I am fine!", end ='#')
print() #打印新行
#以nil结尾(即没有结束字符)
print("ABC", end='')
print("PQR", end='\n') #以新行结尾
#以字符串结尾
print("This is line 1.", end='[END]\n')
print("This is line 2.", end='[END]\n')
print("This is line 3.", end='[END]\n')输出
Hello friends how are you? I am fine!# ABCPQR This is line 1.[END] This is line 2.[END] This is line 3.[END]
