H. Chen
H. Chen

Reputation: 3

problems with using string.join() operator

I tested out the string.join() method on a few lines of code:

a = 1
b = 1
c = 0

superpower = []

if a == 1:
        superpower.append("flying")
if b == 1:
        superpower.append("soaring")
if c == 1:
        superpower.append("high")

", ".join(superpower)

print superpower

but the result always comes back as just a regular list, not a string. How can I fix this? I'm new to python, and would appreciate the help.

Upvotes: -1

Views: 51

Answers (1)

mgilson
mgilson

Reputation: 310227

", ".join(superpower) returns a string, it doesn't convert the input iterable into a string. You aren't doing anything with that return value:

superpower_str = ', '.join(superpower)
print(superpower_str)

is probably what you want.

Upvotes: 5

Related Questions