TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

Python ASCII Value of Character

Python ASCII Value of Charcter for beginners and professionals with programs on basics, controls, loops, functions, native data types etc.

<< Back to PYTHON

Python Program To Find ASCII value of a character

In this tutorial, we will learn how to find the ASCII value of a character and display the result.

ASCII: ASCII is an acronym that stands for American Standard Code for Information Interchange. A specific numerical value is given to different characters and symbols for computers to store and manipulate in ASCII.

It is case sensitive. The same character, having different formats (upper case and lower case), has a different value. For example, The ASCII value of "A" is 65 while the ASCII value of "a" is 97.

Example 1:

K = input("Please enter a character: ")  
  
print ("The ASCII value of '" + K + "' is ", ord(K))

Output:

1#

Please enter a character: J
The ASCII value of 'J' is 74

2#

Please enter a character: $
The ASCII value of '$' is 36

In the above code, we have used the ord() function for converting a character into an integer, that is, ASCII value. This function is used to return the Unicode code point of the given character.

Example 2:

print ("Please enter the String: ", end = "")
string = input()
string_length = len(string)
for K in string:
    ASCII = ord(K)
    print (K, "\t", ASCII)

Output:

Please enter the String: 
 "JavaTpoint#
" 	 34
J 	 74
a 	 97
v 	 118
a 	 97
T 	 84
p 	 112
o 	 111
i 	 105
n 	 110
t 	 116
# 	 35

Unicode is also an encoding technique which is used for getting the unique number of the character. Though ASCII can only encode 128 characters, whereas the current Unicode can encode more than 100,000 characters from hundreds of scripts.

We can also convert the ASCII value into their corresponding character value. For that, we have to use the chr() in place of ord() in the above code.

Example 3:

K = 21  
J = 123
R = 76
print ("The character value of 'K' ASCII value is: ", chr(K))  
print ("The character value of 'J' ASCII value is: ", chr(J))  
print ("The character value of 'R' ASCII value is: ", chr(R))

Output:

The character value of 'K' ASCII value is: 
The character value of 'J' ASCII value is: {
The character value of 'R' ASCII value is: L

Conclusion

In this tutorial, we have discussed how a user can convert character value into ASCII value and also how they can get the character value of the given ASCII value.






Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf