I want to get each item in the list 'spam' but i an not able to call spam list..
spam = ['apples' , 'bananas' , 'tofu' , 'cats']
i = 0
n = len(spam)
for i in range (0, n):
if i <= n :
print(spam(i) , end = ',')
i += 1
else:
break
Traceback (most recent call last):
File "C:\Users\admin\AppData\Local\Programs\Python\Python38\commaCode.py", line 9, in <module>
print(spam(i) , end = ',')
TypeError: 'list' object is not callable
whileloop to aforloop? You seem to have missed some crucial parts of aforloop withrange. You don't need theif, you don't need to incrementimanually and you don't needbreak. In fact, you don't even need thei. Please read the answer of @tyrion below.