Python ord() Function Guide

  1. The ord function is used to return the Unicode code point (an integer representation) of a specified character, which must be a string of length 1.
  2. If the character goes beyond the range of Unicode code points (0-1114111), a ValueError exception will be raised.
  3. The ord function only accepts a single character as a parameter, passing multiple characters or an empty string will result in a TypeError exception.
  4. The ord function can only accept parameters of type str. Passing any other type of parameter, such as int or float, will result in a TypeError exception.
  5. The ord function returns the Unicode code point of a character, not the character itself, so it returns an integer.
  6. The ord function cannot be directly applied to Chinese characters or other non-ASCII characters because their Unicode code points may exceed the ASCII range.
  7. If you need to convert a character to its ASCII value, you can use the ord function. If you need to convert an ASCII value to a character, you can use the chr function.
bannerAds