V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
VforVendetta
V2EX  ›  Python

弄混淆了! f 格式化字符串和字典

  •  
  •   VforVendetta · 286 天前 · 1510 次点击
    这是一个创建于 286 天前的主题,其中的信息可能已经有所发展或是发生改变。

    第一眼看下面这段代码,不对呀!有语法错误!为什么 count key 没有 value 。 再一看原来是 f 格式化字符串。 给自己笑死🤣

    data = {f"{count}": {"f": "txt","k": f"{ext}","q": f"{last}","size": "789","key": f"96"}} 伪代码演示

    6 条回复    2023-07-24 15:03:38 +08:00
    VforVendetta
        1
    VforVendetta  
    OP
       286 天前
    {count}单独看,以为少了{count: value}
    hsfzxjy
        2
    hsfzxjy  
       286 天前 via Android
    格式化一下代码就不会看错
    JasonLaw
        3
    JasonLaw  
       286 天前 via iPhone
    谁会写出这样的代码?🤕可读性基本没有。
    NoOneNoBody
        4
    NoOneNoBody  
       286 天前
    嵌套的话,分行写清晰些
    f"96"就没必要了

    @JasonLaw #3
    有语法高亮的话,还是可读的
    009694
        5
    009694  
       285 天前 via iPhone
    随便一个特征都会被奇怪的场景用出花来。。duck 不必
    rev1si0n
        6
    rev1si0n  
       285 天前
    网文中描述的高级用法,真会玩,真玩出花了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2460 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 08:45 · PVG 16:45 · LAX 01:45 · JFK 04:45
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.