Quantcast
Channel: Planet Python
Viewing all articles
Browse latest Browse all 22871

IslandT: Python Example — What is the total ASCII values of characters in the Hello World string

$
0
0

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!


Viewing all articles
Browse latest Browse all 22871

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>