有没有更好的方法将变量插入字符串?你知道吗
比如说,重复性比。。。你知道吗
with open('zlog.txt', 'a') as log:
log.write('[ %s ] Finished scrolling.\n[ %s ] #%s clicks.\n[ %s ] Number of Elements: %s\n' % (finish_time, finish_time, str(x), finish_time, str(len(elements))))
我经常重用finish_time
,以便在日志中为条目添加时间戳。你知道吗
... % (finish_time, finish_time, str(x), finish_time, str(len(elements)))
在^{} 中使用位置参数说明符:
我喜欢使用格式方法:
能够读取任何对象或数据类型并将其直接传递给字符串的格式
能够将变量传递给字符串而无需索引编号的格式
如果您使用的是Python3.6,那么fstrings有一个特性
这将给你:
相关问题 更多 >
编程相关推荐