From 23329f82754e5f3ab1c94d78047bda2f7591c5d3 Mon Sep 17 00:00:00 2001 From: Josh Mudge Date: Thu, 20 Dec 2018 13:48:53 -0700 Subject: [PATCH] Add arguments info. --- Codecademy.md | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/Codecademy.md b/Codecademy.md index 9d86e8e..4d12d49 100644 --- a/Codecademy.md +++ b/Codecademy.md @@ -167,6 +167,50 @@ or if it has parameters: greet_customer(1,ten) ``` +# Passing Arguments + + ``` + greet_customer(special_item): + print(special_item) + + greet_customer(beef) + ``` + +Result: + + ``` + beef + ``` + +## Using Keyword Arguments + + Keyword arguments are nice for specifying a default but changeable argument. + + Here's an example from P3, Ch2, ex7 + +``` +def create_spreadsheet(title, row_count = 1000): + row_count = str(row_count) + print("Creating a spreadsheet called " + title + " with " + row_count +" rows.") + +create_spreadsheet("Applications", row_count = 10) +``` + +``` +row_count = 1000 +``` +is the default + +``` +row_count = 10 +``` + +is the passed argument and thus what is used for a result: + +``` +Creating a spreadsheet called Applications with 10 rows. +``` + # Fun Projects Design a shop using Ex7 and Ex9 as a frame: