Search code examples
pythonline-breaks

Undesirable line break mysteriously appearing in a print() invocation


I'm printing some variables, like this:

print("First name:", first_name)
print("Last name:", last_name)
print("Password:", password)

The first two are displayed just fine but the last one is like this:

    Password:
    <the password>

Which is undesirable and inconsistent with the other ones, which is why I want it to look like this:

Password:<the password>

Using end="" did not help.


Solution

  • Managed to resolve the problem thanks to Samwise I used :

    password.splitlines()
    password = password[1]
    print("password:",password)
    

    David S method works fine too

    password = password.replace("\n","")
    print("password:",password)