Multiline f-strings

mac2022-06-30  24

多行字符串使用fstring需要注意每行都要加fstring

>>> name = "Eric" >>> profession = "comedian" >>> affiliation = "Monty Python" >>> message = ( ... f"Hi {name}. " ... f"You are a {profession}. " ... f"You were in {affiliation}." ... ) >>> message 'Hi Eric. You are a comedian. You were in Monty Python.'

如果使用三个双引号

>>> message = f""" ... Hi {name}. ... You are a {profession}. ... You were in {affiliation}. ... """ ... >>> message '\n Hi Eric.\n You are a comedian.\n You were in Monty Python.\n'

转载于:https://www.cnblogs.com/c-x-a/p/11320362.html

相关资源:UltraEdit-32
最新回复(0)