'!a' 在 python f 字符串中起什么作用?

问题描述 投票:0回答:1

当在 python 中使用感叹号时,它表示后面必须跟

!a
!s
!r

!a
有什么作用?

你能做到吗?

f"{"txt"!a}"

结果会怎样?

"TXT" # Obviously not this, but still
python f-string
1个回答
0
投票

在该问题的已接受答案中找到了我的问题的答案 保留

'!r (repr)、!s (str) 和

!a (ascii) 只是为了简化与 str.format 替代方案的兼容性,您不需要将它们与 f 字符串一起使用。'

© www.soinside.com 2019 - 2024. All rights reserved.