Embed Functions

Mission: Cleaning and preparing data in python (5)

Hi everyone, this block of code seems to have the function executed within the function itself, and the console runs the function automatically without me executing the function. How does it work? Thanks!

test_data = ["1912", "1929", "1913-1923",
             "(1951)", "1994", "1934",
             "c. 1915", "1995", "c. 1912",
             "(1988)", "2002", "1957-1959",
             "c. 1955.", "c. 1970's", 
             "C. 1990-1999"]

bad_chars = ["(",")","c","C",".","s","'", " "]

def strip_characters(string):
    stripped_test_data = []    
    for char in bad_chars:
        string = string.replace(char,"")
    return string

    for d in test_data:
        date = strip_characters(d)

This is called recursion, where the function calls itself in the body of function definition.

This is strange. I would expect you have called the strip_characters once before all the strip_characters inside get automatically called, else this recursive function can’t even begin to run

Here is the image of the scenario I explained above, Im just wondering if the function is executed due to recurssion or that the virtual console auto-runs functions. Thanks for your help!