可以在字符串中使用变量(f字符串是Python3.6版本中引入的),示例如下:
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license()" for more information. >>> first_name = "名字" >>> last_name = "姓氏" >>> f"{first_name} {last_name}" '名字 姓氏' >>> >>> info = f"abc{first_name}def ghi{last_name}jkl" >>> info 'abc名字def ghi姓氏jkl' >>> print(info) abc名字def ghi姓氏jkl >>> >>> type(info)>>> >>> >>>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)