Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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]}")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading