TypeError: 'list' object cannot be interpreted as an integer


TypeError: 'list' object cannot be interpreted as an integer

類型錯誤,不能將list對象轉換為一個整數.

錯誤代碼,例如如下例子:

 

  1. args = [3,6]  
  2. print(list(range(args)))    


range函數本應該需求,一個整數,或者一對范圍,或者三個整數類型,才能構造一個iterable,這里直接將args這個列表傳遞給它是不行的,需要通過解壓縮機制,更正后代碼為:

  

 
  1. args = [3,6]  
  2. print(list(range(*args)))  # call with arguments unpacked from a list  


使用*args對列表進行解壓縮,后傳遞給range構造一個itetable.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



猜您在找 TypeError: 'list' object cannot be interpreted as an integer Python常見錯誤 【error】 for i in range(len(shape)/2): TypeError: 'float' object cannot be interpreted as an integer Uncaught TypeError: Cannot convert undefined or null to object TypeError: Image data of dtype object cannot be converted to float Vue的報錯:Uncaught TypeError: Cannot assign to read only property 'exports' of object '#' create-react-app 遇到問題 TypeError: Cannot assign to read only property 'jsx' of object '#' Vue的報錯:Uncaught TypeError: Cannot assign to read only property 'exports' of object '#' List 、Integer[]、int[] 轉換 python使用多進程報錯TypeError: cannot serialize '_io.TextIOWrapper' object 在Python運行過程中遇到了如下錯誤: TypeError: ‘list’ object is not callable
 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM