Hi @Horigome. In Python you can define a function that takes any arguments. You can also set a default value for the argument. Python doesn’t know what the words mean – it only knows to expect something to be there as an input. In the body of the code, we tell Python what to do with those inputs. If we put in something it didn’t expect, or if it can’t be used in the way we wrote in the body of the function, then Python will give an error.
Let’s have a look at the explore_data()
function in more detail.
def explore_data(dataset, start, end, rows_and_columns=False):
Because of how we’re defining the function, anything we put in the dataset
slot can be refered to as dataset
in the body of the function. Likewise for start
, end
, and rows_and_columns
. So when we call the function with, say, explore_data(android_apps, 0, 4)
, we are telling Python these 4 things:
dataset = android_apps
start = 0
end = 4
-
rows_and_columns = False
(because that was the default in the function definition)
Then with that information, Python replaces the variables in the function with their values from the input. As long as we, the people using the function, are using it properly, Python will happily process it.
The if-statement if rows_and_columns:
means the same thing as if rows_and_columns = True
. This part of the code will only be run if we add True
to our function input (such as explore_data(android_apps, 0, 4, True
). If we don’t enter anything, then automatically this will be false and the rest of the code won’t be processed (it won’t print the number of rows and columns of your dataset). We want to know ahead of time if we want it to print the number of rows and columns so we know whether to add the True
or not.
I hope that makes it a little clearer for you. Let me know if anything else is confusing and I’ll try my best to help.