350.2 Guided project - app store

Hi: I am starting to learn python with the desire to become a data scientist. I am currently in the first guided project about the profitable app profiles in android and app store. In that project, the function has been written as below to explore the apps:

def explore_data(dataset, start, end, rows_and_columns=False):
    dataset_slice = dataset[start:end]    
    for row in dataset_slice:
        print('\n') # adds a new (empty) line after each row

if rows_and_columns:
    print('Number of rows:', len(dataset))
    print('Number of columns:', len(dataset[0]))

While everything is okay in this, I didn’t understand about row_and_columns=False. I omitted the False parameter (just wrote row_ and columns) and got the same result. Is it the optional parameter? Also, I am getting 17 columns in app store, and I see the data has also 17 columns, but the solution provided has only 16 columns. I believe the data is same. Not sure, why there is the difference!

Thanks for your help!

I think I figured out the 17 columns issue. I downloaded the data and it has 17 columns, but the project data has 16 columns. I would appreciate your thoughts on ‘False’ parameter in above question.

Thank you,

Yes it is an optional parameter. You can also call it a parameter with a default value. The former is seen as optional from the point of view of the function caller, and the latter is seen from point of view of the code inside the function body which uses the value of the parameter.

The purpose of this is to set a default value to that parameter to be used by the function body if the user calling the function does not specify some other value to overwrite this default value. The default value is usually chosen to be the most commonly occurring value, satisfying the most number of real life use cases. This is to provide convenience to people writing code to type less and allow them to avoid specifying that argument when calling the function if they know others reading their code are familiar enough with that function’s api (so co-workers know what extra optional arguments can be used but are not specified when calling).

The purpose of specifying default parameters can also be to pass on work from the caller to within the function body.
An example from https://docs.python-guide.org/writing/gotchas/ (you can learn about Python’s default arguments are evaluated once when the function is defined, not each time the function is called point too from there, important.)

def append_to(element, to=[]):
    return to

If you never used the default [] empty list here when defining the function, the caller has to specify that empty list, which could be a little more troublesome.

Thank you for great explanation, hanqi. That is really helpful.

Hey @bhuwan!

Do you mind marking this topic as solved ? This puts the correct answer (here this would be @hanqi’s answer) in the original post!

Here’s a quick gif tutorial on how to do this:

Done!!! I hope I did correctly :slight_smile: