0

so.. i want to put all the objects in the list together, and my idea was to create a variable with nothing in it and make a for loop to add the strings to the variable... but it doesn't work :( any help?

I searched for an answer but could not find anything online... I am very noob, so sorry if am wrong.

sounds = ["super", "cali", "fragil", "istic", "expi", "ali", "docious"]
x=""
for s in sounds:
    x+s
print(x)

I expected x to be "supercalifragilisticexpialidocious" at the end.

1 Answers1

0

You can use join:

sounds = ["super", "cali", "fragil", "istic", "expi", "ali", "docious"]

x = "".join(sounds)

print(x)

As for your solution, you're missing a =:

sounds = ["super", "cali", "fragil", "istic", "expi", "ali", "docious"]
x=""
for s in sounds:
    x += s
print(x)

You get the same thing:

supercalifragilisticexpialidocious
iz_
  • 15,923
  • 3
  • 25
  • 40