TypeError: ‘list’ object cannot be interpreted as an integer

TypeError: ‘list’ object cannot be interpreted as an integer

Wrong type, cannot convert list object to an integer

Error code, such as the following example:

args=[3,6]

print(list(range(args)))

the range function should require an integer, or a pair of ranges, or three integer types to construct an iteratable. It is not possible to directly pass the args list to it. It needs to be decompressed. After correction, the code is as follows:

args=[3,6]

print(list(range(*args)))#callwithargumentsunpackedfromalist

use * args to decompress the list and pass it to range to construct an itetable

Similar Posts: