ord() function in Python Last Updated : 27 Apr, 2025 Comments Improve Suggest changes Like Article Like Report Python ord() function returns the Unicode code of a given single character. It is a modern encoding standard that aims to represent every character in every language.Unicode includes:ASCII characters (first 128 code points)Emojis, currency symbols, accented characters, etc.For example, unicode of 'A' = 65 and '€' = 8364. Let's look at a code example of ord() function: Python print(ord('a')) print(ord('€')) Output97 8364 Explanation:ord() function returns the unicode of the character passed to it as an argument.unicode of 'a' = 97 and '€' = 8364.Syntaxord(ch)Parameter: ch: A single Unicode character (string of length 1).Return type: it returns an integer representing the Unicode code point of the character.Examples of ord() FunctionExample 1: Basic Usage of ord()In this example, We are showing the ord() value of an integer, character, and unique character with ord() function in Python. Python print(ord('2')) print(ord('g')) print(ord('&')) Output50 103 38 Note: If the string length is more than one, a TypeError will be raised. The syntax can be ord("a") or ord('a'), both will give the same results. The example is given below.Example 2: Exploring ord() with Digits and SymbolsThis code shows that ord() value of "A" and 'A' gives the same result. Python v1 = ord("A") v2 = ord('A') print (v1, v2) Output65 65Example 3: String Length > 1 Causes ErrorThe ord() function only accepts a single character. If the string length is more than 1, a TypeError will be raised. Python print(ord('AB')) Output:Traceback (most recent call last): File "/home/f988dfe667cdc9a8e5658464c87ccd18.py", line 6, in value1 = ord('AB')TypeError: ord() expected a character, but string of length 2 foundExample 4: Using Both ord() and chr()chr() function does the exact opposite of ord() function, i.e. it converts a unicode integer into a character. Let's look at an example: Python v= ord("A") print (v) print(chr(v)) Output65 A Related articles:chr() methodunicodeASCII Comment More infoAdvertise with us Next Article ord() function in Python S Striver Follow Improve Article Tags : Misc Python Python-Built-in-functions python Practice Tags : Miscpythonpython Similar Reads Python - globals() function In Python, the globals() function is used to return the global symbol table - a dictionary representing all the global variables in the current module or script. It provides access to the global variables that are defined in the current scope. This function is particularly useful when you want to in 2 min read Python hash() method Python hash() function is a built-in function and returns the hash value of an object if it has one. The hash value is an integer that is used to quickly compare dictionary keys while looking at a dictionary.Python hash() function SyntaxSyntax : hash(obj)Parameters : obj : The object which we need t 6 min read hex() function in Python hex() function in Python is used to convert an integer to its hexadecimal equivalent. It takes an integer as input and returns a string representing the number in hexadecimal format, starting with "0x" to indicate that it's in base-16. Example:Pythona = 255 res = hex(a) print(res)Output0xff Explanat 2 min read id() function in Python In Python, id() function is a built-in function that returns the unique identifier of an object. The identifier is an integer, which represents the memory address of the object. The id() function is commonly used to check if two variables or objects refer to the same memory location. Python id() Fun 3 min read Python 3 - input() function In Python, we use the input() function to take input from the user. Whatever you enter as input, the input function converts it into a string. If you enter an integer value still input() function converts it into a string.Python input() Function SyntaxSyntax: input(prompt)Parameter:Prompt: (optional 3 min read Python int() Function The Python int() function converts a given object to an integer or converts a decimal (floating-point) number to its integer part by truncating the fractional part.Example:In this example, we passed a string as an argument to the int() function and printed it.Pythonage = "21" print("age =", int(age) 3 min read Python len() Function The len() function in Python is used to get the number of items in an object. It is most commonly used with strings, lists, tuples, dictionaries and other iterable or container types. It returns an integer value representing the length or the number of elements. Example:Pythons = "GeeksforGeeks" # G 2 min read Python map() function The map() function is used to apply a given function to every item of an iterable, such as a list or tuple, and returns a map object (which is an iterator). Let's start with a simple example of using map() to convert a list of strings into a list of integers.Pythons = ['1', '2', '3', '4'] res = map( 4 min read Python - max() function Python max() function returns the largest item in an iterable or the largest of two or more arguments. It has two forms. max() function with objectsmax() function with iterablePython max() function With ObjectsUnlike the max() function of C/C++, the max() function in Python can take any type of obje 4 min read memoryview() in Python The memoryview() function in Python is used to create a memory view object that allows us to access and manipulate the internal data of an object without copying it. This is particularly useful for handling large datasets efficiently because it avoids the overhead of copying data. A memory view obje 5 min read Like