• python '%r'或者'{!r}'的意思


    转载:https://blog.csdn.net/a19990412/article/details/80149112

    这两个都是python的转译字符, 类似于%r, %d,%f

    >>> a = '123'
    >>> b = 'hello, {!r}'.format(a)
    >>> b
    "hello, '123'"
    
    上面的例子用的是format,跟直接%效果类似。
    
    
    
    
    >>> a = '123'
    >>> b = 'hello, %r' % a
    >>> b
    "hello, '123'"
    
    这对一部分的对象还是很有用的。r直接反应对象本体。
    
    
    
    
    
    
    >>> a = '123'
    >>> b = 'hello, %r' % a
    >>> b
    "hello, '123'"
    
    123的本体就是123。
    
    
    
    
    
    >>> b = 'hello, !r' % '123'
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: not all arguments converted during string formatting
    >>>
    --------------------- 
    
    !符号,这个只在fromat中有用,要注意方法。但是效果类似
    >>> b = 'hello, %r' % '123'
    >>> b
    "hello, '123'"
    >>> b = 'hello, {!r}'.format( '123')
    >>> b
    "hello, '123'"
    

    更多操作有时间的话就去挖掘~

  • 相关阅读:
    poj2886 Who Gets the Most Candies?
    poj1201 Intervals
    poj3109 Inner Vertices
    poj1990 MooFest
    poj3368 Frequent values
    NOIP练习赛题目6
    NOIP练习赛题目5
    NOIP练习赛题目4
    NOIP练习赛题目3
    NOIP练习赛题目2
  • 原文地址:https://www.cnblogs.com/baxianhua/p/10769958.html
Copyright © 2020-2023  润新知