Friday, December 22, 2017

Nested Functions and Closures in Python

Let's take an example:

def get_students():
      
       students=["Abhinaw","Aman"]

def get_students_titlecase():

       students_titlecase = []

       for student in students:
              students_titlecase.append(student.title())
     
        return student_titlecase

students_titlecase_names=get_students_titlecase()

print(students_titlecase_names)

This is called Nested function and basically the inner function can access the outer students So this is called closures.

No comments: