@yeskaydeee To demonstrate what is happening behind the scenes, I have inserted ‘A’ at the start and ‘B’ at the end of the same string.
You can observe from my output that we do not have a colon at the start and also we do not have a colon in the next line when ‘B:’ ends. So, what’s happening?
A string is a list. In your case, the very first character (at index 0) and the very last character stored in the string is not ‘H’ and ‘s’ respectively, but a newline character ‘\n’. So, what does a newline character do? As its name suggests it takes the cursor to a new line. Our program will treat it as a character just like it treats ‘a’, ‘b’, ‘c’ or ‘d’. The difference comes when it will be printed. You can see ‘a’ but you can’t see a newline character unless you have a frame of reference.
So, in your program, a newline character is printed first which essentially means your print cursor moves to a new line, then a colon is printed as we have explicitly mentioned that after printing each character, end with a colon (end=’:’). After that ‘H’ is printed and ends with a colon. Therefore, we get ‘:H:’. The same process repeats till we print ‘s:’. After that our program encounters a newline character again which is the last character in our string, prints that (takes us to a new line) and then prints the colon and finally comes out of the loop.
In my case, ‘A’ and ‘B’ are respectively the very first and very last characters in the string. Now, you can make out the difference.
I hope it helps!