Use a loop to print out each name in the list in turnHello, xxx!
——————————————————–
L = [‘Bart’, ‘Lisa’, ‘Adam’]
x = len(L)
for i in range(x):
print(‘Hello,’, L[i])
——————————————————–
Here, if you use for i in x directly, the compiler reports an error.TypeError: ‘int’ object is not iterableļ¼
Traceback(mostrecentcalllast):
File”main.py”,line5,in<module>
foriinx:
TypeError:’int’objectisnotiterable
The reason for this problem is that you cannot iterate directly with int, but must use the range method, i.e. range(x).
Similar Posts:
- How to Solve Error: TypeError int object is not iterable
- Fast locating nonetype ‘object is not Iterable in Python
- [Solved] An error occurred when paddlepaddle iterated data: typeerror: ‘function’ object is not iterative
- [Solved] PythonTypeError: ‘<' not supported between instances of 'str' and 'int'
- TypeError: ‘list’ object cannot be interpreted as an integer
- How to Solve Python TypeError: ‘list’ object is not callable
- [Solved] Python TypeError: sequence item 0: expected str instance, int found
- Python TypeError: can only concatenate str (not “int”) to str
- PaddlePaddle Error: ‘map’ object is not subscriptable
- Python read CSV file prompt “line contains null byte” error