Introduction and example usage of Python ord function ()
This article mainly explains the "introduction and example usage of Python ord function ()". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "the introduction and example usage of Python ord function ()".
Ord function in python
Python ord () function (Python ord () function)
Ord () function is a library function in Python, it is used to get number value from given character value, it accepts a character and returns an integer I.E. It is used to convert a character to an integer I. e. It is used to get the ASCII value of a given character.
The ord () function is a library function in Python that gets a numeric value from a given character value. It accepts a character and returns an integer, which is used to convert a character to an integer, that is, to get the value of a given character in ASCII.
Syntax:
Syntax:
Ord (character)
Parameter:character-character value to be converted in an integer value.
Parameter: the character value to be converted to an integer value by character-.
Return value: str-returns an integer value of given character.
Return value: str-returns the integer value of a given character.
Example:
Example:
Input:val = 'A'print (ord (val)) Output:65
Python code to convert a character into an integer (ASCII value)
Python code converts characters to integers (ASCII values)
# python code to demonstrate an example# of ord () function val = 'A'print ("ASCII code of", val, "is =", ord (val)) val =' x'print ("ASCII code of", val, "is =", ord (val)) val ='@ 'print ("ASCII code of", val, "is =", ord (val) val =' 8'print ("ASCII code of", val, "is =", ord (val))
Output
Output quantity
ASCII code of An is = 65
ASCII code of x is = 120
ASCII code of @ is = 64
ASCII code of 8 is = 56
Thank you for your reading, the above is the content of "introduction and example usage of Python ord function ()". After the study of this article, I believe you have a deeper understanding of the introduction and example usage of Python ord function (), and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!