Print()函数

本文详细介绍了Python内置的print函数,包括其参数Value、Sep、End、File和Flush的用法。Value允许输出任意类型的数据,Sep用于设置值之间的分隔符,End指定输出后跟随的字符,默认换行。File指定了输出位置,通常默认为sys.stdout,而Flush则控制是否强制刷新流。通过实例展示了如何使用这些参数自定义输出格式。
摘要由CSDN通过智能技术生成
print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)

目录

Value

Sep

End

File

Flush


builtins.py里的释义:

Prints the values to a stream, or to sys.stdout by default.
Optional keyword arguments:
file:  a file-like object (stream); defaults to the current sys.stdout.
sep:   string inserted between values, default a space.
end:   string appended after the last value, default a newline.
flush: whether to forcibly flush the stream.

Value

在2.X版本中,print可以不加括号。

在3.X版本及以后,print必须加括号。

Print在控制台里输出,VALUE可以是任何类型。

因为中间有一个"...",print函数里可以加无线个逗号分隔并都为Value的值。

print(1)

>>>1

print(1,2)

>>>1 2

print("123fff")

>>>123fff

print(True)

>>>True

Sep

sep表示分隔符。

print(1,2)>>>1 2

print(1,2,sep="|")>>>1|2

print(12,sep="|")>>>12

sep里的值可以分隔逗号之间的n个值。

print(1,2,3,4,sep="|")>>>1|2|3|4

print(1,2,sep="s]")>>>1s]2

End

End函数表示输入后的符号,默认为换行符(\n)

print(1)

print(2)

>>>1

>>>2

print(1,end="h")

print(2,end="e")

>>>1h2e

File

输出的位置(要求:必须有write函数)

默认:sys.stdout

print(1,end="")=std.stdout.write(1)

Flush

刷新,默认为False

[较为专业,一般不太用]

<我的第一个程序Hello,World.py>

print("Hello,World")

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Unconquerable p

给点吧~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值