Creating a standalone pure Python function
This function is what we will be using to take the selected value from the dropdown, process it somehow, and use its return value to do something that is visible to the user.
The function is so simple that it doesn't require much explanation:
def display_selected_color(color): Â Â Â Â if color is None: Â Â Â Â Â Â Â Â color = 'nothing' Â Â Â Â return 'You selected ' + color
If the user doesn't input anything (or deselects the current option), then the color
variable is set to 'nothing'
, and the function returns 'You selected ' + <color>
, with whatever value color
takes. Later in the chapter, we will create a more involved function to get some information on countries.
A function is essentially a procedure. It takes in one or more arguments (inputs), does something to them, and returns one or more outputs. So,...