亿迅智能制造网
工业4.0先进制造技术信息网站!
首页 | 制造技术 | 制造设备 | 工业物联网 | 工业材料 | 设备保养维修 | 工业编程 |
home  MfgRobots >> 亿迅智能制造网 >  >> Industrial programming >> Python

Python Print() 语句:如何通过示例打印


在本教程中,您将学习-

Python print() 函数

Python 中的 print() 函数用于在屏幕上打印指定的消息。 Python 中的 print 命令打印字符串或在屏幕上打印时转换为字符串的对象。

语法

print(object(s))

如何在 Python 中打印一个简单的字符串?

更多时候,您不需要在编码结构中打印字符串。

以下是如何在 Python 3 中打印语句:

示例:1

要打印 Welcome to Guru99,请使用 Python 打印语句,如下所示:

print ("Welcome to Guru99")


输出:

欢迎来到 Guru99

在 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

打印结束命令

默认情况下,Python 中的 print 函数以换行符结尾。该函数带有一个名为“end”的参数。该参数的默认值为“\n”,即换行符。您可以使用此参数以任何字符或字符串结束打印语句。这仅在 Python 3+ 中可用

示例 1:

print ("Welcome to", end = ' ') 
print ("Guru99", end = '!')

输出:

欢迎来到 Guru99!

示例 2:

# 以'@'结束输出。

print("Python" , end = '@')

输出:

蟒蛇@


Python

  1. Python pass 语句
  2. Java String compareTo() 方法:如何与示例一起使用
  3. 带有示例的 Python 字符串计数()
  4. Python String format() 举例说明
  5. Python String find() 方法及示例
  6. 带有示例的 Python Lambda 函数
  7. 带有示例的 Python round() 函数
  8. 带有示例的 Python map() 函数
  9. Python Timeit() 与示例
  10. Python 中的 type() 和 isinstance() 示例
  11. Python 换行:如何在 Python 中不使用换行进行打印
  12. 带有示例的 Python 列表计数()