实际上我想在 f-string 中的文本上使用标题方法?
actually i want to use a title method over a text in f-string?
my_favourites=['lamborghini',"sea facing resort",
'100 b dollar','3D animator']
line_1='and by that much money i want to own a '.title()+my_favourites[1].title()+' & a
'+my_favourites[0].upper()
print(line_1)
line_2=f'and by that much money i want to own a {my_favourites[1].title()} & a
{my_favourites[0].upper()}'
print(line-2)
#所以这里的问题是连接效果很好,但我不知道如何将 title 方法应用于 f-string 语法中的初始文本,而不将该文本分配给额外的变量。
我承认 F 弦有点奇怪:
f"{'and by that much money i want to own a'.title()} {my_favourites[1].title()} & {'a'.title()} {my_favourites[0].upper()}"
我认为 str.format
更合适:
"and by that much money i want to own a {} & a {}".title().format(my_favourites[1].title(), my_favourites[0].upper())
my_favourites=['lamborghini',"sea facing resort",
'100 b dollar','3D animator']
line_1='and by that much money i want to own a '.title()+my_favourites[1].title()+' & a
'+my_favourites[0].upper()
print(line_1)
line_2=f'and by that much money i want to own a {my_favourites[1].title()} & a
{my_favourites[0].upper()}'
print(line-2)
#所以这里的问题是连接效果很好,但我不知道如何将 title 方法应用于 f-string 语法中的初始文本,而不将该文本分配给额外的变量。
我承认 F 弦有点奇怪:
f"{'and by that much money i want to own a'.title()} {my_favourites[1].title()} & {'a'.title()} {my_favourites[0].upper()}"
我认为 str.format
更合适:
"and by that much money i want to own a {} & a {}".title().format(my_favourites[1].title(), my_favourites[0].upper())