diff --git a/Intro Python - Data types 1.ipynb b/Intro Python - Data types 1.ipynb index b996ab4..4fae893 100644 --- a/Intro Python - Data types 1.ipynb +++ b/Intro Python - Data types 1.ipynb @@ -50,9 +50,37 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The Zen of Python, by Tim Peters\n", + "\n", + "Beautiful is better than ugly.\n", + "Explicit is better than implicit.\n", + "Simple is better than complex.\n", + "Complex is better than complicated.\n", + "Flat is better than nested.\n", + "Sparse is better than dense.\n", + "Readability counts.\n", + "Special cases aren't special enough to break the rules.\n", + "Although practicality beats purity.\n", + "Errors should never pass silently.\n", + "Unless explicitly silenced.\n", + "In the face of ambiguity, refuse the temptation to guess.\n", + "There should be one-- and preferably only one --obvious way to do it.\n", + "Although that way may not be obvious at first unless you're Dutch.\n", + "Now is better than never.\n", + "Although never is often better than *right* now.\n", + "If the implementation is hard to explain, it's a bad idea.\n", + "If the implementation is easy to explain, it may be a good idea.\n", + "Namespaces are one honking great idea -- let's do more of those!\n" + ] + } + ], "source": [ "import this" ] @@ -98,7 +126,15 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hello World\n" + ] + } + ], "source": [ "print (\"Hello World\")" ] @@ -106,14 +142,36 @@ { "cell_type": "code", "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 4, "metadata": { "scrolled": true }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Second line\n" + ] + } + ], "source": [ "print (\"Second line\")" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "markdown", "metadata": {}, @@ -138,10 +196,8 @@ ] }, { - "cell_type": "code", - "execution_count": null, + "cell_type": "markdown", "metadata": {}, - "outputs": [], "source": [ "#### **This is a cell for coding**" ] @@ -167,12 +223,10 @@ ] }, { - "cell_type": "code", - "execution_count": null, + "cell_type": "markdown", "metadata": { "scrolled": true }, - "outputs": [], "source": [ "# Header 1\n", "## Header 2\n", @@ -294,7 +348,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -310,11 +364,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": { "scrolled": true }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "4" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "whole_number" ] @@ -328,11 +393,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": { "scrolled": true }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "4\n" + ] + } + ], "source": [ "print(whole_number)" ] @@ -346,9 +419,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "20" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "a = 10\n", "b = 20\n", @@ -386,9 +470,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "int" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "type(a)" ] @@ -429,7 +524,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": {}, "outputs": [], "source": [ @@ -445,9 +540,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "12.34\n" + ] + } + ], "source": [ "print(a)" ] @@ -461,16 +564,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "float" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "type(a)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, "outputs": [], "source": [ @@ -488,13 +602,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": { "scrolled": true }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "float" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# type(b)" + "type(b)" ] }, { @@ -516,7 +641,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "metadata": {}, "outputs": [], "source": [ @@ -526,11 +651,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "metadata": { "scrolled": true }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "13" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "10 + 3" ] @@ -544,11 +680,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "metadata": { "scrolled": true }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "13" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Sum\n", "a + b" @@ -563,9 +710,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "7" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# difference\n", "\n", @@ -581,7 +739,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": {}, "outputs": [], "source": [ @@ -592,9 +750,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "float" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "type(division)" ] @@ -608,9 +777,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# division: floor division: rounded division\n", "\n", @@ -620,9 +800,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "int" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "type(floor_division)" ] @@ -636,9 +827,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 25, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Module: Remainder of the division\n", "\n", @@ -654,18 +856,40 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 26, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "10" + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "a" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 27, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "b" ] @@ -679,21 +903,34 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 69, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The number 10 is even\n", + "The number 11 is odd\n", + "The number 12 is even\n", + "The number 13 is odd\n", + "The number 14 is even\n", + "The number 15 is odd\n" + ] + } + ], "source": [ "# Even / odd -> modulo (remainder)\n", "# If the remainder of a division by two is zero: even\n", "\n", "\n", - "list_ = [1, 2, 3, 4, 5, 6]\n", + "list_ = [10, 11, 12, 13, 14, 15]\n", "\n", "for i in list_:\n", " if i % 2 == 0:\n", - " print(f\"El numero {i} es par\")\n", + " print(f\"The number {i} is even\")\n", " else:\n", - " print(f\"El numero {i} NO es par\")" + " print(f\"The number {i} is odd\")" ] }, { @@ -719,11 +956,186 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 61, "metadata": {}, "outputs": [], "source": [ - "# your solution here" + "x=10\n", + "y=6" + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "16" + ] + }, + "execution_count": 62, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "x+y" + ] + }, + { + "cell_type": "code", + "execution_count": 63, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "4" + ] + }, + "execution_count": 63, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "x-y" + ] + }, + { + "cell_type": "code", + "execution_count": 64, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "60" + ] + }, + "execution_count": 64, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "x*y" + ] + }, + { + "cell_type": "code", + "execution_count": 65, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1.6666666666666667" + ] + }, + "execution_count": 65, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "x/y\n" + ] + }, + { + "cell_type": "code", + "execution_count": 66, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "float" + ] + }, + "execution_count": 66, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "division = x/y\n", + "type(division)" + ] + }, + { + "cell_type": "code", + "execution_count": 67, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 67, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "floor_division = x//y\n", + "floor_division" + ] + }, + { + "cell_type": "code", + "execution_count": 68, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 68, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "x % b" + ] + }, + { + "cell_type": "code", + "execution_count": 71, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The number 1 is odd\n", + "The number 2 is even\n", + "The number 3 is odd\n", + "The number 4 is even\n", + "The number 5 is odd\n", + "The number 6 is even\n" + ] + } + ], + "source": [ + "# Even / odd -> modulo (remainder)\n", + "# If the remainder of a division by two is zero: even\n", + "\n", + "\n", + "list_ = [1, 2, 3, 4, 5, 6]\n", + "\n", + "for i in list_:\n", + " if i % 2 == 0:\n", + " print(f\"The number {i} is even\")\n", + " else:\n", + " print(f\"The number {i} is odd\")" ] }, { @@ -748,6 +1160,21 @@ "execution_count": null, "metadata": {}, "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 72, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "This is built-in\n" + ] + } + ], "source": [ "# First, let's explore a built-in method: print\n", "# The print method allows us to print messages to the console.\n", @@ -756,9 +1183,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 73, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'THIS IS A STRING'" + ] + }, + "execution_count": 73, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Another example of a built-in method is upper.\n", "# This method converts a string of text to uppercase.\n", @@ -767,7 +1205,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 74, "metadata": {}, "outputs": [], "source": [ @@ -778,9 +1216,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 75, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "8789" + ] + }, + "execution_count": 75, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Next, we use a function from the math library: floor.\n", "# The floor function rounds a number down to the nearest integer.\n", @@ -802,31 +1251,64 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 76, "metadata": { "scrolled": true }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'This is a string'" + ] + }, + "execution_count": 76, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "\"This is a string\"" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 77, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'This is a string with simple quotes'" + ] + }, + "execution_count": 77, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "'This is a string with simple quotes'" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 78, "metadata": { "scrolled": true }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'This is a string with simple quotes'" + ] + }, + "execution_count": 78, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "\"This is a string with simple quotes\" #End Of Line" ] @@ -840,9 +1322,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 79, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'4'" + ] + }, + "execution_count": 79, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "this_is_also_a_string = \"4\"\n", "this_is_also_a_string" @@ -857,9 +1350,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 80, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "str" + ] + }, + "execution_count": 80, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "type(this_is_also_a_string)" ] @@ -873,9 +1377,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 81, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "SyntaxError", + "evalue": "unterminated string literal (detected at line 1) (2937582216.py, line 1)", + "output_type": "error", + "traceback": [ + " \u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[81]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[31m \u001b[39m\u001b[31m\"This is a string\u001b[39m\n ^\n\u001b[31mSyntaxError\u001b[39m\u001b[31m:\u001b[39m unterminated string literal (detected at line 1)\n" + ] + } + ], "source": [ "\"This is a string\n", "with multiple lines\"" @@ -890,9 +1403,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 82, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'\\nThis is a string\\nwith multiple liness'" + ] + }, + "execution_count": 82, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "\"\"\"\n", "This is a string\n", @@ -908,9 +1432,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 83, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "This is a string\n", + "with multiple liness\n" + ] + } + ], "source": [ "print(\"\"\"\n", "This is a string\n", @@ -927,16 +1461,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 84, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'😍'" + ] + }, + "execution_count": 84, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "\"😍\" #emojis -> They are strings" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 85, "metadata": {}, "outputs": [], "source": [ @@ -945,18 +1490,40 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 86, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'😍'" + ] + }, + "execution_count": 86, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "heart_face" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 87, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "str" + ] + }, + "execution_count": 87, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "type(heart_face)" ] @@ -991,7 +1558,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 88, "metadata": {}, "outputs": [], "source": [ @@ -1001,9 +1568,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 89, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "9.5\n" + ] + } + ], "source": [ "c = a + b # Python automatically converts a to float to perform the operation\n", "print(c) # The result, 9.5, is a float" @@ -1011,9 +1586,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 90, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "TypeError", + "evalue": "can only concatenate str (not \"int\") to str", + "output_type": "error", + "traceback": [ + "\u001b[31m---------------------------------------------------------------------------\u001b[39m", + "\u001b[31mTypeError\u001b[39m Traceback (most recent call last)", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[90]\u001b[39m\u001b[32m, line 2\u001b[39m\n\u001b[32m 1\u001b[39m \u001b[38;5;66;03m# But, if we try to perform an operation between a string and an integer:\u001b[39;00m\n\u001b[32m----> \u001b[39m\u001b[32m2\u001b[39m d = \u001b[33;43m\"\u001b[39;49m\u001b[33;43mHola\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m \u001b[49m\u001b[43m+\u001b[49m\u001b[43m \u001b[49m\u001b[43ma\u001b[49m \u001b[38;5;66;03m# This will cause a TypeError\u001b[39;00m\n", + "\u001b[31mTypeError\u001b[39m: can only concatenate str (not \"int\") to str" + ] + } + ], "source": [ "# But, if we try to perform an operation between a string and an integer:\n", "d = \"Hola\" + a # This will cause a TypeError" @@ -1038,7 +1625,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 91, "metadata": {}, "outputs": [], "source": [ @@ -1049,11 +1636,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 93, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "5\n" + ] + } + ], "source": [ - "print(float_number) # The result will be 5, losing the decimal part." + "print(int_number) # The result will be 5, losing the decimal part." ] }, { @@ -1068,9 +1663,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 94, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], "source": [ "# Example of converting a float to a string\n", "a = 3.14159\n", @@ -1079,9 +1682,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 95, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "3.14159\n" + ] + } + ], "source": [ "a = str(a)\n", "print(type(a)) # This will print: \n", @@ -1100,9 +1712,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 96, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], "source": [ "# Example of converting an integer to a string\n", "a = 42\n", @@ -1111,11 +1731,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 97, "metadata": { "scrolled": true }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "42\n" + ] + } + ], "source": [ "a = str(a)\n", "print(type(a)) # This will print: \n", @@ -1140,21 +1769,29 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 128, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "My age is: 42\n" + ] + } + ], "source": [ "# Step 1: Create a variable age with your age as an integer\n", - "age = ...\n", + "age = 42\n", "\n", "# Step 2: Convert the variable age to a string\n", - "age = ...\n", + "age = str(age)\n", "\n", "# Step 3: Concatenate \"My age is: \" with the variable age and store the result in a new variable called message\n", - "message = ...\n", + "message = \"My age is: \" + (age)\n", "\n", "# Step 4: Print the variable message\n", - "print(...)" + "print(message)" ] }, { @@ -1178,9 +1815,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 113, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'Hello'" + ] + }, + "execution_count": 113, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "salutation = input()\n", "salutation" @@ -1195,7 +1843,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 136, "metadata": {}, "outputs": [], "source": [ @@ -1211,9 +1859,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 116, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'Chandler'" + ] + }, + "execution_count": 116, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "name = input(\"Write here your name: \")\n", "name" @@ -1221,9 +1880,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 117, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'42'" + ] + }, + "execution_count": 117, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "number = input(\"Write here your number: \")\n", "number" @@ -1238,18 +1908,41 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 118, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'42424242424242424242'" + ] + }, + "execution_count": 118, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "number * 10" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 119, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "TypeError", + "evalue": "unsupported operand type(s) for /: 'str' and 'int'", + "output_type": "error", + "traceback": [ + "\u001b[31m---------------------------------------------------------------------------\u001b[39m", + "\u001b[31mTypeError\u001b[39m Traceback (most recent call last)", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[119]\u001b[39m\u001b[32m, line 2\u001b[39m\n\u001b[32m 1\u001b[39m \u001b[38;5;66;03m# This will generate an error because we're trying to divide a string.\u001b[39;00m\n\u001b[32m----> \u001b[39m\u001b[32m2\u001b[39m \u001b[43mnumber\u001b[49m\u001b[43m \u001b[49m\u001b[43m/\u001b[49m\u001b[43m \u001b[49m\u001b[32;43m2\u001b[39;49m\n", + "\u001b[31mTypeError\u001b[39m: unsupported operand type(s) for /: 'str' and 'int'" + ] + } + ], "source": [ "# This will generate an error because we're trying to divide a string.\n", "number / 2" @@ -1264,9 +1957,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 120, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "41" + ] + }, + "execution_count": 120, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "number = int(input(\"Write here your number: \"))\n", "number" @@ -1274,18 +1978,40 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 121, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "int" + ] + }, + "execution_count": 121, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "type(number)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 122, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "20" + ] + }, + "execution_count": 122, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "int(number / 2)" ] @@ -1320,9 +2046,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 123, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "str" + ] + }, + "execution_count": 123, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "greeting = \"Hellooooo\"\n", "type(greeting)" @@ -1330,18 +2067,47 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 124, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hellooooo\n" + ] + }, + { + "data": { + "text/plain": [ + "NoneType" + ] + }, + "execution_count": 124, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "type(print(greeting))" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 125, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "str" + ] + }, + "execution_count": 125, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "type(greeting)" ] @@ -1369,7 +2135,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 126, "metadata": {}, "outputs": [], "source": [ @@ -1380,9 +2146,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 127, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'Hello my name is Santi and my age is 24'" + ] + }, + "execution_count": 127, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Using Concatenation with '+'\n", "greeting = \"Hello my name is \" + name + \" and my age is \" + str(age)\n", @@ -1391,9 +2168,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 129, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "('Hello my name is ', 'Santi', ' and my age is ', '42')" + ] + }, + "execution_count": 129, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Using a Comma to Concatenate\n", "greeting = \"Hello my name is \", name, \" and my age is \", str(age)\n", @@ -1402,9 +2190,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 130, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "tuple" + ] + }, + "execution_count": 130, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Checking the Type of the Variable `greeting`\n", "type(greeting)" @@ -1412,7 +2211,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 131, "metadata": {}, "outputs": [], "source": [ @@ -1425,9 +2224,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 132, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'Hello my name is Santi and my age is 42'" + ] + }, + "execution_count": 132, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Using f-strings for cleaner formatting\n", "greeting = f\"Hello my name is {name} and my age is {age}\"\n", @@ -1443,7 +2253,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 133, "metadata": {}, "outputs": [], "source": [ @@ -1454,9 +2264,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 134, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'Hello my name is Laura and my age is 30'" + ] + }, + "execution_count": 134, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Using the .format() Method to Insert Values into a String\n", "greeting = \"Hello my name is {} and my age is {}\".format(name, age)\n", @@ -1479,13 +2300,57 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 140, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'Hello my name is Chandler and I am 42.'" + ] + }, + "execution_count": 140, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# your code here" + "name = input(\"Please write your name: \") \n", + "age = input(\"Please write your age: \") \n", + "\n", + "greet_message = f\"Hello my name is {name} and I am {age}.\"\n", + "greet_message" ] }, + { + "cell_type": "code", + "execution_count": 143, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Hello my name is Chandler and I am 42 years old.'" + ] + }, + "execution_count": 143, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "name = input(\"Please write your name: \")\n", + "age = input(\"Please write your age: \")\n", + "\n", + "say_hello = \"Hello my name is {} and I am {} years old.\".format(name, age)\n", + "say_hello" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [] + }, { "cell_type": "markdown", "metadata": { @@ -1514,7 +2379,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 144, "metadata": {}, "outputs": [], "source": [ @@ -1530,9 +2395,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 145, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'This is a string'" + ] + }, + "execution_count": 145, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "sample_string.capitalize()" ] @@ -1546,20 +2422,42 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 146, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'THIS IS A STRING'" + ] + }, + "execution_count": 146, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "sample_string.upper()" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 147, "metadata": { "scrolled": true }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 147, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# We can also check if the string is in upper case format (uppercase letters)\n", "sample_string.upper().isupper()" @@ -1574,20 +2472,42 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 148, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'this is a string'" + ] + }, + "execution_count": 148, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "sample_string.lower()" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 149, "metadata": { "scrolled": false }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 149, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "sample_string.lower().islower()" ] @@ -1601,9 +2521,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 150, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'THIS IS A STRING'" + ] + }, + "execution_count": 150, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "sample_string.swapcase()" ] @@ -1617,9 +2548,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 151, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'This Is A String'" + ] + }, + "execution_count": 151, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "sample_string.title()" ] @@ -1633,9 +2575,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 152, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'Santi 🥸 Clara 🥸 Laura 🥸 Albert'" + ] + }, + "execution_count": 152, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# New example\n", "list_of_strings = [\"Santi\", \"Clara\", \"Laura\", \"Albert\"]\n", @@ -1651,7 +2604,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 153, "metadata": {}, "outputs": [], "source": [ @@ -1660,18 +2613,40 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 154, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 154, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "number.startswith(\"+\")" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 155, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 155, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "number.startswith(\"34\")" ] @@ -1685,9 +2660,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 156, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 156, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "number.endswith(\"67\")" ] @@ -1701,9 +2687,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 157, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "##This is an example.\n" + ] + } + ], "source": [ "# We define a string with some spaces and characters at the beginning\n", "original_string = \" ##This is an example.\"\n", @@ -1716,9 +2710,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 158, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "This is an example.\n" + ] + } + ], "source": [ "# We can also use lstrip to remove other characters by specifying an argument\n", "modified_string2 = original_string.lstrip(\" #\")\n", @@ -1739,9 +2741,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 159, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "' This is an example.'" + ] + }, + "execution_count": 159, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "original_string.replace(\"#\", \"\")" ] @@ -1755,9 +2768,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 160, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "['Hello', 'my', 'name', 'is', 'Santo']" + ] + }, + "execution_count": 160, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "sentence = \"Hello my name is Santo\"\n", "sentence.split(\" \")" @@ -1765,9 +2789,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 161, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "['H', 'llo my nam', ' is Santo']" + ] + }, + "execution_count": 161, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "sentence.split(\"e\")" ] @@ -1775,7 +2810,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": ".venv", "language": "python", "name": "python3" }, @@ -1789,7 +2824,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.3" }, "nbTranslate": { "displayLangs": [