2016-09-22 5 views
0

これはコール後のPython 3.3.0 - +のためにサポートされていないオペランドのタイプ(S): 'INT' と 'リスト'

def f(*a,b): 
    print (sum(a) , b) 

私の機能では、これは

f([x for x in range(100)] , b=0) 

Traceback (most recent call last): 
    File "<pyshell#61>", line 1, in <module> 
    f([x for x in range(100)] , b=0) 
    File "<pyshell#59>", line 2, in f 
    print (sum(a) , b) 
TypeError: unsupported operand type(s) for +: 'int' and 'list' 

エラーが発生します私がsum(a)を使用せず、代わりにaのみを使うときはうまく動作し、plsはこれで何が絡んでいるのかを教えてくれます。

答えて

0

あなたはaにリストを渡すためにリストを展開する必要があります。

f(*[x for x in range(100)], b=0) 
#^
関連する問題