Write a Python program to find ASCII Value of Total Characters in a String with a practical example.
Python program to find ASCII Value of Total Characters in a String 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 String article to understand everything about Strings. And also refer to the ASCII table article in Python to understand ASCII values.
# Python program to find ASCII Values of Total Characters in a String 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 get 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 For Loop with While Loop.
# Python program to find ASCII Values of Total Characters in a String 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
Python 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