Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

I am so confused. I instructor did not really explain this code ---> end=' '.

I hope the instructor explain the code block on how to print spaces and strikes.

4 Answers

Christian Mangeng
Christian Mangeng
15,970 Points

You can use this command within the print() function to define what follows after the printout. By default, print("hello") will output a newline element after "hello", which is the same as print("hello", end="\n"). If you only want a space after "hello", you can do that with print("hello", end=" "). Using print("hello", end="") does not output any space after "hello".

Thanks Christian! However, is "end" a keyword in Python? Also, why do we need to include it in our code when we can add a space after hello? Say, print("Hello "). Can't we also do print("Hello\n") ?

Christian Mangeng
Christian Mangeng
15,970 Points

1) The end="" statement is part of the print() function.

2) If you added a space or newline directly after the word hello, it would be included in the string. This would change the actual string, which you usually do not want.

I now totally understand! Thank you very much Christian!