Python code on multiple functions

Could someone pls help to understand how this code figures out if there is a header in applestore.csv

def open_dataset(file_name=‘AppleStore.csv’, header=True):
opened_file = open(file_name)
from csv import reader
read_file = reader(opened_file)
data = list(read_file)

if header:
    return data[1:]
else:
    return data

apps_data = open_dataset()

We specify it when we call the function. The function definition includes the default argument header=True which acts as a flag.

When we call the function we can set it to True or False indicating whether the dataset has a header or not.

1 Like

Many thanks for clarification! Does this also mean that when you don’t add a parameter when calling a function as shown below, then by default it is set to True?

apps_data = open_dataset(‘AppleStore.csv’)

Assuming a boolean default argument exists in the function definition, yes.

1 Like