我是PLSQL编程,现在我正在学习Python。我想编写一个简单的for循环,并在条件为真时打印一个值。但是如何搜索整个阵列?你有什么主意吗?感谢
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!')
答案 0 :(得分:5)
if "Gustavo" in v_names:
print("You have a great name!")
答案 1 :(得分:3)
不确定你想要什么,但是这样做了吗?
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.