+ 2
Why output ends with 'None'?
def concatenate(*args): for i in args: i += "-" print(i, end="") print(concatenate("I", "love", "Python", "!"))
13 Antworten
+ 6
Because you are actually printing a seal 😉:
print(print())
You just need:
concatenate("I", "love", "Python", "!")
+ 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.
+ 3
either construct a new string to return or remove the last print...
+ 2
It is that if I change the print for the return it does not return the complete concatenation :(
+ 2
It is possible to write this function without using a loop ☺️
+ 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'))
+ 2
Bob_Li Thanks!!, i learn quite a lot with community interaction 🥰
+ 1
Solo ahhhhhh, thanks so much😂😂🥰
+ 1
You just need to add a condition to look for the last argument.
+ 1
By the way, 'end' can be assigned any character you need.
+ 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 🥰🥰🥰
+ 1
Yes, this is probably the easiest way, but what you tried to do without using "join" is good practice for logical thinking. 😎
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😅