# How does python know the usage of flag , rows_and_columns = False

App Profile Recommendation | Dataquest

My Code:

``````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 after each row

if rows_and_columns:
print('Number of rows:', len(dataset))
print('Number of columns:', len(dataset))
``````

What I expected to happen:

The code is part of the example given. What I don’t understand is how does python know using the flag that headers are to be excluded ? It is not intuitive.

What actually happened:

``````No error. Just the doubt
``````
What does this indicate "rows_and_columns = False" and how does python understand it without the code ? Secondly, if rows_and_columns= False, then how does it relate to "if rows_and columns" ( which is assumed to be "True") . Could I have excluded header without using the two booleans ?

since posting this, I read upon the concept of flags. I do think dataquest should mention it ! I understand now that flags indicate if a condition is met to run the code or not run it. My query still remains:

1. when we initialize that rows and columns = False, which condition are we trying to meet ? Exclusion of header ?
2. If it is exclusion of header, how did Python know if that’s what we are talking about ?
3. When is flag important ? Can we usually code without it ?

this works equally well without a flag, so why the flag !!:

def explore_data(dataset, start, end):
dataset_slice = dataset[start:end]
for row in dataset_slice:
print(row)
print(’\n’) # adds a new (empty) line after each row
print(‘Number of rows:’, len(dataset))
print(‘Number of columns:’, len(dataset))

The condition is if we want to print the number of rows and columns in the dataset. It only adds that choice and can be useful to only print out things we want to display when we call thatt function.

No, it has nothing to do with the exclusion of header. It’s just a flag, if when `True`, will print out the number of rows and columns in the dataset.

It’s important if you don’t want to print that information out and that’s the extent of it.

The purpose here is not so much as “this has a very important reason so you need it”, but more about helping students get comfortable with how functions can be implemented and used.

For this project, you can code without it as per me. It’s use is under your control as well. Feel free to experiment with the function as you think might be necessary. But be mindful of those changes for any future instructions that ask you to call that function.

Understood, thanks a lot!

1 Like
{"ft_lang_label":"__label__en","ft_lang_prob":0.82688826,"math_prob":0.8681235,"size":2575,"snap":"2022-27-2022-33","text_gpt3_token_len":585,"char_repetition_ratio":0.11707507,"word_repetition_ratio":0.06320542,"special_character_ratio":0.23805825,"punctuation_ratio":0.12643678,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.95000803,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-06-30T17:08:33Z\",\"WARC-Record-ID\":\"<urn:uuid:6125e816-5bdf-4f7e-a899-2a17054ef4ec>\",\"Content-Length\":\"34593\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:ae5958de-22b9-432f-a965-924006afd7da>\",\"WARC-Concurrent-To\":\"<urn:uuid:3026268b-d512-4321-bade-120c96cab0c8>\",\"WARC-IP-Address\":\"172.66.43.104\",\"WARC-Target-URI\":\"https://community.dataquest.io/t/how-does-python-know-the-usage-of-flag-rows-and-columns-false/555430\",\"WARC-Payload-Digest\":\"sha1:RSQKUPZGIPSQEE5L2MVJIA3QHPF42TWE\",\"WARC-Block-Digest\":\"sha1:LDTGOTZOG6AG2OGYAHUX554WMZXBBL6F\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-27/CC-MAIN-2022-27_segments_1656103850139.45_warc_CC-MAIN-20220630153307-20220630183307-00416.warc.gz\"}"}