I always want to know what is the total value of all the ASCII values of characters in the Hello World string. In order to get the ASCII value of a character, I will use the Python ord method to find it out. I will loop through each character in the Hello World string using the for loop and then sum up their ASCII values as follows:-
total = 0 for a in "Hello World": total+=ord(a) print(total) # 1052
Not a very interesting figure indeed, maybe you can start your first Python program with another string that when summing up all the ASCII values of its characters will produce an interesting number instead!
A more pythonic solution:
total = sum(ord(char) for char in “Hello World”)
print(total)