特别特别篇2(格式化输出)

本文详细介绍了使用Python进行格式化字符串输出的方法,包括各种转换标志的含义及其应用场景,如整数、浮点数和字符等数据类型的格式化输出。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近比较忙~在调试新写的代码,没时间写~所以更新的慢啦!

特别特别篇(格式化输出)

字符串格式化输出:

我喜欢这种格式,用括号括起来,有c语言的感觉,所以我规定以后我的输出都用这种格式来输出东东。

Print “%format” %(content1, content2, …)

Format可以用的格式输出

Conversion

Meaning

'd'

Signed integer decimal.

'i'

Signed integer decimal.

'o'

Signed octal value.

'u'

Obsolete type – it is identical to 'd'.

'x'

Signed hexadecimal (lowercase).

'X'

Signed hexadecimal (uppercase).

'e'

Floating point exponential format (lowercase).

'E'

Floating point exponential format (uppercase).

'f'

Floating point decimal format.

'F'

Floating point decimal format.

'g'

Floating point format. Uses lowercase exponential format if exponent is less than -4 or not less than precision, decimal format otherwise.

'G'

Floating point format. Uses uppercase exponential format if exponent is less than -4 or not less than precision, decimal format otherwise.

'c'

Single character (accepts integer or single character string).

'r'

String (converts any Python object using repr()).

's'

String (converts any Python object using str()).

'%'

No argument is converted, results in a '%' character in the result.

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值