https://www.sharetechnote.com/html/Python_Print.html
print() 是 Python(实际上是任何语言中最重要的函数)中最重要的函数。没有什么需要特别解释的,只需遵循以下示例。
注意1:本页面中的所有示例都是用 Python 3.x 编写的。如果您使用的是 Python 2.x,可能无法正常工作。
注意2:除非特别提及,否则本页面中的所有示例都假定是在 Windows 7 上编写/运行的。如果您在其他操作系统上运行,可能需要稍微修改一下语法。
基本语法:
示例1:使用双引号打印单个字符串 - Example 1
示例2:使用单引号打印单个字符串 - Example 2
示例3:在单行中打印多个部分 - Example 3
示例4:在单行中打印多个部分并换行 - Example 4
示例5:在末尾不带换行符打印 - Example 5
示例6:在末尾不带换行符打印并指定结束字符 - Example 6
基本语法:
print("string") - Example 1
print('string') - Example 2
print("string1", var1) - Example 3
print("string1", var1, "string2", var2, ...) - Example 4
print("string1","\nString2") - Example 5
print("string",end=' ') - Example 6
示例:
< Example 1 >
print("Hello World")
Result :--------------------------
Hello World
< Example 2 >
print('Hello World')
Result :--------------------------
Hello World
< Example 3 >
score = 75
print("Your score is ",score)
Result :--------------------------
Your score is 75
< Example 4 >
score = 75
grade = "C"
print("Your score is ",score, " And ", "Your Grade is ",grade)
Result :--------------------------
Your score is 75 And Your Grade is C
< Example 5 >
score = 75
grade = "C"
print("Your score is ",score, "\nYour Grade is ",grade)
Result :--------------------------
Your score is 75
Your Grade is C
< Example 6 >
print("===Print without New Line at the end ===")
for i in range(5) :
print(i, " ")
print("===Print without New Line at the end ===")
for i in range(5) :
print(i, " ", end=' ')
Result :--------------------------
===Print without New Line a
t the end ===
0
1
2
3
4
===Print without New Line at the end ===
0 1 2 3 4
< Example 7 >
2381

被折叠的 条评论
为什么被折叠?



