Python Print

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 >

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值