0
Correct syntax while using list functions in booleans
I keep trying to use list function values in Boolean, like this: num=list(range(100)) (num.index(40))==[40]: print ('done') But every time I get a syntax error in the second line
5 Antworten
+ 2
The problem is that the value at index 40 is an integer, not a list. Try:
num=list(range(100))
if num.index(40) == 40: # <-- Remove square brackets here
print('done')
As a side note, you can write the same thing like so:
num = range(100)
if num[40] == 40:
print('done')
Hope this helps :)
+ 1
huuuh...this doesnt look right
try::
num=list(range(100))
if num.index(40)==[40]:
print('done')
+ 1
Thanks!
0
I still get a syntax error pointing to the colon every time
0
No problem :D