Python Value Error: not enough values to unpack

后端 未结 4 1987
囚心锁ツ
囚心锁ツ 2021-01-29 08:02

Get the following error in code, unsure of what it means or what I did wrong. Just trying to initialize three list values to empty collections:

nba,nfl,mlb = []
         


        
4条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-29 09:03

    This attempts to unpack, as the error message says, an iterable on the right hand side into three variables on the left hand side, so, for example, after running a,b,c = 1,2,3 you get a == 1 and b == 2 and c == 3.

    In your case, this iterable is empty, so "there are not enough values to unpack": there are three variables, but no values in the iterable (the iterable is an empty list). What you need is the following:

    a,b,c = [],[],[]
    

    Here you have three variables a,b,c and the iterable discussed above is the tuple [],[],[] in this case.

提交回复
热议问题