0
点赞
收藏
分享

微信扫一扫

Python字符串拼接变量的优雅写法

艾晓雪 2022-04-19 阅读 82

Python字符串拼接变量的优雅写法

方法:

在python中 字符串前加 f表示:在字符串内支持大括号内的python表达式

import time


name = "tom"
# 常规写法
print("his name is " + name + "!")
print("present time is "+ str(int(time.time())))


# 分隔符
print('&'*50)


# 优雅效率写法
print(f"his name is {name}!")
print(f"present time is {int(time.time())}")

举报

相关推荐

0 条评论