print函数python
print()函数 (print() function)
print() function is used to print message on the screen.
print()函数用于在屏幕上打印消息。
Example:
例:
# python print() function example
# printing text
print("Hello world!")
print("Hello world!")
print("I\'m fine!")
# printing variable's values
a = 10
b = 10.23
c = "Hello"
print(a)
print(b)
print(c)
# printing text with variable's values
print("Value of a = ", a)
print("Value of b = ", b)
print("Value of c = ", c)
Output
输出量
Hello world!Hello world!
I'm fine!
10
10.23
Hello
Value of a =  10
Value of b =  10.23
Value 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()函数的结果在换行符(下一行)中打印 。
带有结束参数的print()函数 (print() function with end parameter)
end is an optional parameter in print() function 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是print()函数中的可选参数,其默认值为'\ n' ,这意味着print()以换行符结尾 。 我们可以指定任何字符/字符串作为print()函数的结束字符。
Example:
例:
# python print() function with end parameter example
# ends with a space
print("Hello friends how are you?", end = ' ')
# ends with hash ('#') character
print("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 strings
print("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!#
ABCPQR
This is line 1.[END]
This is line 2.[END]
This is line 3.[END]
Recommended posts
推荐的帖子
- Read input as an integer in Python - 在Python中将输入读取为整数 
- Read input as a float in Python - 在Python中以浮点形式读取输入 
- Parse a string to float in Python (float() function) - 解析要在Python中浮动的字符串(float()函数) 
- How do you read from stdin in Python? - 您如何从Python的stdin中读取信息? 
- Asking the user for integer input in Python | Limit the user to input only integer value - 要求用户在Python中输入整数| 限制用户仅输入整数值 
- Asking the user for input until a valid response in Python - 要求用户输入直到Python中的有效响应 
- Input a number in hexadecimal format in Python - 在Python中以十六进制格式输入数字 
- Input a number in octal format in Python - 在Python中以八进制格式输入数字 
- Input a number in binary format in Python - 在Python中以二进制格式输入数字 
- How to get the hexadecimal value of a float number in python? - 如何在python中获取浮点数的十六进制值? 
- Convert an integer value to the string using str() function in Python - 使用Python中的str()函数将整数值转换为字符串 
- Convert a float value to the string using str() function in Python - 使用Python中的str()函数将浮点值转换为字符串 
- Input and Output Operations with Examples in Python - 使用Python中的示例进行输入和输出操作 
- Taking multiple inputs from the user using split() method in Python - 使用Python中的split()方法从用户获取多个输入 
- Fast input / output for competitive programming in Python - 快速输入/输出,可在Python中进行有竞争力的编程 
- Precision handling in Python - Python中的精确处理 
翻译自: https://www.includehelp.com/python/print-function-with-end-parameter.aspx
print函数python