Advertisement
HasteBin0

Python str() Unicode

May 30th, 2022 (edited)
714
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.29 KB | None | 0 0
  1. uc=lambda s: ', '.join('U+' + hex(ord(x))[2:].upper() for x in s)  # uc for unicode
  2. uc('')
  3. ''
  4. uc('a')
  5. 'U+61'
  6. uc('ab')
  7. 'U+61, U+62'
  8. uc('abc🐉🌄🌇👋')
  9. 'U+61, U+62, U+63, U+1F409, U+1F304, U+1F307, U+1F44B'
  10. str.uc=uc  # TypeError: cannot set 'uc' attribute of immutable type 'str'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement