# INITIAL CODE
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:]
return data
apps_data = open_dataset()
print(apps_data[:5])
Reformatted your code above slightly to fix the indents, for the sake of readability. Keep in mind also that you shouldn’t assign True
or False
boolean values as strings (i.e. it should be header = True
not header = 'True'
.
To answer your question, this function in the mission is a custom function we’re writing. Both the file_name
and header
parameters are therefore also by our own design! Python isn’t assuming anything by itself in the way you meant it.
When we define a function, we can assign our parameters default values to be used when their values aren’t explicitly specified.
The function is defined like so:
def open_dataset(file_name='AppleStore.csv', header=True):
This tells us that the open_dataset
function has 2 parameters, and each of those have their own default values. So simply calling the function by itself, i.e. open_dataset()
, would cause it to use the respective default values you assigned to the file_name
and header
parameters. Here, by assigning a default value of True
to the header
parameter, you are telling Python to assume that the first row will be the header row, because that is how you wrote your function!
As an example, calling your function the following way would cause it not to treat the first row as the header row:
open_dataset(header = False)
Here, since you’re explicitly specifying an argument for the header
parameter, the default value of True
isn’t used.