2016-03-01 45 views
0

我测试出来的几行代码的string.join()方法:问题使用的string.join()操作

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 

但结果总是回来的只是一个普通的列表,而不是一个字符串。我怎样才能解决这个问题?我是python的新手,并希望得到帮助。

回答

5

", ".join(superpower)返回一个字符串,它不会将输入的iterable转换为一个字符串。你没有做任何具有该返回值的任何事情:

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

可能是你想要的。

+0

这很合理,谢谢! –