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

艾晓雪

关注

阅读 82

2022-04-19

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)

0 0 举报