Python | Return multiple values from a function

def calc_marks():
    marks = [59.99, 240.00, 655.25, 75.99]
    over_marks = 0
    for s in marks:
        if s>500:
            over_marks +=1
    average = sum(marks)/len(marks)

    return over_marks, average

over_marks, average = calc_marks()
print("The overlimit is :" + str(over_marks) + " and the average of marks is :" + str(average))


Once we defined the function and if we want to return multiple values then we simply use the return keyword along with the values that we want to pass and separate them with “,”. Outside the function definition, we assign those values to the function like over_marks, average = calc_marks()

Avatar of Dhvanil V

Author: Dhvanil V