Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Python Tutorial
  • Interview Questions
  • Python Quiz
  • Python Glossary
  • Python Projects
  • Practice Python
  • Data Science With Python
  • Python Web Dev
  • DSA with Python
  • Python OOPs
Open In App
Next Article:
Convert Unicode to Bytes in Python
Next article icon

Unicodedata – Unicode Database in Python

Last Updated : 19 Nov, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report

Unicode Character Database (UCD) is defined by Unicode Standard Annex #44 which defines the character properties for all unicode characters. This module provides access to UCD and uses the same symbols and names as defined by the Unicode Character Database.

Functions defined by the module :

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

    Example :




    import unicodedata
       
    print (unicodedata.lookup('LEFT CURLY BRACKET'))
    print (unicodedata.lookup('RIGHT CURLY BRACKET'))
    print (unicodedata.lookup('ASTERISK'))
      
    # gives error as there is 
    # no symbol called ASTER
    # print (unicodedata.lookup('ASTER'))
     
     

    Output :

      {  }  *  
  • unicodedata.name(chr[, default])
    This function returns the name assigned to the given character as a string. If no name is defined, default is returned by the function otherwise ValueError is raised if name is not given.

    Example :




    import unicodedata
       
    print (unicodedata.name(u'/'))
    print (unicodedata.name(u'|'))
    print (unicodedata.name(u':'))
     
     

    Output :

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

    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 digit value assigned to the given character as integer. If no value is defined, default is returned by the function otherwise ValueError is raised if value is not given.

    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  
  • unicodedata.numeric(chr[, default])
    This function returns the numeric value assigned to the given character as integer. If no value is defined, default is returned by the function otherwise ValueError is raised if value is not given.

    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  
  • unicodedata.category(chr)
    This function returns the general category assigned to the given character as string. For example, it returns ‘L’ for letter and ‘u’ for uppercase.

    Example :




    import unicodedata
       
    print (unicodedata.category(u'A'))
    print (unicodedata.category(u'b'))
     
     

    Output :

      Lu  Ll  
  • unicodedata.bidirectional(chr)
    This function returns the bidirectional class assigned to the given character as string. For example, it returns ‘A’ for arabic and ‘N’ for number. An empty string is returned by this function if no such value is defined.

    Example :




    import unicodedata
       
    print (unicodedata.bidirectional(u'\u0660'))
     
     

    Output :

      AN  
  • unicodedata.normalize(form, unistr)
    This function returns the normal form for the Unicode string unistr. Valid values for form are ‘NFC’, ‘NFKC’, ‘NFD’, and ‘NFKD’.

    Example :




    from unicodedata import normalize
       
    print ('%r' % normalize('NFD', u'\u00C7'))
    print ('%r' % normalize('NFC', u'C\u0327'))
    print ('%r' % normalize('NFKD', u'\u2460'))
     
     

    Output :

      u'C\u0327'  u'\xc7'  u'1'  


Next Article
Convert Unicode to Bytes in Python

A

Aditi Gupta
Improve
Article Tags :
  • Python
  • Python-Library
Practice Tags :
  • python

Similar Reads

  • Python Database Tutorial
    Python being a high-level language provides support for various databases. We can connect and run queries for a particular database using Python and without writing raw queries in the terminal or shell of that particular database, we just need to have that database installed in our system. In this t
    4 min read
  • Convert Unicode to Bytes in Python
    Unicode, often known as the Universal Character Set, is a standard for text encoding. The primary objective of Unicode is to create a universal character set that can represent text in any language or writing system. Text characters from various writing systems are given distinctive representations
    2 min read
  • Convert Unicode to ASCII in Python
    Unicode is the universal character set and a standard to support all the world's languages. It contains 140,000+ characters used by 150+ scripts along with various symbols. ASCII on the other hand is a subset of Unicode and the most compatible character set, consisting of 128 letters made of English
    2 min read
  • Working with Unicode in Python
    Unicode serves as the global standard for character encoding, ensuring uniform text representation across diverse computing environments. Python, a widely used programming language, adopts the Unicode Standard for its strings, facilitating internationalization in software development. This tutorial
    3 min read
  • How To Print Unicode Character In Python?
    Unicode characters play a crucial role in handling diverse text and symbols in Python programming. This article will guide you through the process of printing Unicode characters in Python, showcasing five simple and effective methods to enhance your ability to work with a wide range of characters Pr
    2 min read
  • Convert Unicode String to a Byte String in Python
    Python is a versatile programming language known for its simplicity and readability. Unicode support is a crucial aspect of Python, allowing developers to handle characters from various scripts and languages. However, there are instances where you might need to convert a Unicode string to a regular
    2 min read
  • Convert Unicode String to Dictionary in Python
    Python's versatility shines in its ability to handle diverse data types, with Unicode strings playing a crucial role in managing text data spanning multiple languages and scripts. When faced with a Unicode string and the need to organize it for effective data manipulation, the common task is convert
    2 min read
  • unicode_literals in Python
    Unicode is also called Universal Character set. ASCII uses 8 bits(1 byte) to represents a character and can have a maximum of 256 (2^8) distinct combinations. The issue with the ASCII is that it can only support the English language but what if we want to use another language like Hindi, Russian, Ch
    3 min read
  • How to Urlencode a Querystring in Python?
    URL encoding a query string consists of converting characters into a format that can be safely transmitted over the internet. This process replaces special characters with a '%' followed by their hexadecimal equivalent. In this article, we will explore three different approaches to urlencode a query
    2 min read
  • html.unescape() in Python
    With the help of html.unescape() method, we can convert the ascii string into html script by replacing ascii characters with special characters by using html.escape() method. Syntax : html.unescape(String) Return : Return a html script. Example #1 : In this example we can see that by using html.unes
    1 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences