I have the following question:
considering the given list :
list = ['12','8','3']
print('8' in list)
for i in range(5):
if '8' in list == True:
You shouldn't name variables
int because they might conflict with Python's built in keywords.
Your check did
if '8' in list, but that will test if the string 8 is in the list, not the number. Drop the apostrophes.
You don't have to put
if 8 in list in a loop, it'll do the looping and testing for you.
To check if a number is in a list, you can use python's built in
in keyword, your write your own code to do the checking.
Remember not to use keywords like
list, so I've changed the name to
myList in these examples.
if 8 in myList: # Note that you don't have to say == True print('8 is in the list!')
for i in myList)
for i in myList: if i == 8: print('8 is in the list!')**
for i in range(len(myList))
for i in range(len(myList)): if myList[i] == 8: print('8 is in the list!')