Python Forum
For loop question - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: For loop question (/thread-9040.html)



For loop question - peejj - Mar-18-2018

Hi, Im new to the community so please correct my first post if needed. Could anyone explain why the result for A occured compared B's result? Visually its obvious but its hard just interpreting it by words. Any help?

A
def main():
   name = input("enter name: ")
   for i in name:
           print(i, end="")
main()


RESULT:
Output:
enter name: francisco francisco
B
def main():
   name = input("enter name: ")
   for i in name:
           print(name, end="")

main()  


RESULT
Output:
enter name: francisco franciscofranciscofranciscofranciscofranciscofranciscofranciscofranciscofrancisco



RE: For loop question - stranac - Mar-18-2018

In your first code, for each letter of the name, you print that letter.
In the second code, for each letter of the name, you print the entire name.