Page 132 -
P. 132

functions


                                                               Parameters Up Close

                          To use a parameter in Python, simply put a variable name between the
                          parentheses that come after the definition of the function name and before the colon.
                          Then within the function itself, simply use the variable like you would any other:
                      The parameter name goes here.                               Use the parameter's
                                                                                  value in your
                          def shout_out(the_name):                                function's code
                                 return("Congratulations " + the_name + "!")      just like any other
                                                                                  variable.
                          Later, invoke the function from your code with a different parameter value each
                          time you use the function:


                          print(shout_out('Wanda'))
                          msg = shout_out('Graham, John, Michael, Eric, and Terry by 2')
                          print(shout_out('Monty'))





                                            Grab your pencil and update your program. Do the following:
                                            1. Modify the send_to_twitter() function so that the message text is
                                            passed into the function as a parameter.
                                            2. Update your code to make the approriate parameterized calls to
                                            sent_to_twitter().




























                                                                                        you are here 4    97
   127   128   129   130   131   132   133   134   135   136   137