推荐学习书目
› 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
182247236
V2EX  ›  Python

字典表的%字符问题

  •  
  •   182247236 · Dec 21, 2016 · 2768 views
    This topic created in 3569 days ago, the information mentioned may be changed or developed.

    遇到个例子

    phonebook
    {'Alice': '2341', 'Beth': '9102', 'Cecil': '3258'}
    "Cecil's phone number is %(Cecil)s." % phonebook
    "Cecil's phone number is 3258." 原文如下: 在每个转换( conversion specifier )中的 % 字符后面,可以加上用圆括号括起来的键,后面再跟上其他说明元素。

    这段有点看不懂,自己理解

    "%( k ) s"%d 'v' 这里的%和 s 代表什么意思?

    4 replies  •  2016-12-22 00:43:17 +08:00
    Sylv
        1
    Sylv  
       Dec 21, 2016 via iPhone
    关键词: Python 字符串 格式化
    AyoCross
        2
    AyoCross  
       Dec 21, 2016
    "Cecil's phone number is %s." % phonebook[Cecil] # 这样会不会更好理解一点
    182247236
        3
    182247236  
    OP
       Dec 22, 2016
    @AyoCross get 到一点了,不过 @Sylv 给了关键词,我还是查查
    182247236
        4
    182247236  
    OP
       Dec 22, 2016
    @Sylv 马上去查查
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   915 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 81ms · UTC 20:13 · PVG 04:13 · LAX 13:13 · JFK 16:13
    ♥ Do have faith in what you're doing.