Why does it remain a space between Ste and !? How can I eliminate it, without using a difficult function?
a = input("Enter a name: ")
Enter a name: Ale
print("Hello,", a, "!")
Hello, Ste !
Why does it remain a space between Ste and !? How can I eliminate it, without using a difficult function?
a = input("Enter a name: ")
Enter a name: Ale
print("Hello,", a, "!")
Hello, Ste !
By default, print
separates each of its arguments with a space. You can change it by specifying the sep
parameter with something else, including an empty string. This should work:
print("Hello, ", a, "!", sep="")
=> Hello, Ale!
Comma ,
by default leaves a space after a string. You can try using +
:
print("Hello, " + a + "!")
=>Hello, Ste!
Use the strip function to cut the space at the initial and end of the string.
print("Hello,", a.strip(), "!", sep="")