看了一些网上的解释,最主流的解释是“str是给人看的,repr是给机器看的”,如果已经理解了的,这句话是对的,但是是有问题的,对于没懂的,这句话是无法理解的. 我来尝试解释一下.先直译一下官方文档: repr(object) Return a string containing a printable representation of an object. For many types, this function makes an attempt to return a string tha…
实例1: v1=u '好神奇的问题!?' type(v1)->unicode v1.decode("utf-8")# not work,because v1 is unicode already v1.encode("gb2312")#work,convert from unicode into gbk2312 [发现] decode是把指定的对象转化为unicode(unicode包含utf-8,utf-16),并且指明了待转化对象的编码方式. encode…