Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 用开放的花括号填充f字串_Python_Python 3.x_F String - Fatal编程技术网

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

在Python中,我们可以通过以下方式填充f字符串:

>>> 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 {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{'