Why output ends with 'None'? | Sololearn: Learn to code for FREE!


Why output ends with 'None'?

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

8/8/2022 6:55:29 PM

Oro Collares

13 Answers

New Answer


Because you are actually printing a seal 😉: print(print()) You just need: concatenate("I", "love", "Python", "!")


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.


either construct a new string to return or remove the last print...


It is that if I change the print for the return it does not return the complete concatenation :(


It is possible to write this function without using a loop ☺️


''' 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'))


Bob_Li Thanks!!, i learn quite a lot with community interaction 🥰


Solo ahhhhhh, thanks so much😂😂🥰


You just need to add a condition to look for the last argument.


By the way, 'end' can be assigned any character you need.


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 🥰🥰🥰


Yes, this is probably the easiest way, but what you tried to do without using "join" is good practice for logical thinking. 😎


if now I'm struggling to remove the last "-" so that it becomes valid, I don't know if that's a bad practice😅