ord()
ord() Unicode point of input char
ord() takes input char of single length.
returns Unicode point value of input Char.
Here are some sample outputs of single input string ( output is shown against each row after comment )
print(ord('a')) # 97
print(ord('b')) # 98
print(ord('P')) # 80
print(ord('#')) # 35
print(ord('$')) # 36
The first 128 unicode point values are same as ASCII values.
If we input more than one char then it will return error.
print(ord('ab'))
TypeError: ord() expected a character, but string of length 2 found
Sample Script
Converts any lower case char to upper case char ( without using any built-in string functions )
str='Welcome to Python'
for i in str:
k=ord(i) # ASCII value of i
if (k >=97 and k<=122):
print(chr(k-32),end='')
else:
print(i,end='')
Output
WELCOME TO PYTHON
«All Built in Functions in Python
chr() returns the char by taking the Unicode point value
ascii()
← Subscribe to our YouTube Channel here
This article is written by plus2net.com team.
https://www.plus2net.com
plus2net.com