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

Python string 格式化的问题

  •  
  •   eote · Feb 28, 2016 · 3734 views
    This topic created in 3909 days ago, the information mentioned may be changed or developed.

    使用 format 与%格式化字符串有什么区别。为什么我在文档里多用 format 而别人的项目里看到的都是用%
    <script src="https://gist.github.com/imAArtist/116c5ed823fafa593e28.js"></script>

    9 replies  •  2016-02-29 13:02:53 +08:00
    eote
    eote
    OP
    Feb 28, 2016
    1
    WangYanjie
    WangYanjie
    Feb 28, 2016
    2
    google
    shyling
    shyling
    Feb 28, 2016
    4
    写 c 时熟悉了%d
    pc10201
    pc10201
    Feb 28, 2016
    5
    %格式化字符串是老式的写法
    format 是新式的,而且功能更多
    Kisesy
    Kisesy
    Feb 28, 2016
    6
    你再学一段时间,就是这个了 log.debug(xxxx)
    Ge4Los
    Ge4Los
    Feb 28, 2016
    7
    "this is tuple : %s" % (1,2,3) #不能直接使用元组。
    "this is tuple:{}".format((1,2,3)) #可以直接使用元组。
    而 %s 要想输出元组,就得用 ((1,2,3),) 作为参数了
    erse
    erse
    Feb 28, 2016
    8
    最好用 format 而不是用%,有坑
    feather12315
    feather12315
    Feb 29, 2016 via Android
    9
    doc 建议 format
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1883 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 15:44 · PVG 23:44 · LAX 07:44 · JFK 10:44
    ♥ Do have faith in what you're doing.