Search code examples
python

what is the meaning of index[",i,"] in a loop?


what is the meaning of this part of my code?

my code haven't any problem but i wanna know what is the meaning of this part of my code:) thank you!

orginalString = input("enter the word: ")
print("orginal string:", orginalString)
size = len(orginalString)
print("printing only even index chars")
for i in range(0, size, 2):
    print("index[", i,"]", orginalString[i])

i wanna know why we should put i like this there? and what does it mean?


Solution

  • Every comma in a print statement creates a separator in the line.

    If you want cleaner formatting, use f-strings

    print(f"index[{i}] {originalString[i]}")