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 purpose of the end=" " argument to print?

I am an online IT student and in my Python application development class we look at a coding example. Basically the code converts the characters of a string into their ordinal values:

for ch in message:
        print(ord(ch),    end=" ")

My question is what the purpose of the end=" " part is as this is never explained in the textbook. It may not be that important, but it bothers me having a part that I do not understand. Any help is much appreciated.

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 :

Here is an article that explains it for you
https://www.w3schools.com/python/ref_func_print.asp

in short, it specifies what you want your print statement to end in.

ie print("Hello world", end=", stack overflow") returns Hello world, stack overflow

in python, you do not need to specify it as the default is \n

so the below is fine

for ch in message:
        print(ord(ch))
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