jeudi 3 décembre 2015

if else under for loop working on != but ==

I'm not understanding why == condition is not working but != is working in for loop. Here's the code segment:

# this way it's not working . only single time running and not giving desired output

list_of_student= []

for student in student_list:

    student_detail = student(val[1],val[2],val[3])  # namedtuple

    if (student_id and student_id==student.id) or (student_name and student_name==student.name):
        return student_detail
    else:
        list_of_student.append(student_detail)

But if I change == to != and revert the following actions , it's working fine. Could you please tell me the reason, or, where I'm wrong ?

#this way it's working fine.
list_of_student= []

for student in student_list:

    student_detail = student(val[1],val[2],val[3])   # namedtuple
    if (student_id and student_id!=student.id) or (student_name and student_name!=student.name):
        list_of_student.append(student_detail)

    else:
        return student_detail

Aucun commentaire:

Enregistrer un commentaire