Guided project 1 (Python Fundamentals): Question on defining and using explore_data function

Hello, can someone explain what is the purpose of assigning “False” to “rows_and_columns” parameter?
And later when we actually use the explore_data function, we assign True to rows_and_columns…why? :slightly_frowning_face:

def explore_data(dataset, start, end, rows_and_columns=False):
    dataset_slice = dataset[start:end]    
    for row in dataset_slice:
        print(row)
        print('\n') # adds a new (empty) line between rows
        
    if rows_and_columns:
        print('Number of rows:', len(dataset))
        print('Number of columns:', len(dataset[0]))

print(android_header)
print('\n')
explore_data(android, 0, 3, True) 

Thanks a lot :slight_smile:

1 Like

You could probably just as easily write the function so that rows_and_columns=True is the default. Then if you wanted to use the function to explore the data but not print how many rows and columns it contains, just pass in False for that parameter. My guess is for having us do it this way for the project is to reinforce what we learned about default arguments in functions in an earlier mission. As you grow in your knowledge you’ll be able to write custom functions that have the flexibility and usefulness you need to make analysis easier.

OHHHH!!! I seee. We are actually using rows_and_columns to determine if we want to print number of rows or columns or not. Nicee.

Thanks a lot
Have a great weekend!
:smiley:

1 Like