0
student = {
    'Tom': 'A1',
    'Amy': 'B2',
    'John': 'C3',
}

student_id = []
for i in student.values():
    print(i)
    student_id.append(i)
print(student_id)

The outcome for the above code is:

A
B
C
['A', 'B', 'C']

But when I assign the appended list to variable a, it yields a different outcome:

student = {
    'Tom': 'A',
    'Amy': 'B',
    'John': 'C',
}

student_id = []
for i in student.values():
    print(i)
    a = student_id.append(i)
print(a)

The outcome become:

A
B
C
None

Why is this happening?

0 Answers0