请问这个语句是输出什么? print('{!r}'.format(x)) - 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
saximi

请问这个语句是输出什么? print('{!r}'.format(x))

  •  
  •   saximi Nov 13, 2017 4917 views
    This topic created in 3102 days ago, the information mentioned may be changed or developed.
    {!r}是指以什么样的格式输出呢?
    谢谢了!
    5 replies    2017-11-15 20:50:40 +08:00
    ipwx
        1
    ipwx  
       Nov 13, 2017
    repr(x)
    enrolls
        2
    enrolls  
       Nov 14, 2017   1
    善用谷歌啊。https://pyformat.info/
    zhusimaji
        3
    zhusimaji  
       Nov 14, 2017 via iPhone
    是时候了解一下 repr 与 str 区别了
    bxtx999
        4
    bxtx999  
       Nov 14, 2017
    The str() function is meant to return representations of values which are fairly human-readable, while repr() is meant to generate representations which can be read by the interpreter (or will force a SyntaxError if there is not equivalent syntax). For objects which don ’ t have a particular representation for human consumption, str() will return the same value as repr().

    '!a' (apply ascii()), '!s' (apply str()) and '!r' (apply repr()) can be used to convert the value before it is formatted:

    >>> import math
    >>> print('The value of PI is approximately {}.'.format(math.pi))
    The value of PI is approximately 3.14159265359.
    >>> print('The value of PI is approximately {!r}.'.format(math.pi))
    The value of PI is approximately 3.141592653589793.
    saximi
        5
    saximi  
    OP
       Nov 15, 2017
    @ipwx
    @enrolls
    @zhusimaji
    @bxtx999 感谢大家指点!
    About     Help     Advertise     Blog     API     FAQ     Solana     1421 Online   Highest 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 36ms UTC 17:05 PVG 01:05 LAX 10:05 JFK 13:05
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86