本文共 1695 字,大约阅读时间需要 5 分钟。
print函数python
print() function is used to print message on the screen.
print()函数用于在屏幕上打印消息。
Example:
例:
# python print() function example# printing textprint("Hello world!")print("Hello world!")print("I\'m fine!")# printing variable's valuesa = 10b = 10.23c = "Hello"print(a)print(b)print(c)# printing text with variable's valuesprint("Value of a = ", a)print("Value of b = ", b)print("Value of c = ", c)
Output
输出量
Hello world!Hello world!I'm fine!1010.23HelloValue of a = 10Value of b = 10.23Value of c = Hello
See the output of the above program, print() function is ending with a newline and the result of the next print() function is printing in the newline (next line).
参见上面程序的输出, print()函数以换行符结尾,下一个print()函数的结果在换行符(下一行)中打印 。
end is an optional parameter in and its default value is '\n' which means print() ends with a newline. We can specify any character/string as an ending character of the print() function.
end是的可选参数,其默认值为'\ n' ,这意味着print()以换行符结尾 。 我们可以指定任何字符/字符串作为print()函数的结束字符。
Example:
例:
# python print() function with end parameter example# ends with a spaceprint("Hello friends how are you?", end = ' ')# ends with hash ('#') characterprint("I am fine!", end ='#')print() # prints new line# ends with nil (i.e. no end character)print("ABC", end='')print("PQR", end='\n') # ends with a new line# ends with stringsprint("This is line 1.", end='[END]\n')print("This is line 2.", end='[END]\n')print("This is line 3.", end='[END]\n')
Output
输出量
Hello friends how are you? I am fine!#ABCPQRThis is line 1.[END]This is line 2.[END]This is line 3.[END]
Recommended posts
推荐的帖子
翻译自:
print函数python
转载地址:http://dxtzd.baihongyu.com/