Detailed explanation of Python ord function of case

  • 2021-11-29 08:04:07
  • OfStack

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 to get 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, which is used 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: character-The character value to convert to an integer value.

Return value: str-returns an integer value of given character.

Return value: str-Returns the integer value of the given character.

Example:

Example:


Input:
val = 'A'
print(ord(val))

Output:
65

Python code to convert a character into an integer (ASCII value)

Python codes convert 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

ASCII code of  A  is =  65

ASCII code of  x  is =  120

ASCII code of  @  is =  64

ASCII code of  8  is =  56


Related articles: