-4

I'm a complete beginner to Python and programming in general. I'm learning on my own, using web resources. I'm currently doing an exercise in order to practice, but I need help. I have a list of objects with 5 items (item 1 to item5). I need your help to find an item in the list (see below).

item_list = ["item1, item2, item3, item4, item5"]

my_item = input("what item do you need ?")

if my_item == item_list[0:4]:

       print(my_item "has been found in the list")
Patrick Artner
  • 50,409
  • 9
  • 43
  • 69
Hakim
  • 3
  • 3
  • 1
    If you are a complete beginner, have a look at some tutorial series or similar. I'm pretty fond of this source which provides an online environment etc. to learn and understand python: [python institute courses](https://pythoninstitute.org/free-python-courses/) (Not related to the question per se, but just a tip :) ) – tbjorch Feb 19 '21 at 10:34
  • 1
    You do not have a list of many items - you have a list that contains 1 string (== 1 item). SO does not aim to teach you python, look up tutorials for that. You can use SO as resource - simply googling `python how to find if item in list site:stackoverflow.com` gives you roughly 170k hits that will give you the knowledge you need - no need to post a _new_ question. – Patrick Artner Feb 19 '21 at 10:34
  • Thanks, Patrick Artner. As I said, I am completely new to it, and I had no clue where to look for, especially when the answers on the web sound even more complex than my question :) It's my very first steps, so all my deep apologies if my question sounds dumb. Also, I have followed the advice of tbjorch, and I am now following the Python institute course. Many thanks to both of you. – Hakim Feb 19 '21 at 18:53

1 Answers1

-1

Python has a specific keyword to "check if an it is in list", it's simply called in.

Therefore your line could look like:

if my_item in item_list:
    ...
Ivo De Jong
  • 199
  • 7