Skip to content

Instantly share code, notes, and snippets.

@flyfir248
Created September 24, 2023 08:39
Show Gist options
  • Save flyfir248/4505937a3c2c3a7f0ed86dd64adae98b to your computer and use it in GitHub Desktop.
Save flyfir248/4505937a3c2c3a7f0ed86dd64adae98b to your computer and use it in GitHub Desktop.
Day2_10_09_2023.ipynb
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/flyfir248/4505937a3c2c3a7f0ed86dd64adae98b/day2_10_09_2023.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"id": "c0092a2f",
"metadata": {
"id": "c0092a2f"
},
"source": [
"# Agenda\n",
"- Recap\n",
"- Datatypes\n",
"- Operators\n",
"- Conditional statements"
]
},
{
"cell_type": "markdown",
"id": "c2640eae",
"metadata": {
"id": "c2640eae"
},
"source": [
"## Recap\n",
"- Components of Spyder\n",
" - Editor\n",
" - Console\n",
" - Variable explorer\n",
"- Working with jupyter\n",
" - How to launch jupyter\n",
" - How to create folder\n",
" - How to create a ipynb file\n",
" - How to create a new cell in jupyter notebook\n",
" - How to execute ?\n",
" - Run current cell and create new cell - Shift+Enter\n",
" - Only run current cell - Ctrl+Enter\n",
"- Basics of python\n",
" - How to create a variable ?\n",
" - variable_name , assignment operator, constant/lietral\n",
" - How to comment a single line and multiline"
]
},
{
"cell_type": "markdown",
"id": "21680f95",
"metadata": {
"id": "21680f95"
},
"source": [
"### Creating a markdown cell\n",
"- Esc+m\n",
"- Select markdown from the task bar, visible on top of the notebook"
]
},
{
"cell_type": "markdown",
"id": "497dbb30",
"metadata": {
"id": "497dbb30"
},
"source": [
"### Creating bullets\n",
"- Use (\\-) hyphen and space\n",
"- Nested bullets ,use tab and then use hyphen and space"
]
},
{
"cell_type": "markdown",
"id": "db6568ad",
"metadata": {
"id": "db6568ad"
},
"source": [
"### After creating the markdown and adding the text, run the cell to see the using shift+enter or control+enter"
]
},
{
"cell_type": "markdown",
"id": "c0c195e8",
"metadata": {
"id": "c0c195e8"
},
"source": [
"### Elements of variables ?\n",
"- Data type\n",
"- Value"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "960671b0",
"metadata": {
"id": "960671b0"
},
"outputs": [],
"source": [
"a = 23"
]
},
{
"cell_type": "markdown",
"id": "7e870615",
"metadata": {
"id": "7e870615"
},
"source": [
"### Data type\n",
"The type of value the variable contains, is called datatype"
]
},
{
"cell_type": "markdown",
"id": "f6cdd8cd",
"metadata": {
"id": "f6cdd8cd"
},
"source": [
"### Different datatypes available in python\n",
"- integer\n",
"- float\n",
"- complex\n",
"- string\n",
"- boolean\n",
"- list\n",
"- tuple\n",
"- dictionary\n",
"- set"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cf2c158f",
"metadata": {
"id": "cf2c158f",
"outputId": "550efd98-a756-4c3e-9004-8e893cf4bdf4"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1\n",
"2\n",
"23\n"
]
}
],
"source": [
"a = 1\n",
"b = 2\n",
"c = 23\n",
"\n",
"print(a)\n",
"print(b)\n",
"print(c)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2b91328d",
"metadata": {
"id": "2b91328d"
},
"outputs": [],
"source": [
"# Float\n",
"c=1.2\n",
"d=3.4"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2c0d7ba7",
"metadata": {
"id": "2c0d7ba7",
"outputId": "5eed6ff0-226b-4692-a8ba-6f9102abbb17"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1.2\n",
"3.4\n"
]
}
],
"source": [
"print(c)\n",
"print(d)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9cc9395e",
"metadata": {
"id": "9cc9395e",
"outputId": "1e6026af-0dbd-41b2-96ba-6b7ae0f389e2"
},
"outputs": [
{
"data": {
"text/plain": [
"1.2"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"c"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8ead3eba",
"metadata": {
"id": "8ead3eba",
"outputId": "bbff96c2-9270-4a42-e1b2-30a2b2a73f36"
},
"outputs": [
{
"data": {
"text/plain": [
"3.4"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"d"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0b823c76",
"metadata": {
"id": "0b823c76",
"outputId": "7185d602-c48f-4c12-c753-5018f90c1dd1"
},
"outputs": [
{
"data": {
"text/plain": [
"3.4"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"c\n",
"d"
]
},
{
"cell_type": "markdown",
"id": "530e9d1e",
"metadata": {
"id": "530e9d1e"
},
"source": [
"### Finding data type"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8d7ae7f2",
"metadata": {
"id": "8d7ae7f2",
"outputId": "b0d2270a-faf2-49c3-9641-5ac87166a69c"
},
"outputs": [
{
"data": {
"text/plain": [
"float"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(c)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3af04596",
"metadata": {
"id": "3af04596",
"outputId": "d0a6ae24-5778-4385-fa39-75a5a3551d5a"
},
"outputs": [
{
"data": {
"text/plain": [
"float"
]
},
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(d)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1be5278f",
"metadata": {
"id": "1be5278f"
},
"outputs": [],
"source": [
"# Complex\n",
"p = 1+3j"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2a193143",
"metadata": {
"id": "2a193143",
"outputId": "36740a36-078b-4382-9e27-ffc7026addc7"
},
"outputs": [
{
"data": {
"text/plain": [
"(1+3j)"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"p"
]
},
{
"cell_type": "markdown",
"id": "6e3fcf0c",
"metadata": {
"id": "6e3fcf0c"
},
"source": [
"### Rules for creating a variable name\n",
"- Start with alphabet or underscore ( _ )\n",
"- Can contain alphabets underscore or number. Special charaters are not allowed ( including space)\n",
"- Case sensitive"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "416c77eb",
"metadata": {
"id": "416c77eb"
},
"outputs": [],
"source": [
"# Valid variable names\n",
"a = 12\n",
"_a = 123.4\n",
"b34 = 2354"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "45e742a8",
"metadata": {
"id": "45e742a8",
"outputId": "d5495be7-a8d1-498a-de7a-8df9ed7baef2"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"12\n",
"123.4\n",
"2354\n"
]
}
],
"source": [
"print(a)\n",
"print(_a)\n",
"print(b34)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "000523bf",
"metadata": {
"id": "000523bf",
"outputId": "8bfd3f73-790e-4663-c1d9-52214f3696d9"
},
"outputs": [
{
"ename": "SyntaxError",
"evalue": "invalid syntax (3661316499.py, line 1)",
"output_type": "error",
"traceback": [
"\u001b[1;36m Input \u001b[1;32mIn [48]\u001b[1;36m\u001b[0m\n\u001b[1;33m 1a = 23 # Invalid variable name results in error\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
]
}
],
"source": [
"1a = 23 # Invalid variable name results in error"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bf983f72",
"metadata": {
"id": "bf983f72",
"outputId": "f9d1d55a-7a1a-4ba9-8836-e34dbd86ef95"
},
"outputs": [
{
"ename": "SyntaxError",
"evalue": "invalid syntax (2921059549.py, line 1)",
"output_type": "error",
"traceback": [
"\u001b[1;36m Input \u001b[1;32mIn [49]\u001b[1;36m\u001b[0m\n\u001b[1;33m $a = 23 # Invalid variable name results in error\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
]
}
],
"source": [
"$a = 23 # Invalid variable name results in error"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "93f0069e",
"metadata": {
"id": "93f0069e",
"outputId": "ac5df44d-4104-4b11-d1a1-c952e358f9f1"
},
"outputs": [
{
"ename": "SyntaxError",
"evalue": "invalid syntax (2059849318.py, line 1)",
"output_type": "error",
"traceback": [
"\u001b[1;36m Input \u001b[1;32mIn [50]\u001b[1;36m\u001b[0m\n\u001b[1;33m abc! = 23 # Invalid variable name results in error\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
]
}
],
"source": [
"abc! = 23 # Invalid variable name results in error"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "57cb0659",
"metadata": {
"id": "57cb0659",
"outputId": "aedd32e8-9ee4-4b2c-e6d4-c2bc7b95694b"
},
"outputs": [
{
"ename": "SyntaxError",
"evalue": "invalid syntax (1394063064.py, line 1)",
"output_type": "error",
"traceback": [
"\u001b[1;36m Input \u001b[1;32mIn [42]\u001b[1;36m\u001b[0m\n\u001b[1;33m abc% = 23 # Invalid variable name results in error\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
]
}
],
"source": [
"abc% = 23 # Invalid variable name results in error"
]
},
{
"cell_type": "markdown",
"id": "6568eb8d",
"metadata": {
"id": "6568eb8d"
},
"source": [
"### Basic operations with integers and float"
]
},
{
"cell_type": "markdown",
"id": "9b30c335",
"metadata": {
"id": "9b30c335"
},
"source": [
"## Arithmetic operators\n",
"- \\+ Addition\n",
"- \\- Subtraction\n",
"- \\* Multiplication\n",
"- / Division\n",
"- // Quotient\n",
"- % Modulo\n",
"- ** Power or Exponent"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8a1c604b",
"metadata": {
"id": "8a1c604b",
"outputId": "10adf059-a91b-4bc9-a8e9-b140ef8913dd"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"5\n"
]
}
],
"source": [
"# Addition\n",
"add = 2+3\n",
"print(add)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ba05d860",
"metadata": {
"id": "ba05d860",
"outputId": "e9028f94-8efe-4110-81e6-344ff4ba4595"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Addition of the given numbers is 5\n"
]
}
],
"source": [
"print('Addition of the given numbers is ', add)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "59e0438b",
"metadata": {
"id": "59e0438b",
"outputId": "2afbe558-c775-4bf3-9aad-b5f9d83ba93e"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"20\n",
"-20\n"
]
}
],
"source": [
"# Subtraction\n",
"a = 23\n",
"b = 3\n",
"diff_1 = a-b\n",
"bus = b-a #### Any valid variable name can be given\n",
"print(diff_1)\n",
"print(bus)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d7412a52",
"metadata": {
"id": "d7412a52",
"outputId": "5e04e44b-384a-464c-e7ea-100ddfb37474"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"23\n"
]
}
],
"source": [
"# To get the value of a use print\n",
"print(a)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "72e7deec",
"metadata": {
"id": "72e7deec",
"outputId": "c191ced2-1b62-42f7-99f4-971f8979f057"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"46\n"
]
}
],
"source": [
"# Multiplication\n",
"z = a*2\n",
"print(z)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "040af992",
"metadata": {
"id": "040af992",
"outputId": "fe28df81-c98b-47d5-af65-981ea7942556"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2.5\n"
]
}
],
"source": [
"# Division\n",
"a = 5\n",
"b = 2\n",
"quo = a/b\n",
"print(quo)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4f45788b",
"metadata": {
"id": "4f45788b",
"outputId": "1ea8a9c6-974a-4e70-8296-e41f52ab12f1"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"5\n",
"6\n",
"2.5\n"
]
}
],
"source": [
"print(a)\n",
"print(b)\n",
"print(quo)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "daace9a5",
"metadata": {
"id": "daace9a5",
"outputId": "faecaa65-9f3d-4814-ea08-a82662ca657b"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<class 'int'>\n",
"<class 'int'>\n",
"<class 'float'>\n"
]
}
],
"source": [
"print(type(a))\n",
"print(type(b))\n",
"print(type(quo))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4ac74436",
"metadata": {
"id": "4ac74436",
"outputId": "91b6a4e2-8716-45fd-adf4-02fb1b232313"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"5\n",
"6\n"
]
}
],
"source": [
"# Multiple assignments\n",
"a,b = 5,6\n",
"print(a)\n",
"print(b)"
]
},
{
"cell_type": "markdown",
"id": "0bcd8689",
"metadata": {
"id": "0bcd8689"
},
"source": [
"### Three different ways of converting a floating value to an integer\n",
"- Round\n",
" - Nearest integer\n",
" - 3.7 - 4\n",
" - 3.2 - 3\n",
"- Ceil\n",
" - Nearest integer greater than the given floating value\n",
" - 3.7 - 4\n",
" - 3.2 - 4\n",
"- Floor\n",
" - Nearest integer smaller than the given floating value\n",
" - 3.7 - 3\n",
" - 3.2 - 3"
]
},
{
"cell_type": "markdown",
"id": "23d85f2a",
"metadata": {
"id": "23d85f2a"
},
"source": [
"### Importing libraries\n",
"- Whenever a functionality is not available in python by default. Then we will import external libraries\n",
"- In below example we are importing math because ceil and floor are not availble in python by default\n",
"- Import will include all the functions available in external library to current executing jupyter notebook\n",
"- One of the simple Syntax to import library is\n",
" - import library_name\n",
" - Ex: import math\n",
"- Only after importing a library we can use its functions\n",
"- Use functions with library by using libraryname followed by dot(.) then function name\n",
" - Ex: math.ceil\n",
"- For one jupyter notebook excution importing library once is sufficient"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5363937c",
"metadata": {
"id": "5363937c"
},
"outputs": [],
"source": [
"import math"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "20dd83ad",
"metadata": {
"id": "20dd83ad",
"outputId": "5e33e02b-4168-4c4b-aa64-a80fd5b65a50"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"3\n",
"4\n",
"3\n"
]
}
],
"source": [
"print(round(3.2))\n",
"print(math.ceil(3.2))\n",
"print(math.floor(3.7))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "97f28d3d",
"metadata": {
"id": "97f28d3d",
"outputId": "6d801d69-ed0b-47a5-e54c-b4531fd04581"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"123\n"
]
}
],
"source": [
"print(math.floor(123.784))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "22720181",
"metadata": {
"id": "22720181",
"outputId": "0a83df10-2624-49f5-bfe6-212a8419e133"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"3\n",
"3\n"
]
}
],
"source": [
"### Floor division or Floored quotient\n",
"c,d = 11,3\n",
"fl_quo = c//d\n",
"# Above code is equivalent to\n",
"print(math.floor(c/d))\n",
"print(fl_quo)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "aeeeb81e",
"metadata": {
"id": "aeeeb81e",
"outputId": "5cbffda8-a032-41fd-8ce0-e15d45c079ed"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"3.6666666666666665\n"
]
}
],
"source": [
"print(11/3)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7467dc0c",
"metadata": {
"id": "7467dc0c",
"outputId": "212d1e60-e0bb-4e6c-c19c-e93274dffb0a"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"4\n"
]
}
],
"source": [
"print(math.ceil(11/3))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a78bd35b",
"metadata": {
"id": "a78bd35b",
"outputId": "7da0cb7f-8b60-41ba-9fa8-a286ff247f58"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1\n"
]
}
],
"source": [
"# Modulo operator or Remainder\n",
"x54545,jhjhjhjhjh = 13,4\n",
"zdkfghdk7673567 = x54545 % jhjhjhjhjh\n",
"print(zdkfghdk7673567)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "40ac1660",
"metadata": {
"id": "40ac1660",
"outputId": "4fcb21e7-bc2e-4d58-a64d-5b13b472cc75"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"64\n",
"64\n"
]
}
],
"source": [
"# Power operator\n",
"num1, num2 = 2 , 6\n",
"power_of_two_num1 = num1 ** num2\n",
"print(power_of_two_num1)\n",
"print(power_of_two_num1)"
]
},
{
"cell_type": "markdown",
"id": "8ac89128",
"metadata": {
"id": "8ac89128"
},
"source": [
"### Boolean constants\n",
"- True\n",
"- False\n"
]
},
{
"cell_type": "markdown",
"id": "0480fc0d",
"metadata": {
"id": "0480fc0d"
},
"source": [
"### Invalid boolean values\n",
"- flase\n",
"- true\n",
"- FALSE\n",
"- TRUE"
]
},
{
"cell_type": "markdown",
"id": "ec821156",
"metadata": {
"id": "ec821156"
},
"source": [
"### Fundamental operation in mathematics\n",
"- Addition\n",
"- Comparision\n",
" - True\n",
" - False\n",
"\n",
"### What a cpu contains\n",
"- Arithmetic and Logical unit (ALU)"
]
},
{
"cell_type": "markdown",
"id": "00a38414",
"metadata": {
"id": "00a38414"
},
"source": [
"### Comparision operators\n",
"- Only two possible results\n",
" - True\n",
" - False\n",
"- Different comparision operators\n",
" - == Equal\n",
" - != Not equal\n",
" - \\> Greater than\n",
" - \\< Less than\n",
" - \\>= Greater than or equal\n",
" - \\<= Less than or equal"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e3c0ad76",
"metadata": {
"id": "e3c0ad76",
"outputId": "efd45e9c-a144-48f4-8d83-ae7fa2029685"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"False\n"
]
}
],
"source": [
"### Equal operator\n",
"i = 4\n",
"j = 8\n",
"print(i==j)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "43bb8358",
"metadata": {
"id": "43bb8358",
"outputId": "05059c73-7f53-4e4b-d1d2-1efa4e71eee5"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"True\n"
]
}
],
"source": [
"i = 4\n",
"j = 4\n",
"print(i==j)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d4be2c36",
"metadata": {
"id": "d4be2c36",
"outputId": "65e42b48-c4c3-4a25-b0ff-dc72a45eaf7e"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"True\n"
]
}
],
"source": [
"i = 4.6\n",
"j = 4.6\n",
"print(i==j)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c1277a6b",
"metadata": {
"id": "c1277a6b",
"outputId": "b52ccbfc-5dea-406a-e8c4-8f007bea480e"
},
"outputs": [
{
"ename": "SyntaxError",
"evalue": "invalid syntax (36860527.py, line 3)",
"output_type": "error",
"traceback": [
"\u001b[1;36m Input \u001b[1;32mIn [136]\u001b[1;36m\u001b[0m\n\u001b[1;33m print(power_of _two _num)\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
]
}
],
"source": [
"### Common error while declaring and printing the variables\n",
"power_of_two_num = 1\n",
"print(power_of _two _num)\n",
"#### Please verify are you using the same name as you declared , character by character"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "41cf1552",
"metadata": {
"id": "41cf1552",
"outputId": "7b7ecb1a-3665-4fdb-81be-c5feb93e2d40"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"False\n"
]
}
],
"source": [
"# Not equal operator\n",
"i = 4.6\n",
"j = 4.6\n",
"print(i != j)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "62247c79",
"metadata": {
"id": "62247c79"
},
"outputs": [],
"source": [
"glass1 = 20\n",
"glass2 = 40"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f83e1817",
"metadata": {
"id": "f83e1817",
"outputId": "9ad3f60c-f114-434c-f5b2-627111bf7f67"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"False\n"
]
}
],
"source": [
"print(glass1 == glass2)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "97aa22a7",
"metadata": {
"id": "97aa22a7",
"outputId": "f0dc489e-62df-4bde-ab73-8536fc08d3f2"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"True\n"
]
}
],
"source": [
"print(glass2 > glass1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "10b3d3fe",
"metadata": {
"id": "10b3d3fe"
},
"outputs": [],
"source": [
"g3 = 20\n",
"g4 = 20"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "56b3328d",
"metadata": {
"id": "56b3328d",
"outputId": "71253d84-0bd9-4193-aac3-64ecff6a22a2"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"True\n"
]
}
],
"source": [
"print(g4 == g3)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8ef8c9de",
"metadata": {
"id": "8ef8c9de",
"outputId": "1ec307f1-e2e5-4aef-c666-f797c4d0d8f6"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"False\n"
]
}
],
"source": [
"## Not equal\n",
"print(g4 != g3)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4416112f",
"metadata": {
"id": "4416112f",
"outputId": "b9851ef9-ed09-4b10-8ed0-daeb73bd9471"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"True\n"
]
}
],
"source": [
"print(glass2 > glass1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "32422893",
"metadata": {
"id": "32422893",
"outputId": "260ca9e5-0a38-48d6-e6b4-f92ebc027317"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"False\n"
]
}
],
"source": [
"print(glass2 < glass1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "77ee611d",
"metadata": {
"id": "77ee611d",
"outputId": "28c87950-b608-42dd-c4bc-234cafe112c3"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"True\n"
]
}
],
"source": [
"print(glass2 >= glass1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5f87f1d5",
"metadata": {
"id": "5f87f1d5",
"outputId": "5946fda5-7646-4a48-f08a-75537db11606"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"True\n"
]
}
],
"source": [
"print(g3>=g4)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "21b28839",
"metadata": {
"id": "21b28839",
"outputId": "ea8eab49-c25a-4b57-9cc0-bcedf31e2894"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"True\n"
]
}
],
"source": [
"print(g4>=g3)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8e02dfc1",
"metadata": {
"id": "8e02dfc1"
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "2e6fc885",
"metadata": {
"id": "2e6fc885"
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "470e0038",
"metadata": {
"id": "470e0038"
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "0139cd09",
"metadata": {
"id": "0139cd09"
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "879115e1",
"metadata": {
"id": "879115e1"
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "0da7c466",
"metadata": {
"id": "0da7c466"
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "d381e880",
"metadata": {
"id": "d381e880"
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.12"
},
"colab": {
"provenance": [],
"include_colab_link": true
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment