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

19th May 2018, 2:15 PM
...
... - avatar
5 Answers
+ 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 :)
19th May 2018, 3:05 PM
Just A Rather Ridiculously Long Username
+ 1
huuuh...this doesnt look right try:: num=list(range(100)) if num.index(40)==[40]: print('done')
19th May 2018, 2:18 PM
᠌᠌Code X
᠌᠌Code X - avatar
+ 1
Thanks!
19th May 2018, 4:30 PM
...
... - avatar
0
I still get a syntax error pointing to the colon every time
19th May 2018, 2:36 PM
...
... - avatar
0
No problem :D
19th May 2018, 5:33 PM
Just A Rather Ridiculously Long Username