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


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com



    Post your comments , suggestion , error , requirements etc here





    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer