May I ask, what does += mean? Sorry got lost in the woods. I keep seeing this in the forums and seems to always work like a concatenating function?
+= is the shorthand assignment operator. If you type
a += b, it means
a = a + b. Similarly we have
n = ["Michael", "Lieberman"] def join_strings(words): result = " " for i in range(len(words)): result += words[i] return result# Add your function here print join_strings(n)
I saw error as
Oops, try again. join_strings(['x', 'y', 'z', 'a']) returned ' xyza' instead of 'xyza'
Hi there - this bit's the problem:
- Inside the function, create a variable called result and set it to "", an empty string.
It looks like when you're creating the variable result it has a space in the string.
Because of this, the space appears before the name. Apart from that it looks good. Get rid of the space in the string and you should be okay.
I am facing issues with the following code where I have remove the space between the "" , but I am getting only the first string printed. The code and the outputs are added below:
n = ["Michael", "Lieberman"]
Add your function here
for i in range(len(words)):
Oops, try again.
join_strings(['x', 'y', 'z', 'a']) returned 'x' instead of 'xyza'