{"id":24573,"date":"2021-10-22T09:08:52","date_gmt":"2021-10-22T03:38:52","guid":{"rendered":"https:\/\/python-programs.com\/?p=24573"},"modified":"2021-11-05T19:39:16","modified_gmt":"2021-11-05T14:09:16","slug":"python-ord-function-with-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-ord-function-with-examples\/","title":{"rendered":"Python ord() Function with Examples"},"content":{"rendered":"

In the previous article, we have discussed Python Program for round() Function<\/a>
\nord() Function in Python:<\/strong><\/p>\n

The ord() function returns a number that represents the Unicode code of a given character.<\/p>\n

Syntax:<\/strong><\/p>\n

ord(character)<\/pre>\n

Parameters<\/strong><\/p>\n

character:<\/strong> It is a Unicode character.<\/p>\n

Return Value:<\/strong><\/p>\n

The ord() function returns the Unicode character as an integer.<\/p>\n

Note:<\/strong> When the length of the string is not equal to one, a TypeError is thrown.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given character = '4'\r\nGiven character = '$'\r\nGiven character = 'd'<\/pre>\n

Output:<\/strong><\/p>\n

The integer representing the given Unicode character 4 =  52\r\nThe integer representing the given Unicode character $ = 36\r\nThe integer representing the given Unicode character d = 100<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given character = '0'\r\nGiven character = '@'\r\nGiven character = 'y'<\/pre>\n

Output:<\/strong><\/p>\n

The integer representing the given Unicode character 0 =  48\r\nThe integer representing the given Unicode character @ = 64\r\nThe integer representing the given Unicode character y = 121<\/pre>\n

Program for ord() Function in Python<\/h2>\n