码迷,mamicode.com
首页 > 其他好文 > 详细

Multiline f-strings

时间:2019-08-08 13:27:43      阅读:55      评论:0      收藏:0      [点我收藏+]

标签:需要   iat   median   com   python   ring   引号   lin   you   

多行字符串使用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'

Multiline f-strings

标签:需要   iat   median   com   python   ring   引号   lin   you   

原文地址:https://www.cnblogs.com/c-x-a/p/11320362.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!