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

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

TypeError, cannot convert list object to an integer.

Error codes, such as the following example:

 

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


The range function should require an integer, or a pair of ranges, or three integer types to construct an iterable. It is not possible to directly pass the list of args to it. It needs to go through the decompression mechanism. The corrected code is:

  

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


Use *args to unpack the list and pass it to range to construct an itetable.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324733975&siteId=291194637