zoukankan      html  css  js  c++  java
  • python 字符串格式化,使用f前缀

    格式化一般用%,但后来推荐用format

    format有进步,可以用索引或者名字,但仍然没有很方便和快捷

    # logger.debug('{}  {}  {}  {}  {}  {}'.format(method,  resp.status_code, resp.elapsed.total_seconds(), resp.is_redirect, resp.text.__len__(),resp.url))
    logger.debug(f'{method} {resp.status_code} {round(resp.elapsed.total_seconds(),2):>3.2f} {resp.is_redirect} {resp.text.__len__():<8d} {resp.url}')

    上面的改写为下面的,那么参数的位置信息立马就清晰很多。

    前提是要使用python3.6以及以上版本
  • 相关阅读:
    #4702. gcd
    独特的树叶

    搞笑的代码 ( funny )
    越野赛车问题
    删边(cip)
    最长公共子序列
    美食节
    线段树
    新年快乐
  • 原文地址:https://www.cnblogs.com/ydf0509/p/9467300.html
Copyright © 2011-2022 走看看