+ 1

Simple python list problem

Hi guys! I want to know how to compare all the variable of a list to another variable, I can't find that on internet... I hope you can help me, sorry my English mistakes, I'm French and my English isn't that good ^^

24th Sep 2019, 8:47 AM
manu
6 Answers
+ 3
This lesson might offer you a solution. Check "List functions" https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2456/
24th Sep 2019, 9:42 AM
Seb TheS
Seb TheS - avatar
+ 3
l = [1,2,3,4,5] n2 = 2 if n2 in l: print(n2,"is in list")
24th Sep 2019, 12:03 PM
Choe
Choe - avatar
24th Sep 2019, 10:18 AM
Seb TheS
Seb TheS - avatar
+ 2
That can also be done using the any function, but there is an "in" operation which does it with 3 words. Anyways here's 3 solutions: https://code.sololearn.com/chYqUmKNvt2m/?ref=app
24th Sep 2019, 2:27 PM
Seb TheS
Seb TheS - avatar
+ 1
I read all the lessons and the exemple but i don't find what i search ^^ I just want to make something like that If any item in my list == my variable If you can explain more in details that can be great 👌 Also thank for respond speedily to my message
24th Sep 2019, 11:19 AM
manu
+ 1
Thank you guys ^^ I just use "in" I didn't know that you can do that inside an if statement... But that perfectly work
25th Sep 2019, 4:56 AM
manu