Python Print() 语句:如何使用示例进行打印
⚡ 智能摘要
Python print() function displays a message or object on the screen after converting it to a string. The examples below show how to print strings, blank lines, and multiple items, and how to control line endings.

Python print()函数
print() 函数 Python 用于在屏幕上打印指定消息。print 命令 Python 在屏幕上打印时打印字符串或转换为字符串的对象。
语法:
print(object(s))
如何在 Python?
通常你需要 打印字符串 在您的编码构造中。
以下是如何打印语句 Python 3:
例如:1
打印欢迎信息 Guru99,使用 Python 打印语句如下:
print ("Welcome to Guru99")
输出:
歡迎來到 Guru99
In Python 2,同样的例子如下
print "Welcome to Guru99"
例如2:
如果要打印五个国家的名字,可以这样写:
print("USA")
print("Canada")
print("Germany")
print("France")
print("Japan")
输出:
USA Canada Germany France Japan
如何打印空白行
有时你需要在 Python 程序。以下是使用以下命令执行此任务的示例 Python 打印格式。
计费示例:
让我们打印 8 个空白行。您可以输入:
print (8 * "\n")
要么:
print ("\n\n\n\n\n\n\n\n\n")
这是代码
print ("Welcome to Guru99")
print (8 * "\n")
print ("Welcome to Guru99")
输出
Welcome to Guru99 Welcome to Guru99
打印结束命令
By default, the print function in Python ends with a newline. This function comes with a parameter called ‘end’. The default value of this parameter is ‘\n’, i.e., the new line character. You can end a print statement with any character or string using this parameter. This is available only in Python 3 +。
例如1:
print("Welcome to", end=' ') print("Guru99", end='!')
输出:
歡迎來到 Guru99!
例如2:
# ends the output with '@' print("Python", end='@')
输出:
Python@
