What does 'u' mean in a list?

前端 未结 4 1666
独厮守ぢ
独厮守ぢ 2020-11-29 11:09

This is the first time I\'ve came across this. Just printed a list and each element seems to have a u in front of it i.e.

[u\'hello\', u         


        
相关标签:
4条回答
  • 2020-11-29 11:27

    Unicode.

    0 讨论(0)
  • 2020-11-29 11:30

    it's an indication of unicode string. similar to r'' for raw string.

    >>> type(u'abc')
    <type 'unicode'>
    >>> r'ab\c'
    'ab\\c'
    
    0 讨论(0)
  • 2020-11-29 11:33

    I believe the u' prefix creates a unicode string instead of regular ascii

    0 讨论(0)
  • 2020-11-29 11:46

    The u just means that the following string is a unicode string (as opposed to a plain ascii string). It has nothing to do with the list that happens to contain the (unicode) strings.

    0 讨论(0)
提交回复
热议问题