316-5 Multiple Return Statements

Quick question regarding this screen.

Can anyone explain the variable header?

The logic is easy being that we added the second parameter, header=True to utilize in the if/else conditional statement below it.

However, header is just a random variable, right? So, where is the actual calculation for checking the variable called header?

if header:, I get, but how does the program know what header is?

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

The program doesn’t know what header is. The only thing the program knows is that if we declare header=True, then it will return all the data excluding data[0] (the header row), and if we say header=False, then it will return the entire dataset (since there is no header row). We, as the coder using the function, would want to know ahead of time if the dataset contains a header so that we know whether or not to make header True or False appropriately in the function. (If we make a mistake and the data doesn’t really have a header row, we’re going to end up losing the first row of data when we don’t declare the header False!) I hope that makes sense!

This was confusing to me as well, I was operating under the impression that we need to create something that check swhether a header exists.
e.g. if data[0] is a string then there is a header and otherwise no.

Anyway, thanks for explaining.