码迷,mamicode.com
首页 > 编程语言 > 详细

python f-string

时间:2020-02-06 01:33:20      阅读:76      评论:0      收藏:0      [点我收藏+]

标签:class   替换   而不是   源代码   版本   常量   运行   int   字符   

  • python3.6及以后的版本支持f-string
  • f-string提供了一种使用最少的语法将表达式嵌入到字符串文本中的方法。应该注意,f-string实际上是在运行时计算的表达式,而不是常量。在Python源代码中,f-string是一个文字字符串,以“f”为前缀,其中包含大括号内的表达式。表达式被它们的值替换。
  • 用法:

    >>> x = 1
    >>> print(f'{x}', f"{x}", f"""{x}""")
    1 1 1
    >>> print(f'{x}', f'{{x}}' , f'{{{x}}}')
    1 {x} {1}

python f-string

标签:class   替换   而不是   源代码   版本   常量   运行   int   字符   

原文地址:https://www.cnblogs.com/edhg/p/12267469.html

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