diff --git a/00_variables_strings_numbers.ipynb b/00_variables_strings_numbers.ipynb index 28ecbac..74e05a1 100644 --- a/00_variables_strings_numbers.ipynb +++ b/00_variables_strings_numbers.ipynb @@ -18,23 +18,33 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 55, "metadata": { "id": "JLTMQ6_2B_b0" }, "outputs": [], "source": [ + "my_name = \"Erynn\"\n", + "\n", "# `greeting` is a variable; \"Hello world!\" is a string\n", "greeting = \"Hello world!\"" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 56, "metadata": { "id": "cZbnXEVXB_b1" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hello world!\n" + ] + } + ], "source": [ "# `print()` is a function\n", "print(greeting)" @@ -42,14 +52,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 57, "metadata": { "id": "TOzUs8zPB_b1" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hello world! And you, Erynn!\n" + ] + } + ], "source": [ "# What happens when we evaluate this cell?\n", - "greeting" + "greeting\n", + "print(f\"{greeting} And you, {my_name}!\")" ] }, { @@ -61,7 +80,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 58, "metadata": {}, "outputs": [], "source": [ @@ -70,11 +89,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 59, "metadata": {}, - "outputs": [], - "source": [ - "# Your turn --- how do we **print** the variable?" + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hello, Intro to DH!\n" + ] + } + ], + "source": [ + "# Your turn --- how do we **print** the variable?\n", + "print(greeting)" ] }, { @@ -88,7 +116,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 60, "metadata": {}, "outputs": [], "source": [ @@ -97,16 +125,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 61, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'this is a constant'" + ] + }, + "execution_count": 61, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "I_SHOULD_NEVER_CHANGE" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 62, "metadata": {}, "outputs": [], "source": [ @@ -115,9 +154,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 63, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "\"uh-oh! don't do this!!!\"" + ] + }, + "execution_count": 63, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "I_SHOULD_NEVER_CHANGE" ] @@ -154,9 +204,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 64, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'this is a string **literal**'" + ] + }, + "execution_count": 64, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# A literal is data that is declared directly -- it is **literally** what it is\n", "\"this is a string **literal**\"" @@ -164,11 +225,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 65, "metadata": { "id": "e6_bNdg5B_b3" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "This is a string.\n" + ] + } + ], "source": [ "ex_1 = \"This is a string.\"\n", "print(ex_1)" @@ -176,11 +245,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 66, "metadata": { "id": "DEmVQKnLB_b3" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "This is also a string\n" + ] + } + ], "source": [ "ex_2 = 'This is also a string'\n", "print(ex_2)" @@ -188,35 +265,81 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 67, "metadata": { "id": "6N7JobIrB_b3" }, - "outputs": [], - "source": [ - "ex_3 = \"Here is a string.'\n", + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Here is a string.\n" + ] + } + ], + "source": [ + "ex_3 = \"Here is a string.\"\n", "print(ex_3)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 68, "metadata": { "id": "pwaxgu1HB_b3" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "I asked the question, \"When should I use single quotes.\"\n", + "I'm writing a string with double quotes -- it's making it easier to use apostrophes.\n" + ] + } + ], "source": [ "ex_4 = 'I asked the question, \"When should I use single quotes.\"'\n", - "print(ex_4)" + "print(ex_4)\n", + "\n", + "ex_5 = \"I'm writing a string with double quotes -- it's making it easier to use apostrophes.\"\n", + "print(ex_5)" + ] + }, + { + "cell_type": "code", + "execution_count": 69, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "I said, 'He said, \"She said, 'Forward slashes are the way to go!'\"'\n" + ] + } + ], + "source": [ + "ex_6 = \"I said, 'He said, \\\"She said, 'Forward slashes are the way to go!'\\\"'\"\n", + "print(ex_6)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 70, "metadata": { "id": "1E3MwY0DB_b3" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "edward gibbon\n" + ] + } + ], "source": [ "historian = \"edward gibbon\"\n", "print(historian)" @@ -224,22 +347,38 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 71, "metadata": { "id": "ComprGlSB_b4" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Edward Gibbon\n" + ] + } + ], "source": [ "print(historian.title())" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 72, "metadata": { "id": "c-GaA4_JB_b4" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], "source": [ "# What happens if we forget the parentheses on `title()`?\n", "print(historian.title)" @@ -254,7 +393,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 73, "metadata": {}, "outputs": [], "source": [ @@ -267,20 +406,40 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 74, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "I'm on multiple lines!\n", + "\n", + "Whoa!\n", + "\n" + ] + } + ], "source": [ "print(multiline_string)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 75, "metadata": { "id": "k5K8KbEqB_b4" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "becky chambers\n" + ] + } + ], "source": [ "novelist = \"Becky Chambers\"\n", "print(novelist.lower())" @@ -288,29 +447,51 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 76, "metadata": { "id": "Yo-qC0MwB_b4" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 76, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "\"becky\" == \"becky\"" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 77, "metadata": { "id": "QbBcRQZfB_b4" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 77, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "\"becky\" == \"Becky\"" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 78, "metadata": { "id": "6bJmR4ZSB_b4" }, @@ -322,11 +503,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 79, "metadata": { "id": "ccEVnJY-B_b4" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ada lovelace\n" + ] + } + ], "source": [ "full_name = first_name + \" \" + last_name\n", "print(full_name)" @@ -334,11 +523,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 80, "metadata": { "id": "s3ukpffIB_b4" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " Hello, Ada Lovelace\n" + ] + } + ], "source": [ "greeting = f\" Hello, {first_name} {last_name}\"\n", "print(greeting.title())" @@ -355,67 +552,121 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 81, "metadata": { "id": "O4d0bejVB_b4" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "tab\n" + ] + } + ], "source": [ "print(\"tab\")" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 82, "metadata": { "id": "8JguVX8QB_b4" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\ttab\n" + ] + } + ], "source": [ "print(\"\\ttab\")" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 83, "metadata": { "id": "9XqoF39uB_b4" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Languages: \n", + "Greek\n", + "Latin\n", + "English\n" + ] + } + ], "source": [ "print(\"Languages: \\nGreek\\nLatin\\nEnglish\")" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 84, "metadata": { "id": "abf-wbFVB_b4" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "' string '" + ] + }, + "execution_count": 84, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "str_rspace = \"string \"\n", - "print(str_rspace)" + "str_rspace = \" string \"\n", + "str_rspace" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 85, "metadata": { "id": "B0MQPD2_B_b4" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " string\n" + ] + } + ], "source": [ "print(str_rspace.rstrip())" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 86, "metadata": { "id": "PtN_oFpCB_b5" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " string .\n" + ] + } + ], "source": [ "example = str_rspace + \".\"\n", "print(example)" @@ -423,11 +674,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 87, "metadata": { "id": "49wF2WPMB_b5" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " string.\n" + ] + } + ], "source": [ "example_2 = str_rspace.rstrip() + \".\"\n", "print(example_2)" @@ -444,11 +703,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 88, "metadata": { "id": "PzEDVoWwB_b5" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "5072" + ] + }, + "execution_count": 88, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# integers\n", "238 + 4834" @@ -456,29 +726,51 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 89, "metadata": { "id": "4J0s8k45B_b5" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "12" + ] + }, + "execution_count": 89, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "19 - 7" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 90, "metadata": { "id": "hA-9haewB_b5" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "216" + ] + }, + "execution_count": 90, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "54 * 4" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 91, "metadata": { "id": "14LxsedTB_b5" }, @@ -489,51 +781,95 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 92, "metadata": { "id": "3mKwnS3gB_b5" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "45" + ] + }, + "execution_count": 92, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "num" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 93, "metadata": { "id": "PDogTSWoB_b5" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "50" + ] + }, + "execution_count": 93, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "num + 5" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 94, "metadata": { "id": "YUb8QZJLB_b5" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "int" + ] + }, + "execution_count": 94, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "type(num)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 95, "metadata": { "id": "YxNBSpHkB_b5" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "3.0" + ] + }, + "execution_count": 95, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "30 / 10 # this will return a float" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 96, "metadata": { "id": "QZ3NwuPzB_b5" }, @@ -544,33 +880,66 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 97, "metadata": { "id": "sp-kh3TaB_b5" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "4.285714285714286" + ] + }, + "execution_count": 97, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "f" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 98, "metadata": { "id": "UDRnydXbB_b6" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "float" + ] + }, + "execution_count": 98, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "type(f)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 99, "metadata": { "id": "LDcm4C4gB_b6" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "27" + ] + }, + "execution_count": 99, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "3 ** 3" ] @@ -581,7 +950,7 @@ "provenance": [] }, "kernelspec": { - "display_name": ".venv", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -595,7 +964,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.7" + "version": "3.12.1" } }, "nbformat": 4,