You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"In Python, objects are one thing and their <b>pointers</b> (you might want to call them labels or variables) are another. As I told you above in the case of `a=1`, the integer was created somewhere in the available memory and we attached the pointer `a` to it so that we could use it later. Python automatically \"knew\" that we meant `1` to be an integer by convention. That is, the <b>type</b> of `1` was determined to be an integer on the fly. We call this aspect of a language \"dynamic typing\" and it means that the user doesn\u2019t need to explicitly specify the <b>type</b> of an object. This can be a surprise for someone coming from the C-family or Fortran programming languages. \n",
244
+
"In Python, objects are one thing and their <b>pointers</b> (you might want to call them labels or variables) are another. As I told you above in the case of `a=1`, the integer was created somewhere in the available memory and we attached the pointer `a` to it so that we could use it later. Python automatically \"knew\" that we meant `1` to be an integer by convention. That is, the <b>type</b> of `1` was determined to be an integer on the fly. We call this aspect of a language \"dynamic typing\" and it means that the user doesn’t need to explicitly specify the <b>type</b> of an object. This can be a surprise for someone coming from the C-family or Fortran programming languages. \n",
245
245
"\n",
246
246
"### Pointers vs Objects\n",
247
247
"In a dynamically typed language, <b>pointers</b> are labels for objects in memory (like `1` above). They can be plucked off one object and placed on another. For example the two consecutive commands,"
@@ -271,7 +271,7 @@
271
271
"metadata": {},
272
272
"source": [
273
273
"### Strong typing\n",
274
-
"Even though Python determines object <b>types</b> dynamically when they are created, the object <b>type</b> is fixed. We call this aspect of a programming language <b>strong typing</b>. In practical terms, all that this means is that Python will throw an error if you try and do something with an object that it is incapable of. Python will not automatically convert <i>unrelated</i> types (e.g., `int` to `str`) just to make your code run. Thus, `a` in the example above might be alternately assigned to an integer or a string, but operations on the object that `a` points to must be consistent with that object. The compiler won\u2019t guess your intentions. For example\n"
274
+
"Even though Python determines object <b>types</b> dynamically when they are created, the object <b>type</b> is fixed. We call this aspect of a programming language <b>strong typing</b>. In practical terms, all that this means is that Python will throw an error if you try and do something with an object that it is incapable of. Python will not automatically convert <i>unrelated</i> types (e.g., `int` to `str`) just to make your code run. Thus, `a` in the example above might be alternately assigned to an integer or a string, but operations on the object that `a` points to must be consistent with that object. The compiler won’t guess your intentions. For example\n"
275
275
]
276
276
},
277
277
{
@@ -326,7 +326,7 @@
326
326
"cell_type": "markdown",
327
327
"metadata": {},
328
328
"source": [
329
-
"throws an error, because string objects can\u2019t be added to integers. Sometimes Python is forgiving, like if you add an integer and float (we'll return to this), but it is best to be explicit. \n",
329
+
"throws an error, because string objects can’t be added to integers. Sometimes Python is forgiving, like if you add an integer and float (we'll return to this), but it is best to be explicit. \n",
330
330
"\n",
331
331
"### Data types\n",
332
332
"We've partly covered this but let's be comprehensive. We'll refer to <b>objects</b> as anything that is stored in memory and <b>data</b> as special types of objects that are single values. Data objects are the most elementary of the objects we will work with in Python and more complicated objects like functions and structures will use data objects as inputs. The basic data types that we commonly work with are `int`, `float`, `string`, `complex`, and `boolean`. Python can handle all of these natively."
@@ -476,10 +476,9 @@
476
476
"What are <b>functions</b> and <b>operators</b>? I've snuck these concepts in without alerting you, but I think based on the above examples you might be able to guess what they are. Let's give each a proper definition and further examples.\n",
477
477
"\n",
478
478
"### Operators ###\n",
479
-
"<b>Operators</b> are commands that \u201coperate\u201d on objects to their left and right and return a new object or value. This abstract notion is actually extremely intuitive. For example `+` and `/` are arithmetic operators for addition and division of the objects on either side of the operator. `<` is a logical operator, it returns `True` when the object on the right is larger than the object on the left (Note: logical operators can be used on things that aren't obviously numeric). `is` is another logical operator, it returns `True` when the pointers on the left and right point to the same object, and `False` when they don\u2019t. `is` is similar to `==` (\"equals\"), except that `==` can evaluate to `True` if two different objects evaluate to the same value. <b>Note:</b> using `is` for value comparison is a misuse because many equal values are <i>not</i> the same object (e.g., two different lists with the same contents). Use `==` for value equality and reserve `is` for identity checks like `x is None`. Here are some usage examples\n",
479
+
"<b>Operators</b> are commands that “operate” on objects to their left and right and return a new object or value. This abstract notion is actually extremely intuitive. For example `+` and `/` are arithmetic operators for addition and division of the objects on either side of the operator. `<` is a logical operator, it returns `True` when the object on the right is larger than the object on the left (Note: logical operators can be used on things that aren't obviously numeric). `is` is another logical operator, it returns `True` when the pointers on the left and right point to the same object, and `False` when they don’t. `is` is similar to `==` (\"equals\"), except that `==` can evaluate to `True` if two different objects evaluate to the same value. <b>Note:</b> using `is` for value comparison is a misuse because many equal values are <i>not</i> the same object (e.g., two different lists with the same contents). Use `==` for value equality and reserve `is` for identity checks like `x is None`. Here are some usage examples\n",
480
480
"\n",
481
-
"\n",
482
-
""
481
+
"Note: See Python operator reference: https://docs.python.org/3/reference/expressions.html#operator-precedence\n"
483
482
]
484
483
},
485
484
{
@@ -531,7 +530,9 @@
531
530
"### Functions ###\n",
532
531
"In Python, a `function` is a special type of object that takes other objects as input and does something or optionally returns other object(s) as output(s). `functions` are the work-horse of most programs and they are more intuitive to see and use than this abstract definition makes them appear. At their most essential, `functions` allow you to reuse chunks of code for operation on new inputs or with tweaks to the parameters associated with the reused code. \n",
533
532
"\n",
534
-
"A `function` is called in Python by using its name followed by parentheses (e.g., `print(1)` calls the `print()` function with the integer `1`). Most, though not all, functions will accept some kind of object as an input. The inputted objects to a function are called its <b>arguments</b>, and these go inside the parentheses. We've seen several examples of `functions` already: `print()`, `int()`, `float()`. These are functions that are standard in Python and can be used by default. `print()` takes in an <b>argument</b> but doesn't <b>return</b> anything. `int()` takes in an object that is convertible to an integer and <b>returns</b> an `int` object. For example: "
533
+
"A `function` is called in Python by using its name followed by parentheses (e.g., `print(1)` calls the `print()` function with the integer `1`). Most, though not all, functions will accept some kind of object as an input. The inputted objects to a function are called its <b>arguments</b>, and these go inside the parentheses. We've seen several examples of `functions` already: `print()`, `int()`, `float()`. These are functions that are standard in Python and can be used by default. `print()` takes in an <b>argument</b> but doesn't <b>return</b> anything. `int()` takes in an object that is convertible to an integer and <b>returns</b> an `int` object. For example:\n",
534
+
"\n",
535
+
"Note: See defining functions: https://docs.python.org/3/reference/compound_stmts.html#function-definitions\n"
"- <strong>tuple</strong>: tuples are structures that store data in <b>order</b> but are <b>immutable</b>. That is tuples are like lists, except that you can't add or remove from them without creating a whole new object in memory. Sometimes you need things that are immutable (e.g., the next two structures require immutable objects!). Defined using `()` (check examples below).\n",
799
800
"\n",
800
-
"- <strong>set</strong>: sets are like lists but they are <b>unordered</b> and no duplicates are allowed. Unordered? Yes, sets collect objects but don't keep track of where they were put. On a technical side, it is actually more accurate to say that sets are hyperspecific about where they\u2019ve put things (internally) and so you as the user cannot modify that order. This makes sets very efficient at calculating membership (e.g., is \"1\" in our set?) and intersections (common objects in multiple sets). If you wanted to know if the numbers 7,23,and 108 existed in three lists or three sets, it would be much faster to do the latter. Defined using `{}` or `set(list)` notation. (check examples below).\n",
801
+
"- <strong>set</strong>: sets are like lists but they are <b>unordered</b> and no duplicates are allowed. Unordered? Yes, sets collect objects but don't keep track of where they were put. On a technical side, it is actually more accurate to say that sets are hyperspecific about where they’ve put things (internally) and so you as the user cannot modify that order. This makes sets very efficient at calculating membership (e.g., is \"1\" in our set?) and intersections (common objects in multiple sets). If you wanted to know if the numbers 7,23,and 108 existed in three lists or three sets, it would be much faster to do the latter. Defined using `{}` or `set(list)` notation. (check examples below).\n",
801
802
"\n",
802
803
"- <strong>dictionary</strong>: dictionaries are structures that store objects in pairs. Each pair consists of a <b>key</b> and a <b>value</b>. In analogy, a phone book is a dictionary, where the key is a person's name, and the value their phone number. You could accomplish the same thing using two sets of ordered lists, but dictionaries have the advantage that their keys are stored...as...a...<b>set</b>! Returning to our phonebook example, this would make it really easy to figure out if someone is in the phonebook (otherwise you would need to read every name). It also means that there can't be two identical keys in your dictionary. Defined with `{}` notation with `key:value` pairs. (check examples below)\n",
803
804
"\n",
@@ -1032,7 +1033,7 @@
1032
1033
"\n",
1033
1034
"- <strong>Example 5</strong>: `in` is an operator that returns a true or false depending on if the object on the left hand side is in the data structure on the right hand side. `in` comparisons can be slow for lists because every object needs to be compared against the thing on the lhs of `in`. Because of the way that sets store objects, `in` can be evaluated very rapidly. \n",
1034
1035
"\n",
1035
-
"- <strong>Example 6</strong>: sets\u00a0can perform set logical operations very effectively (surprised?). If you want to calculate which objects two groups have in common, or which objects in group `a` are not in group `b`, then sets are the data structure that you want to use. In this case we've demonstrated how to calculate the union (set that results from combining unique objects of each) and intersection (set of objects in common to both) of two sets `a` and `b`, using the methods of the same name. \n",
1036
+
"- <strong>Example 6</strong>: sets can perform set logical operations very effectively (surprised?). If you want to calculate which objects two groups have in common, or which objects in group `a` are not in group `b`, then sets are the data structure that you want to use. In this case we've demonstrated how to calculate the union (set that results from combining unique objects of each) and intersection (set of objects in common to both) of two sets `a` and `b`, using the methods of the same name. \n",
1036
1037
"\n",
1037
1038
"### Dictionary - Examples ###"
1038
1039
]
@@ -1767,7 +1768,7 @@
1767
1768
"\n",
1768
1769
"The above examples show how <b>methods</b> are similar to <b>functions</b> except that by default they have the attributes of the instance passed as inputs (i.e., the string itself in the above examples), and you call them with the `.method(args)` syntax. Similar to functions, methods can return one, many, or no objects. \n",
1769
1770
"\n",
1770
-
"Data structures like `lists` and `dictionaries` are likewise implemented as `classes` within python, and each have their own useful methods that will need to routinely be used. Here are some examples of list methods:\u00a0"
1771
+
"Data structures like `lists` and `dictionaries` are likewise implemented as `classes` within python, and each have their own useful methods that will need to routinely be used. Here are some examples of list methods:"
0 commit comments