DEV Community

Discussion on: Python print() and beyond

Collapse
ntchambers profile image
Nicholas Chambers

In section 2, you have the following snippet:

print("Hello James", end="y\n")
print("How are you doing", end="\n")
Enter fullscreen mode Exit fullscreen mode

which you say outputs:

Hello Jamesy
How are you doingy
Enter fullscreen mode Exit fullscreen mode

Shouldn't the snippet instead be:

print("Hello James", end="y\n")
print("How are you doing", end="y\n")
Enter fullscreen mode Exit fullscreen mode
Collapse
josiasaurel profile image
Josias Aurel Author • Edited on

In this case, I wanted every line to end with a y character rather than a y character on a newline.
Anyways, playing around with those will help grasp it better.

Collapse
ntchambers profile image
Nicholas Chambers • Edited on

Yes, that's my point. Your code currently does not end every line with a y.

~ 🌲 python3
Python 3.9.0 (default, Nov 30 2020, 15:21:09)
[Clang 12.0.0 (clang-1200.0.32.27)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> print("Hello James", end="y\n")
Hello Jamesy
>>> print("How are you doing", end="\n")
How are you doing
Enter fullscreen mode Exit fullscreen mode

Your end for the second print is just \n. It is missing a y in it.

Thread Thread
josiasaurel profile image
Josias Aurel Author

You'll have to include the end="y" un every print statement . In the second print statement you wrote, you didn't include the end="y" and that's why you didn't get the y at the end of it.

Thread Thread
ntchambers profile image
Nicholas Chambers

I'm aware. This is your code, not mine. Your code does not currently include end="y\n" for the second line, just end="\n". However, you then show output with every line ending in a y: i.imgur.com/haIqpYx.png

Thread Thread
josiasaurel profile image
Josias Aurel Author

Oh thanks 🤦 I hadn't notice it . I'm really sorry for this

Thread Thread
ntchambers profile image
Nicholas Chambers

No problem! Happy to help!