0

I'm PLSQL programming and now I'm learning Python. I want to code a simple for loop and print a value if the condition is true. But How can I search a entire array? Do you have any idea? Thanks

v_names = ['Gustavo', 'Tim', 'Matt', 'Bjorn', 'Lars']

for names in v_names:
    if names[x] == 'Gustavo': #wrong code line, I need your help here
        print ('You have a great name!') 
2
  • 1
    Remove [x] (and maybe rename names to name for clarity). Commented Feb 14, 2018 at 14:22
  • 2
    just use if names == instead of if names[x] == Commented Feb 14, 2018 at 14:22

2 Answers 2

5
if "Gustavo" in v_names:
    print("You have a great name!")
Sign up to request clarification or add additional context in comments.

1 Comment

my god! You can search a entire array list using a simple if sentence??? Im facinated how simple is Python!!! i will mark your answer as correct soon
3

Not sure what you want but does this do the job?

v_names =  ['Gustavo', 'Tim', 'Matt', 'Bjorn', 'Lars']

for name in v_names: #This loops over every element in v_names 
    if name == 'Gustavo': #Now if name is equal to Gustavo
        print ('You have a great name!') #Then print stuff.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.