Change language

Unicodedata — Python Unicode database

| |

Functions defined by the module:

  • unicodedata.lookup (name)
    This function looks for a character by name. If a symbol with the given name is found in the database, then the corresponding symbol is returned, otherwise a Keyerror is thrown.

    Example:

    import unicodedata

     

    print unicodedata.lookup ( ’LEFT CURLY BRACKET’ )

    print unicodedata.lookup ( ’ RIGHT CURLY BRACKET’ )

    print unicodedata .lookup ( ’ASTERISK’ )

      
    # gives error as is
    # no symbol named ASTRA
    # print unicodedata.lookup (& # 39; ASTER & # 39;)

    Output:

     {} * 
  • unicodedata.name (chr [, default])
    This function returns the name assigned to the given character as a string. If no name is specified, the function returns a default value, otherwise a ValueError is thrown if no name is specified.

    Example:

    import unicodedata

      

    print unicodedata.name (u ’/’ )

    print unicodedata.name (u ’|’ )

    print unicodedata. name (u ’:’ )

    Output:

     SOLIDUS VERTICAL LINE COLON 
  • unicodedata.decimal (chr [, by default])
    This function returns the decimal value assigned to the given character as an integer. If no value is specified, the function returns the default value, otherwise ValueError is raised if no value is specified.

    Example:

    import unicodedata

      

    print unicodedata.decimal (u ’9’ )

    print unicodedata.decimal (u ’a’ )

    Output:

     9 Traceback (most recent call last): File "7e736755dd176cd0169eeea6f5d32057.py", line 4, in print unicodedata.decimal (u’a’) ValueError: not a decimal 
  • unicodedata.digit (chr [, default])
    This function returns the numeric value assigned to the given character as an integer. If no value is specified, the function returns the default value, otherwise ValueError is raised if no value is specified.

    Example:

    import unicodedata

     

    print unicodedata.decimal (u ’9’ )

    print unicodedata.decimal (u ’143’ )

    Output:

     9 Traceback (most recent call last): File "ad47ae996380a777426cc1431ec4a8cd.py", line 4, in print unicodedata. decimal (u’143’) TypeError: need a single Unicode character as parameter 
  • un icodedata.numeric (chr [, default])
    This function returns the numeric value assigned to the given character as an integer. If no value is specified, the function returns the default value, otherwise ValueError is raised if no value is specified.

    Example:

    import unicodedata

      

    print unicodedata.decimal (u ’9’ )

    print unicodedata.decimal (u ’143’ )

    Output:

     9 Traceback (most recent call last): File "ad47ae996380a777426cc1431ec4a8cd.py", line 4, in print unicodedata.decimal (u’143’) TypeError: need a single Unicode character as parameter 
  • unicodeda ta.category (CHR)
    This function returns the general category assigned to the given character as a string. For example, it returns L for a letter and U for uppercase letters.

    Example:

    import unicodedata

     

    print unicodedata.category (u ’A’ )

    print unicodedata.category (u ’b’ )

    Output:

     Lu Ll 
  • unicodedata.bidirectional (CHR)
    This function returns a bi-directional class assigned to the given character as a string. For example, it returns "A" for Arabic and "N" for number. This function returns an empty string if no such value is defined.

    Example:

    import unicodedata

     

    print unicodedata.bidirectional (u ’u0660’ )

    Output:

     AN 
  • unicodedata.normalize (form, uniform)
    This function returns the normal form form for a Unicr Unicode string. Valid values ​​for the form are NFC, NFKC, NFD, and NFKD.

    Example:

    from unicodedata import normalize

     

    print ’% r’ % normalize ( ’NFD’ , u ’u00C7’ )

    print ’% r’ % normalize ( ’NFC’ , u ’ Cu0327’ )

    print  ’% r’ % normalize ( ’ NFKD’ , u ’u2460’ )

    Output:

     u’Cu0327’ u’xc7’ u’1’ 

This article courtesy of Aditi Gupta . If you are as Python.Engineering and would like to contribute, you can also write an article using contribute.python.engineering or by posting the article [email protected] ... See my article appearing on the Python.Engineering homepage and help other geeks.

Please post comments if you find anything wrong or if you would like to share more information on the topic discussed above.

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

Common xlabel/ylabel for matplotlib subplots

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

12 answers

NUMPYNUMPY

Flake8: Ignore specific warning for entire file

12 answers

NUMPYNUMPY

glob exclude pattern

12 answers

NUMPYNUMPY

How to avoid HTTP error 429 (Too Many Requests) python

12 answers

NUMPYNUMPY

Python CSV error: line contains NULL byte

12 answers

NUMPYNUMPY

csv.Error: iterator should return strings, not bytes

12 answers


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

sin

How to specify multiple return types using type-hints

exp

Printing words vertically in Python

exp

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

cos

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically