diff --git a/s23/Gurmail_lecture_notes/08_Conditionals-1/lec_08_Conditionals1.ipynb b/s23/Gurmail_lecture_notes/08_Conditionals-1/lec_08_Conditionals1.ipynb index 3e6428b404ec6d76a7ad0085e8879fa9fa1a6b36..cc64714a46453a49ef5d6cf675f2cbde5354e3b9 100644 --- a/s23/Gurmail_lecture_notes/08_Conditionals-1/lec_08_Conditionals1.ipynb +++ b/s23/Gurmail_lecture_notes/08_Conditionals-1/lec_08_Conditionals1.ipynb @@ -11,6 +11,24 @@ "* Q2 due Today" ] }, + { + "cell_type": "markdown", + "id": "a9ecd185", + "metadata": {}, + "source": [ + "# Function Scope Rules\n", + "1. Functions must be called before they run\n", + "2. Local variables are recycled when functions end\n", + "3. Local variables are recreated every time a function is called\n", + "4. We can only see variables that are in the active frame or the global frame\n", + "5. We can in general \"use\" any global variable with no problems at all. \"Use\" means anything other than assignment. e.g. printing\n", + "6. Python makes variables that we assign something to as local\n", + "7. Must assign local variables before we can use them.\n", + "8. use the keyword global to use the global version of the variable instead of making a local variable.\n", + "9. When we pass data (arguments) to functions the data is copied into the parameter - we don't use the original variables.\n", + "10. Even if the variables have the same name we still copy the data from the argument to the parameter." + ] + }, { "cell_type": "markdown", "id": "309ae71d", @@ -617,7 +635,7 @@ "outputs": [], "source": [ "def format_date(month, day, year):\n", - " \"\"\"returns a string representing the date, such as Feb 11th of ‘22\"\"\"\n", + " \"\"\"returns a string representing the date, such as Feb 11th of ‘23\"\"\"\n", " result_str = \"\"\n", " result_str += format_month(month)\n", " result_str += \" \" + format_day(day)\n", diff --git a/s23/Gurmail_lecture_notes/08_Conditionals-1/lec_08_Conditionals1_template_Gurmail_lec1.ipynb b/s23/Gurmail_lecture_notes/08_Conditionals-1/lec_08_Conditionals1_template_Gurmail_lec1.ipynb index 382a1651c71741027671038bf307dbdd6c0c6a52..5dcbfc312c6cec3d249d02dc5786c0280271da1b 100644 --- a/s23/Gurmail_lecture_notes/08_Conditionals-1/lec_08_Conditionals1_template_Gurmail_lec1.ipynb +++ b/s23/Gurmail_lecture_notes/08_Conditionals-1/lec_08_Conditionals1_template_Gurmail_lec1.ipynb @@ -11,6 +11,24 @@ "* Q2 due Today" ] }, + { + "cell_type": "markdown", + "id": "4933dfcf", + "metadata": {}, + "source": [ + "# Function Scope Rules\n", + "1. Functions must be called before they run\n", + "2. Local variables are recycled when functions end\n", + "3. Local variables are recreated every time a function is called\n", + "4. We can only see variables that are in the active frame or the global frame\n", + "5. We can in general \"use\" any global variable with no problems at all. \"Use\" means anything other than assignment. e.g. printing\n", + "6. Python makes variables that we assign something to as local\n", + "7. Must assign local variables before we can use them.\n", + "8. use the keyword global to use the global version of the variable instead of making a local variable.\n", + "9. When we pass data (arguments) to functions the data is copied into the parameter - we don't use the original variables.\n", + "10. Even if the variables have the same name we still copy the data from the argument to the parameter." + ] + }, { "cell_type": "markdown", "id": "309ae71d", @@ -476,7 +494,7 @@ "outputs": [], "source": [ "def format_date(month, day, year):\n", - " \"\"\"returns a string representing the date, such as Feb 11th of ‘22\"\"\"\n", + " \"\"\"returns a string representing the date, such as Feb 11th of ‘23\"\"\"\n", " pass" ] }, diff --git a/s23/Gurmail_lecture_notes/08_Conditionals-1/lec_08_Conditionals1_template_Gurmail_lec2.ipynb b/s23/Gurmail_lecture_notes/08_Conditionals-1/lec_08_Conditionals1_template_Gurmail_lec2.ipynb index 3066c0c9633d2e7a62a3cc5bcbcc3fdac1e9a64b..2ebb2c285677b9324dacc37ba927a62469c7e23d 100644 --- a/s23/Gurmail_lecture_notes/08_Conditionals-1/lec_08_Conditionals1_template_Gurmail_lec2.ipynb +++ b/s23/Gurmail_lecture_notes/08_Conditionals-1/lec_08_Conditionals1_template_Gurmail_lec2.ipynb @@ -11,6 +11,24 @@ "* Q2 due Today" ] }, + { + "cell_type": "markdown", + "id": "c8695d05", + "metadata": {}, + "source": [ + "# Function Scope Rules\n", + "1. Functions must be called before they run\n", + "2. Local variables are recycled when functions end\n", + "3. Local variables are recreated every time a function is called\n", + "4. We can only see variables that are in the active frame or the global frame\n", + "5. We can in general \"use\" any global variable with no problems at all. \"Use\" means anything other than assignment. e.g. printing\n", + "6. Python makes variables that we assign something to as local\n", + "7. Must assign local variables before we can use them.\n", + "8. use the keyword global to use the global version of the variable instead of making a local variable.\n", + "9. When we pass data (arguments) to functions the data is copied into the parameter - we don't use the original variables.\n", + "10. Even if the variables have the same name we still copy the data from the argument to the parameter." + ] + }, { "cell_type": "markdown", "id": "309ae71d", @@ -476,7 +494,7 @@ "outputs": [], "source": [ "def format_date(month, day, year):\n", - " \"\"\"returns a string representing the date, such as Feb 11th of ‘22\"\"\"\n", + " \"\"\"returns a string representing the date, such as Feb 11th of ‘23\"\"\"\n", " pass" ] }, @@ -487,7 +505,7 @@ "metadata": {}, "outputs": [], "source": [ - "format_date(9, 23, 2022)" + "format_date(2, 11, 2023)" ] }, {