Python 用开放的花括号填充f字串
在Python中,我们可以通过以下方式填充f字符串:Python 用开放的花括号填充f字串,python,python-3.x,f-string,Python,Python 3.x,F String,在Python中,我们可以通过以下方式填充f字符串: >>> f"{' hello ':#^80}" '#################################### hello #####################################' f"{' hello ':{chr(123)}^80}" 如何用{字符填充'hello'字符串?您可以这样做: >>> f"{' hello
>>> f"{' hello ':#^80}"
'#################################### hello #####################################'
f"{' hello ':{chr(123)}^80}"
如何用{
字符填充'hello'
字符串?您可以这样做:
>>> f"{' hello ':#^80}"
'#################################### hello #####################################'
f"{' hello ':{chr(123)}^80}"
要确定“{”的值为123,可以运行返回123的ord(“{”)
输出:
'{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{ hello {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{'
您可以这样做:
>>> f"{' hello ':#^80}"
'#################################### hello #####################################'
f"{' hello ':{chr(123)}^80}"
要确定“{”的值为123,可以运行返回123的ord(“{”)
输出:
'{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{ hello {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{'
对支撑本身使用转义序列:
>>> f"{' hello ':\x7b^80}"
'{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{ hello {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{'
对支撑本身使用转义序列:
>>> f"{' hello ':\x7b^80}"
'{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{ hello {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{'