May-13-2021, 08:22 PM
It is a docstring, as in "document" string. The computer collects these and uses them when I ask for help.
I like my "ask()" function so much that I decide to use it in other programs. I reorganize function to make it independent of the foods dictionary.
I start python, import my module and ask for help.
So to answer you question, the computer does not care what is contained between those triple quotes. That is meant for the user
I like my "ask()" function so much that I decide to use it in other programs. I reorganize function to make it independent of the foods dictionary.
"""survey: Useful function(s) for writing surveys. """ def ask(question, items, yes_items, score=1): """Ask quesiton. If input is 'y', add score to each item in yes_items""" if input(question) == 'y': for item in yes_items: items[item] += score if __name__ == '__main__': # Demo code showing how you would use ask() foods = {'donuts':0, 'pancakes':0, 'bacon':0, 'waffles':0, 'eggs':0, 'bagels':0} print('Please answer each question with "y" for "yes" and "n" for "no".') # Add one to the foods if you answer yes to these questions ask('Do you like food with holes? ', foods, ('donuts', 'bagels')) ask('Do you like stuff made from animals? ', foods, ('bacon', 'eggs')) ask('Do you like sweets? ', foods, ('donuts', 'pancakes', 'waffles')) # Subtract 1 from these foods if you are gluten sensitive ask('Are you gluten sensitive? ', foods, ('donuts', 'pancakes', 'waffles', 'bagels'), -1) for item, score in foods.items(): print(item, '=', score)Now I have a fairly generic function named "ask()" and some code that demonstrates how ask() is used.
I start python, import my module and ask for help.
Output:>>> import survey
>>> help(survey)
Help on module survey:
NAME
survey - survey.py
DESCRIPTION
Useful functions for writing surveys.
FUNCTIONS
ask(question, items, yes_items, score=1)
Ask quesiton. If input is 'y', add score to each food item in good_foods
FILE
...\survey.py
There are also tools that collect all the docstrings from your modules and create nicely formatted user documentation and other kinds of reports.So to answer you question, the computer does not care what is contained between those triple quotes. That is meant for the user