+ 1

word=input('Enter a word');Enter a word:cheese;print(word+'shop') why space comes in between cheese nd shop

21st Aug 2017, 2:06 AM
Balkrishan
6 odpowiedzi
+ 7
Space doesnt come in b/w cheese and shop unless you enter 'cheese ' as the input.
21st Aug 2017, 2:15 AM
Pixie
Pixie - avatar
+ 4
Cheese Shop
4th Apr 2019, 11:25 AM
johan
johan - avatar
+ 3
If you want to make sure that there is no white space before or after the word that is entered you can use the str.strip() method. print(word.strip() + 'shop') You could also use it chained to the input function, since it returns a string. word=input('Enter a word').strip() There is also a left strip which only removes white space on the left of the string, and right strip which removes white space on the right of the string. lstrip() rstrip()
21st Aug 2017, 2:30 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
Ans cheee shop
30th Aug 2018, 3:32 PM
Ammar Muhammad Abubakar
Ammar Muhammad Abubakar - avatar
+ 1
cheese shop
11th Jul 2020, 8:08 AM
Хүлэгү
Хүлэгү - avatar
0
I got struggled in that too. It has nothing to do with input, they made a trick. It was written print(word + ' shop'), if you look carefully, you will notice the space BEFORE shop
11th Jun 2018, 8:14 AM
Ayberk Kaan Güneş
Ayberk Kaan Güneş - avatar