Write a Python program to find ASCII Value of Total Characters in a String with a practical example.
This python program allows the user to enter a string. Next, it prints the characters inside this string using For Loop. Here, we used For Loop to iterate each character in a String. Inside the For Loop, we used print function to return ASCII values of all the characters inside this string.
TIP: Please refer to the Python String article to understand everything about Strings. And also refer to the ASCII table article from the Learn Python page to understand ASCII values.
str1 = input("Please Enter your Own String : ")
for i in range(len(str1)):
print("The ASCII Value of Character %c = %d" %(str1[i], ord(str1[i])))

Python program to find ASCII Value of Total Characters in a String Example 2
This ASCII Values Python program is the same as the above. However, we just replaced the Python for loop with Python while Loop.
str1 = input("Please Enter your Own String : ")
i = 0
while(i < len(str1)):
print("The ASCII Value of Character %c = %d" %(str1[i], ord(str1[i])))
i = i + 1
The ASCII Value of String Characters output
Please Enter your Own String : Hello
The ASCII Value of Character H = 72
The ASCII Value of Character e = 101
The ASCII Value of Character l = 108
The ASCII Value of Character l = 108
The ASCII Value of Character o = 111
Also Read