Why output ends with 'None'? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why output ends with 'None'?

def concatenate(*args): for i in args: i += "-" print(i, end="") print(concatenate("I", "love", "Python", "!"))

8th Aug 2022, 6:55 PM
Josué Varela
Josué Varela - avatar
13 Answers
+ 6
Because you are actually printing a seal 😉: print(print()) You just need: concatenate("I", "love", "Python", "!")
8th Aug 2022, 7:43 PM
Solo
Solo - avatar
+ 8
Your function does not return anything, that's why it prints None. Either replace the print() in the function with return or remove the last print.
8th Aug 2022, 6:58 PM
Lisa
Lisa - avatar
+ 3
either construct a new string to return or remove the last print...
8th Aug 2022, 7:15 PM
Lisa
Lisa - avatar
+ 2
It is that if I change the print for the return it does not return the complete concatenation :(
8th Aug 2022, 7:07 PM
Josué Varela
Josué Varela - avatar
+ 2
It is possible to write this function without using a loop ☺️
8th Aug 2022, 8:04 PM
Solo
Solo - avatar
+ 2
''' Oro Collares you can use the sep parameter of print. ''' #use directly print('I', 'love','python', sep='-') #use inside a function def hypenate(*args): print(*args, sep='-') hypenate('print','is','a','function') #if you want a string return value def add_hypen(*args): return '-'.join(args) print(add_hypen('This','also','works'))
10th Aug 2022, 5:26 PM
Bob_Li
Bob_Li - avatar
+ 2
Bob_Li Thanks!!, i learn quite a lot with community interaction 🥰
10th Aug 2022, 6:06 PM
Josué Varela
Josué Varela - avatar
+ 1
Solo ahhhhhh, thanks so much😂😂🥰
8th Aug 2022, 7:49 PM
Josué Varela
Josué Varela - avatar
+ 1
You just need to add a condition to look for the last argument.
8th Aug 2022, 8:24 PM
Solo
Solo - avatar
+ 1
By the way, 'end' can be assigned any character you need.
8th Aug 2022, 8:27 PM
Solo
Solo - avatar
+ 1
My God it was making my life complicated, I just had to put "-".join(args) in the function, I'm going to finish more courses I loved them Solo 🥰🥰🥰
8th Aug 2022, 9:01 PM
Josué Varela
Josué Varela - avatar
+ 1
Yes, this is probably the easiest way, but what you tried to do without using "join" is good practice for logical thinking. 😎
8th Aug 2022, 10:55 PM
Solo
Solo - avatar
0
if now I'm struggling to remove the last "-" so that it becomes valid, I don't know if that's a bad practice😅
8th Aug 2022, 8:08 PM
Josué Varela
Josué Varela - avatar