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
Birinder Jagdev
1,668 PointsHow to output each letter inline using print() ?
Following code prints:
Y
E
S
Code
banner = "yes"
for letter in banner:
print(letter.upper())
Is there some other print function in python to print inline and not add a new line every time ?
YES
1 Answer
Steven Parker
243,318 PointsYou can use the same function, just pass the optional argument that allows you to specify what it does at the end.
By default it adds a newline, but you can tell it not to:
print(letter.upper(), end="")
You'll probably want to use an extra "print" after the loop to get a newline. For more details, on the optional arguments, see the documentation page for "print".
Also, did you know that the "upper" function can be used on an entire string? The loop isn't necessary here:
banner = "yes"
print(banner.upper())
Birinder Jagdev
1,668 PointsBirinder Jagdev
1,668 PointsThanks for the great answer @Steven. Next time I'll remember to check documentation first. :)