Anybody could tell me what's different between below codes


#1

1)
def get_class_average(students):
results = []
for student in students:
results.append(get_average(student))**
(no indent)return average(results)**
2)
def get_class_average(students):
results = []
for student in students:
results.append(get_average(student))
(indent)return average(results)

What's the different? Need help. Thank you in advance.
I don't know why the format has been changed.
the different between those code is indent.
[quote="leadh2o, post:1, topic:39223, full:true"]
1)

def get_class_average(students):
    results = []
    for student in students:
        results.append(get_average(student))**
    return average(results)**

2)

def get_class_average(students):
    results = []
    for student in students:
        results.append(get_average(student))
        return average(results)

What's the different? Need help. Thank you in advance.


#2

the function ends once a return keyword is reached, in scenario 1 this happens after the for loop has run for each student in students, in your second scenario this already happens in the first run of the for loop (the loop just appends the first student, then return is reached, the function ends (if the function ends, the loop in the function also ends))

This a huge difference


#3

thank you, got it now