+ 1

how to get output (hello! world! spam! eggs!)

words = ["hello", "world", "spam", "eggs"] for word in words: print(word + "!") #how to get output (hello! world! spam! eggs!)

1st Mar 2024, 9:20 AM
Amirhossein Ghannad
7 Answers
+ 3
print accepts a keyword argument 'end'. It is defaulted to end='\n'. you can change it to end='! ' to use ! instead and prevent printing to new lines. words = ["hello", "world", "spam", "eggs"] for word in words: print(word, end='! ')
1st Mar 2024, 10:06 AM
Bob_Li
Bob_Li - avatar
+ 4
Are you missing a space between each word?
1st Mar 2024, 1:21 PM
Ausgrindtube
Ausgrindtube - avatar
+ 1
print (' "hello","word","spam","eggs" ')
1st Mar 2024, 7:59 PM
Yasmine
Yasmine - avatar
+ 1
Bob_Li words = ["hello", "world", "spam", "eggs"] print(' '.join(word+'!' for word in words))
3rd Mar 2024, 3:04 PM
Amirhossein Ghannad
+ 1
Amir Ghannad great idea. Here is a variation: print('! '.join(words)+'!')
3rd Mar 2024, 3:16 PM
Bob_Li
Bob_Li - avatar
0
for word in words: words = word + "!" print(words) Try this it is expected you create a variable for the new words you want
3rd Mar 2024, 2:34 AM
Shadrach Gowon Ogwuche
Shadrach Gowon Ogwuche - avatar
0
hide
9th Mar 2024, 6:25 AM
Scooby Cookie
Scooby Cookie - avatar