0

I am curious

How can I make this code print (("ni"*3)+("!")) result in a ni ni ni! and ni! ni! ni!

24th Mar 2021, 11:20 AM
Vladislav Umanets
Vladislav Umanets - avatar
5 Answers
+ 4
print(("ni!\n")*3)
24th Mar 2021, 12:05 PM
iTech
iTech - avatar
+ 2
use a newline character '\n' print("Tom\nand\nJerry") #output Tom and Jerry
24th Mar 2021, 11:26 AM
Slick
Slick - avatar
+ 2
Slick your solution works, but output an unexpected blank line at the end if you doesn't specify end="" as named optional argument to the print statement ^^ Jan Markus solution might be the most 'pythonic' way, as he unpack a list of 3 items and explicitly set sep="\n" as optional separator named argument (instead of default one space string)
24th Mar 2021, 1:21 PM
visph
visph - avatar
0
iTech thanks, I see now, I have to put \n after “ni!”
24th Mar 2021, 12:09 PM
Vladislav Umanets
Vladislav Umanets - avatar
0
hahaha okay buddy Vladislav Umanets
24th Mar 2021, 12:14 PM
Slick
Slick - avatar