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.
3 Antworten
+ 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]
+ 1
Thanks, Jay:). Could you explain how I was to know that? For range 0 len means I should be printing the length, no?
0
Thanks, Diego! I also see that I missed the exclamation point "!" (at the end). Thus some of the confusion.