0

x = "hello!"?

x = "hello!" for i in range(0, len(x)-1: prin(x(i)) x equals a string hello. len(x)-1 means to count from the -1 (second to last index), so why it printed the whole string is beyond me. Any ideas? As always, any help appreciated.

11th Apr 2019, 9:03 PM
tristach605
tristach605 - avatar
3 Respuestas
+ 3
x = "hello!" for i in range(0, len(x)-1): # "i" takes the values from 0 to 4 -> range(0, 5) print(x[i]) # x[0], x[1], x[2], x[3], x[4]
11th Apr 2019, 10:54 PM
Diego
Diego - avatar
+ 1
Thanks, Jay:). Could you explain how I was to know that? For range 0 len means I should be printing the length, no?
11th Apr 2019, 10:13 PM
tristach605
tristach605 - avatar
0
Thanks, Diego! I also see that I missed the exclamation point "!" (at the end). Thus some of the confusion.
12th Apr 2019, 9:22 PM
tristach605
tristach605 - avatar