zoukankan      html  css  js  c++  java
  • python 总结之 repr函数

    repr:

    repr(object)

    Return a string containing a printable representation of an object. This is the same value yielded by conversions (reverse quotes). It is sometimes useful to be able to access this operation as an ordinary function. For many types, this function makes an attempt to return a string that would yield an object with the same value when passed to eval(), otherwise the representation is a string enclosed in angle brackets that contains the name of the type of the object together with additional information often including the name and address of the object. A class can control what this function returns for its instances by defining a __repr__() method.

    可以认为它能把一个对象转换成一个可打印的字符串,它特点是对于包含着转义字符的字符串,也能完整打印出来,例如

    l = [ 'cdxc3kx9bx1dx08x84MXr0!xd1xecx86xabx01', 'cwx1cx9ex08x05`x8fx9dfdxd0xbfS7x9dZx8f']

    直接 print l[i],就会出现乱码,原因是里面的元素含义转义字符

    这时候采用repr的函数,它就能完成地把转义字符也打印出来

    --------------------------我是测试输出结果的分隔线-----------------------------------------------------------------------

    l = [ 'cdxc3kx9bx1dx08x84MXr0!xd1xecx86xabx01', 'cwx1cx9ex08x05`x8fx9dfdxd0xbfS7x9dZx8f']

    printl[0]

    print repr(l[0])

    >>>
    cd胟?凪Xr0!鸯啱
    'cdxc3kx9bx1dx08x84MXr0!xd1xecx86xabx01'

  • 相关阅读:
    HTML5基础知识(1)--上标和下标文本
    jQuery基础--样式篇(5)
    jQuery基础--样式篇(4)
    jQuery基础--样式篇(3)
    jQuery基础--样式篇(2)
    jQuery基础--样式篇(1)
    使用D3绘制图表(7)--饼状图
    使用D3绘制图表(6)--竖直柱状图表
    安装Centos 7 错误解决
    linux下搭建LAMP
  • 原文地址:https://www.cnblogs.com/tanliyu/p/4933752.html
Copyright © 2011-2022 走看看