{"id":19694104,"url":"https://github.com/agent-006/python","last_synced_at":"2025-08-10T06:08:28.282Z","repository":{"id":229575509,"uuid":"776551065","full_name":"Agent-006/python","owner":"Agent-006","description":null,"archived":false,"fork":false,"pushed_at":"2024-03-30T07:49:59.000Z","size":798,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-27T12:38:46.672Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Agent-006.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-23T20:20:48.000Z","updated_at":"2024-03-25T06:53:27.000Z","dependencies_parsed_at":"2024-03-29T19:31:51.924Z","dependency_job_id":"7f9bfbf7-e3c4-4b04-8c63-ee6ce62917ad","html_url":"https://github.com/Agent-006/python","commit_stats":null,"previous_names":["agent-006/python"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Agent-006/python","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Agent-006%2Fpython","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Agent-006%2Fpython/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Agent-006%2Fpython/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Agent-006%2Fpython/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Agent-006","download_url":"https://codeload.github.com/Agent-006/python/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Agent-006%2Fpython/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269683183,"owners_count":24458628,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-10T02:00:08.965Z","response_time":71,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-11T19:20:21.441Z","updated_at":"2025-08-10T06:08:28.256Z","avatar_url":"https://github.com/Agent-006.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ⭐ Python ⭐\n\n\u003chr style= \"border-top: 1px dotted #ccc;\"\u003e\n\n## 🎯 What is python ? ✅\n\n-\u003e Python is a high-level programming language that is widely used for \\\nvarious purpose such as web development, data analysis, artificial intelligence, scientific computing, and more.\n\nIt was created by Guido van Rossum and first released in 1991.\\\nIt features a clear and concise syntax, which allows developers to write code quickly and efficiently. Python supports multiple programming paradigms, \\\nincluding porcedural, object-oriented, and functional programming.\n\n\u003chr style= \"border-top: 1px dotted #ccc;\"\u003e\n\n## 🎯 What is Byte-Code in python ? ✅\n\n-\u003e In python, bytecode refers to the intermediate representation of the source code that is generated by the Python interpreter. When you write a Python script or enter commands in the Python shell, the Python interpreter first tanslates the source code into bytecode before executing it.\n\nBytecode is a low-level, platform-independent representation of the souce code that is optimized for efficient execution by the Python virtual machine(PVM). It is not directly executable by the computer's hardware like machine code, but it serves as an intermidiary step between the source code and the execution.\n\nThe bytecode is stored in `.pyc` files (compiled Python files) or in memory if the code is entered interactively. These `.pyc` files are created by the interpreter to speed up the execution of Python programs by avoiding the need to recompile the source code every time it is executed.\n\nWhen you run a Python script, the interpreter checks if a corresponding `.pyc` file exists and if it is up-to-date with the source code. If the `.pyc` file exists and is up-to-date, the interpreter loads and executes the bytecode directly, speeding up the execution process. If the `.pyc` file is missing or outdated, the interpreter recompiles the source code into bytecode and then executes it.\n\nOverall, bytecode plays a crucial role in the execution of Python programs, providing a platform-independent and efficient representation of the source code for interpretation by the Python virtual machine.\n\n\u003chr style= \"border-top: 1px dotted #ccc;\"\u003e\n\n## 🎯 What is virtual machine in python ? ✅\n\n-\u003e In Python, the term \"virtual machine\" refers to the Python Virtual Machine (PVM). The PVM is an interpreter that executes Python bytecode. It is responsible for translating the bytecode generated from Python source code into machine code that can be understood and executed by the underlying hardware.\n\nThe PVM abstracts the underlying hardware architecture, providing a platform-independent runtime environment for Python programs. This means that Python code can be written and executed on any platform (such as Windows, macOS, or Linux) without modification, as long as the appropriate Python interpreter is available for that platform.\n\nThe PVM manages memory allocation, garbage collection, and other runtime tasks required for executing Python code. It also provides access to the Python standard library and any additional modules or packages that are installed.\n\nOverall, the Python Virtual Machine plays a crucial role in the execution of Python programs, providing a consistent and portable runtime environment across different platforms.\n\n![Project View](./assets/img/Screenshot%202024-03-24%20143612.png)\n\n\u003chr style= \"border-top: 1px dotted #ccc;\"\u003e\n\n## 🎯 What is frozen binaries in python ? ✅\n\n-\u003e In Python, frozen binaries typically refer to executable files that contain both the Python interpreter and the bytecode of a Python script, packaged together into a single standalone file. These frozen binaries are generated using tools like PyInstaller or cx_Freeze.\n\nWhen you freeze a Python script into a binary, the resulting executable includes the Python interpreter along with any necessary libraries and dependencies, allowing the program to be run on a system that doesn't have Python installed. This makes distribution and deployment of Python applications more convenient, as users don't need to install Python separately to run the application.\n\nFrozen binaries are often used for distributing Python applications as standalone executables, especially for deployment on systems where installing Python may not be feasible or desirable. They encapsulate the entire Python environment needed to run the application, making it easier to distribute and execute Python code across different platforms.\n\n\u003chr style= \"border-top: 1px dotted #ccc;\"\u003e\n\n## 🎯 Do you know what `__pychache__` means ? ✅\n\n-\u003e `__pycache__` is a directory automatically generated by Python to store compiled bytecode files (`.pyc` files) when a Python module is imported. This directory is created in the same directory as the Python script or module being executed.\n\nThe purpose of the `__pycache__` directory is to improve the performance of Python programs by caching compiled bytecode. When a Python module is imported, the interpreter checks if a corresponding `.pyc` file exists in the `__pycache__` directory. If the `.pyc` file exists and is up-to-date with the source code, the interpreter loads the bytecode from the `.pyc` file instead of recompiling the source code, which can save time and resources.\n\nThe `__pycache__` directory is automatically managed by Python and typically doesn't need manual intervention. It's safe to ignore or delete the `__pycache__` directory if necessary, as Python will recreate it as needed when modules are imported.\n\n🌟 Source Change \u0026 Python Version\\\n hello_chai.cpython-312.pyc\n\n🌲 Works only for imported files\\\n🌲 not for top level files (parent or root directory)\n\n\u003chr style= \"border-top: 1px dotted #ccc;\"\u003e\n\ndef\nvariables\nengine\nbytecode machinecode\n\n# 🎯 Immutable and mutable in python ✅\n\n-\u003e In python, data types can be classified as either mutable or immutable, depending on whether their values can be changed after they are created.\n\n1. \u003cb\u003eImmutable Data Types:\u003c/b\u003e Immutable data types are those whose values cannot be changed after they are created. Any operation that appears to modify an immutable object actually creates a new object with the modified value. Examples of immutable data types in Python include:\\\n   🌲int (integer)\\\n   🌲float (floating-point number)\\\n   🌲str (string)\\\n   🌲tuple\\\n   🌲frozenset\n\n⭐ Example:\n\n    username = \"sagar\"\n\n⭐ Example:\n\n    x = 10\n    y = x\n    print(x) # gives output as 10\n    print(y) # gives output as 10\n    x = 15\n    print(x) # gives output as 15\n    print(y) # gives output as 10\n\n![diagram_explaination](./assets/img/Screenshot%202024-03-24%20231752.png)\n\n📒 In the above two examples, you can understand the concept of immutable and mutable in python only by the diagram. Whenever we create a variable and assign a immutable type value to it, It's value is stored in the memory and the variable name(username) is then takes refrence of that memory location.\n\nSo, whenever we assign a new value to the immutable data type, a new memory location is assigned and it's reference is given to the variable. It previous value of that variable is removed by the garbage collector of python and then removed from the memory if not in use or referenced by any other variable.\n\n\u003chr style= \"border-top: 1px dotted #ccc;\"\u003e\n\n# 🎯 Data(Object)-Types in python ✅\n\n-\u003e\n\n🌲 Number : 1234, 3.14, 3+4j, 0b111, Decimal(), Fraction()\\\n🌲 String : 'spam', \"Bob's\", b'a\\x01c', u'sp\\xc4m'\\\n🌲 List : [1, [2, 'three'], 4.5], list(range(10))\\\n🌲 Tuple : (1, 'spam', 4, 'U'), tuple('spam'), namedtuple\\\n🌲 Dictionary : {'food': 'spam', 'taste': 'yum'}, dict(hours=10)\\\n🌲 Set : set('abc'), {'a', 'b', 'c'}\\\n🌲 File : open('eggs.txt'), open(r'C:\\ham.bin', 'wb')\\\n🌲 Boolean : True, False\\\n🌲 None : None\\\n🌲 Functions, modules, classes\n\n⭐ Advance: Decorators, Generators, Iterators, MetaProgramming\n\n\u003chr style= \"border-top: 1px dotted #ccc;\"\u003e\n\n# 🎯 Internal working of python | copy, refrence counts, slice ✅\n\n-\u003e Refer to this link:\n\n🔗 [Video explanation 📽️](https://www.youtube.com/watch?v=brp5aiuWfso\u0026list=PLu71SKxNbfoBsMugTFALhdLlZ5VOqCg2s\u0026index=7)\n\n\u003chr style= \"border-top: 1px dotted #ccc;\"\u003e\n\n# 🎯 Numbers in python ✅\n\n-\u003e decimal context manager\n\n🔗 [Video explanation 📽️](https://www.youtube.com/watch?v=E4GNbP4SbKM\u0026list=PLu71SKxNbfoBsMugTFALhdLlZ5VOqCg2s\u0026index=8)\n\n\u003chr style= \"border-top: 1px dotted #ccc;\"\u003e\n\n# 🎯 Strings in python ✅\n\n-\u003e\n\n```\n\u003e\u003e\u003e num_list = \"0123456789\"\n\u003e\u003e\u003e num_list[:]\n'0123456789'\n\u003e\u003e\u003e num_list[3:]\n'3456789'\n\u003e\u003e\u003e num_list[:7]\n'0123456'\n\u003e\u003e\u003e num_list[0:7:1]\n'0123456'\n\u003e\u003e\u003e num_list[0:7:2]\n'0246'\n\u003e\u003e\u003e num_list[0:7:4]\n'04'\n\u003e\u003e\u003e num_list[0:7:4]\n'04'\n\u003e\u003e\u003e num_list[0:7:-1]\n''\n\u003e\u003e\u003e num_list[0:7:-2]\n''\n\u003e\u003e\u003e num_list[::-2]\n'97531'\n\u003e\u003e\u003e num_list[::]\n'0123456789'\n\u003e\u003e\u003e num_list[::-1]\n'9876543210'\n\u003e\u003e\u003e num_list[::2]\n'02468'\n\u003e\u003e\u003e chai = 'Masala chai'\n\u003e\u003e\u003e chai\n'Masala chai'\n\u003e\u003e\u003e print(chai.lower())\nmasala chai\n\u003e\u003e\u003e print(chai.upper())\nMASALA CHAI\n\u003e\u003e\u003e chai\n'Masala chai'\n\u003e\u003e\u003e chai = \"    Masala Chai    \"\n\u003e\u003e\u003e chia\nTraceback (most recent call last):\n  File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\nNameError: name 'chia' is not defined\n\u003e\u003e\u003e chai\n'    Masala Chai    '\n\u003e\u003e\u003e print(chai.strip())\nMasala Chai\n\u003e\u003e\u003e chai = \"Lemon Chai\"\n\u003e\u003e\u003e chia\nTraceback (most recent call last):\n  File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\nNameError: name 'chia' is not defined\n\u003e\u003e\u003e chai\n'Lemon Chai'\n\u003e\u003e\u003e print(chai.replace(\"Lemon\", \"Ginger\"))\nGinger Chai\n\u003e\u003e\u003e chai\n'Lemon Chai'\n\u003e\u003e\u003e chai = \"Lemon, Ginger, Masala, Mint\"\n\u003e\u003e\u003e chia\nTraceback (most recent call last):\n  File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\nNameError: name 'chia' is not defined\n\u003e\u003e\u003e chai\n'Lemon, Ginger, Masala, Mint'\n\u003e\u003e\u003e print(chai.split())\n['Lemon,', 'Ginger,', 'Masala,', 'Mint']\n\u003e\u003e\u003e print(chai.split(\", \"))\n['Lemon', 'Ginger', 'Masala', 'Mint']\n\u003e\u003e\u003e print(chai.split(\",\"))\n['Lemon', ' Ginger', ' Masala', ' Mint']\n\u003e\u003e\u003e chai = \"Masala Chai\"\n\u003e\u003e\u003e print(chai.find(\"Chai\"))\n7\n\u003e\u003e\u003e chai = \"Masala Chai Chai Chai\"\n\u003e\u003e\u003e print(chai.count(\"Chai\"))\n3\n\u003e\u003e\u003e chai_type = \"Masala\"\n\u003e\u003e\u003e quantity = 2\n\u003e\u003e\u003e order = \"I ordered {} cups of {} chai\"\n\u003e\u003e\u003e order\n'I ordered {} cups of {} chai'\n\u003e\u003e\u003e print(order.format(quantity, chai_type))\nI ordered 2 cups of Masala chai\n\u003e\u003e\u003e chai_variety = [\"Lemon\", \"Masala\", \"Ginger\"]\n\u003e\u003e\u003e chai_variety\n['Lemon', 'Masala', 'Ginger']\n\u003e\u003e\u003e print(chai_variety.toStr())\nTraceback (most recent call last):\n  File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\nAttributeError: 'list' object has no attribute 'toStr'\n\u003e\u003e\u003e print(\"\".join(chai_variety))\nLemonMasalaGinger\n\u003e\u003e\u003e print(\" \".join(chai_variety))\nLemon Masala Ginger\n\u003e\u003e\u003e print(\" ,\".join(chai_variety))\nLemon ,Masala ,Ginger\n\u003e\u003e\u003e print(\", \".join(chai_variety))\nLemon, Masala, Ginger\n\u003e\u003e\u003e chai = \"Masala Chai\"\n\u003e\u003e\u003e chai\n'Masala Chai'\n\u003e\u003e\u003e print(len(chai))\n11\n\u003e\u003e\u003e for letter in chai:\n...     print(letter)\n...\nM\na\ns\na\nl\na\n\nC\nh\na\ni\n\u003e\u003e\u003e chai = \"He said, \\\"Masala chai is awesome\\\" \"\n\u003e\u003e\u003e chai\n'He said, \"Masala chai is awesome\" '\n\u003e\u003e\u003e chai = \"Masala\\nChai\"\n\u003e\u003e\u003e chai\n'Masala\\nChai'\n\u003e\u003e\u003e print(chai)\nMasala\nChai\n\u003e\u003e\u003e chai = r\"Masala\\nChai\"\n\u003e\u003e\u003e print(chai)\nMasala\\nChai\n\u003e\u003e\u003e chai = r\"c:\\user\\pwd\\\"\n  File \"\u003cstdin\u003e\", line 1\n    chai = r\"c:\\user\\pwd\\\"\n           ^\nSyntaxError: unterminated string literal (detected at line 1)\n\u003e\u003e\u003e chai = r\"c\\:\\user\\pwd\\\"\n  File \"\u003cstdin\u003e\", line 1\n    chai = r\"c\\:\\user\\pwd\\\"\n           ^\nSyntaxError: unterminated string literal (detected at line 1)\n\u003e\u003e\u003e chai = r\"c:\\\\user\\\\pwd\\\\\"\n\u003e\u003e\u003e chai\n'c:\\\\\\\\user\\\\\\\\pwd\\\\\\\\'\n\u003e\u003e\u003e print(chai)\nc:\\\\user\\\\pwd\\\\\n\u003e\u003e\u003e chai = r\"c\\:\\user\\pwd\"\n\u003e\u003e\u003e print(chai)\nc\\:\\user\\pwd\n\u003e\u003e\u003e chai = r\"c:\\user\\pwd\\\"\n  File \"\u003cstdin\u003e\", line 1\n    chai = r\"c:\\user\\pwd\\\"\n           ^\nSyntaxError: unterminated string literal (detected at line 1)\n\u003e\u003e\u003e chai = r\"c:\\user\\pwd\"\n\u003e\u003e\u003e print(chai)\nc:\\user\\pwd\n\u003e\u003e\u003e chai = \"Masala Chai\"\n\u003e\u003e\u003e print(\"Masala\" in chai)\nTrue\n\u003e\u003e\u003e print(\"Masalaa\" in chai)\nFalse\n```\n\n\u003chr style= \"border-top: 1px dotted #ccc;\"\u003e\n\n# 🎯 List in python ✅\n\n```\n\u003e\u003e\u003e tea_varieties = [\"Black\", \"Green\", \"Oolong\", \"White\"]\n\u003e\u003e\u003e print(tea_varieties)\n['Black', 'Green', 'Oolong', 'White']\n\u003e\u003e\u003e print(tea_varieties[0])\nBlack\n\u003e\u003e\u003e print(tea_varieties[-1])\nWhite\n\u003e\u003e\u003e print(tea_varieties[1:3])\n['Green', 'Oolong']\n\u003e\u003e\u003e print(tea_varieties[:3])\n['Black', 'Green', 'Oolong']\n\u003e\u003e\u003e print(tea_varieties[:2])\n['Black', 'Green']\n\u003e\u003e\u003e print(tea_varieties[:2:2])\n['Black']\n\u003e\u003e\u003e print(tea_varieties[:2:-2])\n['White']\n\u003e\u003e\u003e print(tea_varieties[::-2])\n['White', 'Green']\n\u003e\u003e\u003e print(tea_varieties[::-1])\n['White', 'Oolong', 'Green', 'Black']\n\u003e\u003e\u003e tea_varieties[3] = \"Herbal\"\n\u003e\u003e\u003e print(tea_varieties\n... print(tea_varieties\n  File \"\u003cstdin\u003e\", line 1\n    print(tea_varieties\n          ^^^^^^^^^^^^\nSyntaxError: invalid syntax. Perhaps you forgot a comma?\n\u003e\u003e\u003e print(tea_varieties)\n['Black', 'Green', 'Oolong', 'Herbal']\n\u003e\u003e\u003e tea_varieties[1:2]\n['Green']\n\u003e\u003e\u003e tea_varieties[1:2] = \"Lemon\"\n\u003e\u003e\u003e tea_varieties[1:2]\n['L']\n\u003e\u003e\u003e tea_varieties\n['Black', 'L', 'e', 'm', 'o', 'n', 'Oolong', 'Herbal']\n\u003e\u003e\u003e tea_varieties = [\"Black\", \"Green\", \"Oolong\", \"White\"]\n\u003e\u003e\u003e print(tea_varieties)\n['Black', 'Green', 'Oolong', 'White']\n\u003e\u003e\u003e tea_varieties[1:2]\n['Green']\n\u003e\u003e\u003e tea_varieties[1:2] = [\"Lemon\"]\n\u003e\u003e\u003e tea_varieties[1:2]\n['Lemon']\n\u003e\u003e\u003e print(tea_varieties)\n['Black', 'Lemon', 'Oolong', 'White']\n\u003e\u003e\u003e tea_varieties[1:3]\n['Lemon', 'Oolong']\n\u003e\u003e\u003e tea_varieties[1:3] = [\"Green\", \"Masala\"]\n\u003e\u003e\u003e tea_varieties[1:3]\n['Green', 'Masala']\n\u003e\u003e\u003e print(tea_varieties)\n['Black', 'Green', 'Masala', 'White']\n\u003e\u003e\u003e tea_varieties[1:1]\n[]\n\u003e\u003e\u003e tea_varieties[1:1] = [\"test\", \"test\"]\n\u003e\u003e\u003e tea_varieties[1:1]\n[]\n\u003e\u003e\u003e print(tea_varieties)\n['Black', 'test', 'test', 'Green', 'Masala', 'White']\n\u003e\u003e\u003e tea_varieties[1:2]\n['test']\n\u003e\u003e\u003e tea_varieties[1:3]\n['test', 'test']\n\u003e\u003e\u003e tea_varieties[1:3] = []\n\u003e\u003e\u003e print(tea_varieties)\n['Black', 'Green', 'Masala', 'White']\n\u003e\u003e\u003e for tea in tea_varieties:\n...     print(tea)\n...\nBlack\nGreen\nMasala\nWhite\n\u003e\u003e\u003e for tea in tea_varieties:\n...     print(tea, end=\"-\")\n...\nBlack-Green-Masala-White-\u003e\u003e\u003e\n\u003e\u003e\u003e if \"Oolong\" in tea_varieties:\n...     print(\"I have Oolong tea\")\n...\n\u003e\u003e\u003e tea_varieties.append(\"Oolong\")\n\u003e\u003e\u003e if \"Oolong\" in tea_varieties:\n...     print(\"I have Oolong tea\")\n...\nI have Oolong tea\n\u003e\u003e\u003e tea_varieties.pop()\n'Oolong'\n\u003e\u003e\u003e tea_varieties\n['Black', 'Green', 'Masala', 'White']\n\u003e\u003e\u003e tea_varieties.remove(\"Green\")\n\u003e\u003e\u003e tea_varieties\n['Black', 'Masala', 'White']\n\u003e\u003e\u003e tea_varieties.insert(1, \"Green\")\n\u003e\u003e\u003e tea_varieties\n['Black', 'Green', 'Masala', 'White']\n\u003e\u003e\u003e tea_varieties_copy = tea_varieties.copy()\n\u003e\u003e\u003e tea_varieties_copy.append(\"Lemon\")\n\u003e\u003e\u003e tea_varieties_copy\n['Black', 'Green', 'Masala', 'White', 'Lemon']\n\u003e\u003e\u003e tea_varieties\n['Black', 'Green', 'Masala', 'White']\n\u003e\u003e\u003e squared_nums = [x**2 for x in range(10)]\n\u003e\u003e\u003e squared_nums\n[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]\n\u003e\u003e\u003e cube_num = [y**3 for y in range(10)]\n\u003e\u003e\u003e cube_num\n[0, 1, 8, 27, 64, 125, 216, 343, 512, 729]\n```\n\n\u003chr style= \"border-top: 1px dotted #ccc;\"\u003e\n\n# 🎯 Dictionary in python ✅\n\n-\u003e\n\n```\n\u003e\u003e\u003e chai_types = {\"Masala\": \"Spicy\", \"Ginger\": \"Zesty\", \"Green\": \"Mild\"}\n\u003e\u003e\u003e chai_types\n{'Masala': 'Spicy', 'Ginger': 'Zesty', 'Green': 'Mild'}\n\u003e\u003e\u003e chai_types[0]\nTraceback (most recent call last):\n  File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\nKeyError: 0\n\u003e\u003e\u003e chai_types[\"Masala\"]\n'Spicy'\n\u003e\u003e\u003e chai_types.get('Ginger')\n'Zesty'\n\u003e\u003e\u003e chai_types.get('Gingery')\n\u003e\u003e\u003e chai_types['Green'] = 'Fresh'\n\u003e\u003e\u003e chai_types\n{'Masala': 'Spicy', 'Ginger': 'Zesty', 'Green': 'Fresh'}\n\u003e\u003e\u003e for chai in chai_types:\n...     print(chai)\n...\nMasala\nGinger\nGreen\n\u003e\u003e\u003e for chai in chai_types:\n...     print(chai, chai_types[chai])\n...\nMasala Spicy\nGinger Zesty\nGreen Fresh\n\u003e\u003e\u003e for key, values in chai_types.items():\n...     print(key, values)\n...\nMasala Spicy\nGinger Zesty\nGreen Fresh\n\u003e\u003e\u003e if \"Masala\" in chai_types:\n...     print('I have masala chai')\n...\nI have masala chai\n\u003e\u003e\u003e print(len(chai_types))\n3\n\u003e\u003e\u003e chai_types\n{'Masala': 'Spicy', 'Ginger': 'Zesty', 'Green': 'Fresh'}\n\u003e\u003e\u003e chai_types[\"Earl Grey\"] = \"Citrus\"\n\u003e\u003e\u003e chai_types\n{'Masala': 'Spicy', 'Ginger': 'Zesty', 'Green': 'Fresh', 'Earl Grey': 'Citrus'}\n\u003e\u003e\u003e chai_types.pop(\"Ginger\")\n'Zesty'\n\u003e\u003e\u003e chai_types\n{'Masala': 'Spicy', 'Green': 'Fresh', 'Earl Grey': 'Citrus'}\n\u003e\u003e\u003e chai_types.pop()\nTraceback (most recent call last):\n  File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\nTypeError: pop expected at least 1 argument, got 0\n\u003e\u003e\u003e chai_types.popitem()\n('Earl Grey', 'Citrus')\n\u003e\u003e\u003e chai_types\n{'Masala': 'Spicy', 'Green': 'Fresh'}\n\u003e\u003e\u003e del chai_types[\"Green\"]\n\u003e\u003e\u003e chai_types\n{'Masala': 'Spicy'}\n\u003e\u003e\u003e chai_types_copy = chai_types.copy()\n\u003e\u003e\u003e tea_shop = {\n... \"chai\": {'Masala' : 'Spicy', 'Ginger' : 'Zesty'},\n... \"Tea\" : {'Green' : 'Mild', 'Black' : 'Strong'}\n... }\n\u003e\u003e\u003e tea_shop\n{'chai': {'Masala': 'Spicy', 'Ginger': 'Zesty'}, 'Tea': {'Green': 'Mild', 'Black': 'Strong'}}\n\u003e\u003e\u003e tea_shop['chai']\n{'Masala': 'Spicy', 'Ginger': 'Zesty'}\n\u003e\u003e\u003e tea_shop['chai']['Ginger']\n'Zesty'\n\u003e\u003e\u003e squared_nums = {x:x**2 for x in range(6)}\n\u003e\u003e\u003e squared_nums\n{0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25}\n\u003e\u003e\u003e squared_nums.clear()\n\u003e\u003e\u003e squared_nums\n{}\n\u003e\u003e\u003e keys = ['Masala', 'Ginger', 'Lemon']\n\u003e\u003e\u003e keys\n['Masala', 'Ginger', 'Lemon']\n\u003e\u003e\u003e default_value = 'Delicious'\n\u003e\u003e\u003e new_dict = dict.fromkeys(keys, default_value)\n\u003e\u003e\u003e new_dict\n{'Masala': 'Delicious', 'Ginger': 'Delicious', 'Lemon': 'Delicious'}\n\u003e\u003e\u003e new_dict = dict.fromkeys(keys, keys)\n\u003e\u003e\u003e new_dict\n{'Masala': ['Masala', 'Ginger', 'Lemon'], 'Ginger': ['Masala', 'Ginger', 'Lemon'], 'Lemon': ['Masala', 'Ginger', 'Lemon']}\n```\n\n\u003chr style= \"border-top: 1px dotted #ccc;\"\u003e\n\n# 🎯 Tuples in python ✅\n\n-\u003e\n\n```\n\u003e\u003e\u003e tea_types = ('Black', 'Green', 'Oolong')\n\u003e\u003e\u003e tea_types\n('Black', 'Green', 'Oolong')\n\u003e\u003e\u003e tea_types[0]\n'Black'\n\u003e\u003e\u003e tea_types[-1]\n'Oolong'\n\u003e\u003e\u003e tea_types[1:]\n('Green', 'Oolong')\n\u003e\u003e\u003e tea_types[0]\n'Black'\n\u003e\u003e\u003e tea_types[0] = 'Lemon'\nTraceback (most recent call last):\n  File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\nTypeError: 'tuple' object does not support item assignment\n\u003e\u003e\u003e len(tea_types)\n3\n\u003e\u003e\u003e more_tea = ('Herbal', 'Earl Grey')\n\u003e\u003e\u003e all_tea = more_tea + tea_types\n\u003e\u003e\u003e all_tea\n('Herbal', 'Earl Grey', 'Black', 'Green', 'Oolong')\n\u003e\u003e\u003e if 'Green' in all_tea:\n...     print('I have green tea')\n...\nI have green tea\n\u003e\u003e\u003e more_tea = ('Herbal', 'Earl Grey', 'Herbal')\n\u003e\u003e\u003e more_tea\n('Herbal', 'Earl Grey', 'Herbal')\n\u003e\u003e\u003e more_tea.count()\nTraceback (most recent call last):\n  File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\nTypeError: tuple.count() takes exactly one argument (0 given)\n\u003e\u003e\u003e more_tea.count('Herbal')\n2\n\u003e\u003e\u003e tea_types\n('Black', 'Green', 'Oolong')\n\u003e\u003e\u003e (black, green, Oologn) = tea_types\n\u003e\u003e\u003e black\n'Black'\n\u003e\u003e\u003e type(tea_types)\n\u003cclass 'tuple'\u003e\n\u003e\u003e\u003e\n```\n\n\u003chr style= \"border-top: 1px dotted #ccc;\"\u003e\n\n# 🎯 Conditional in python ✅\n\n-\u003e\n\n🌲 Classify a person's age group: Child( \u003c 13), Teenager(13-19), Adult(20-59), Senior(60+)\\\n🌲 Movie tickets are priced based on age: $12 for adults(18 and over), $8 for children. Everyone gets a $2 discount on Wednesday.\\\n🌲 Assign a letter grade based on a student's score: A(90-100), B(80-89), C(7079), D(60-69), F(below 60).\\\n🌲 Determine if a fruit is ripe, overripe, or unripe based on its color. (e.g., Banana: Green - Unripe, Yellow - Ripe, Brown - Overripe)\\\n🌲 Suggest an activity based on the weather(e.g., Sunny - Go for a walk, Rainy - Read a book, Snowy - Build a snowman).\\\n🌲 Choose a mode of transportation based on the distance (e.g., \u003c3 km: Walk, 3-15 km: Bike, \u003e15 km: Car).\\\n🌲 Customize a coffee order: \"Small\", \"Medium\", or \"Large\" with an option for \"Extra shot\" of expresso.\\\n🌲Check if a password is \"Weak\", \"Medium\", or \"Strong\". Criteria: \u003c6 chars (Weak), 6-10 chars (Medium), \u003e10 chars (Strong).\\\n🌲 Determine if a year is a leap year.(Leap years are divisible by 4, but not by 100 unless also divisible by 400).\\\n🌲 Recommend a type of pet food based on the pet's species and age. (e.g., Dog: \u003c2 years - Puppy food, Cat: \u003e5 years - Senior cat food).\n\n\u003chr style= \"border-top: 1px dotted #ccc;\"\u003e\n\n# 🎯 loops in python ✅\n\n🌲 \u003cb\u003eCounting Positive Numbers\u003c/b\u003e\\\n \u003cb\u003eProblem:\u003c/b\u003e Given a list of numbers, count how many are positive.\n\n```\nnumbers = [1, -2, 3, -4, 5, 6, -7, -8, 9, 10]\n```\n\n🌲 \u003cb\u003eSum of Even Numbers\u003c/b\u003e\\\n \u003cb\u003eProblem:\u003c/b\u003e Calculate the sum of even numbers up to a given number `n`.\n\n🌲 \u003cb\u003eMultiplication Table Printer\u003c/b\u003e\\\n \u003cb\u003eProblem:\u003c/b\u003e Print the multiplication table for a given number up to 10, but skip the fifth iteration.\n\n🌲 \u003cb\u003eReverse a string using a loop\u003c/b\u003e\\\n \u003cb\u003eProblem:\u003c/b\u003e Reverse a string using a loop.\n\n🌲 \u003cb\u003eFind the First Non-Repeated Character\u003c/b\u003e\\\n \u003cb\u003eProblem:\u003c/b\u003e Given a string, find the first non-repeated character.\n\n🌲 \u003cb\u003eFactorial Calculator\u003c/b\u003e\\\n \u003cb\u003eProblem:\u003c/b\u003e Compute the factorial of a number using a while loop.\n\n🌲 \u003cb\u003eValidate Input\u003c/b\u003e\\\n \u003cb\u003eProblem:\u003c/b\u003e Keep asking the user for input until they enter a number between 1 and 10.\n\n🌲 \u003cb\u003ePrime Number Checker\u003c/b\u003e\\\n \u003cb\u003eProblem:\u003c/b\u003e Check if a number is prime.\n\n🌲 \u003cb\u003eList Uniqueness Checker\u003c/b\u003e\\\n \u003cb\u003eProblem:\u003c/b\u003e Check if all elements in a list are unique. If a duplicate is found, exit the loop and print the duplicate.\n\n```\n items = [\"apple\", \"banana\", \"orange\", \"apple\", \"mango\"]\n```\n\n🌲 \u003cb\u003eExponential Backoff\u003c/b\u003e\\\n \u003cb\u003eProblem:\u003c/b\u003e Implement an exponential backoff strategy that doubles the wait time between retries, starting from 1 second, but stops after 5 retries.\n\n\u003chr style= \"border-top: 1px dotted #ccc;\"\u003e\n\n# 🎯 Behind the scene of loops in python ✅\n\n```\n\u003e\u003e\u003e file = open(\"chai.py\")\n\u003e\u003e\u003e file.readline()\n'import time\\n'\n\u003e\u003e\u003e file.readline()\n'print(\"chai is here\")\\n'\n\u003e\u003e\u003e file.readline()\n'username = \"sagar\"\\n'\n\u003e\u003e\u003e file.readline()\n'print(username)'\n\u003e\u003e\u003e file.readline()\n''\n\u003e\u003e\u003e file = open(\"chai.py\")\n\u003e\u003e\u003e file.__next__()\n'import time\\n'\n\u003e\u003e\u003e file.__next__()\n'print(\"chai is here\")\\n'\n\u003e\u003e\u003e file.__next__()\n'username = \"sagar\"\\n'\n\u003e\u003e\u003e file.__next__()\n'print(username)'\n\u003e\u003e\u003e file.__next__()\nTraceback (most recent call last):\n  File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\nStopIteration\n\u003e\u003e\u003e for line in open(\"chai.py\"):\n...     print(line)\n...\nimport time\n\nprint(\"chai is here\")\n\nusername = \"sagar\"\n\nprint(username)\n\u003e\u003e\u003e for line in open(\"chai.py\"):\n...     print(line, end='')\n...\nimport time\nprint(\"chai is here\")\nusername = \"sagar\"\nprint(username)\u003e\u003e\u003e\n\u003e\u003e\u003e file = open(\"chai.py\")\n\u003e\u003e\u003e while True:\n...     line = file.readline()\n...     if not line:\n...             break\n...     print(line, end='')\n...\nimport time\nprint(\"chai is here\")\nusername = \"sagar\"\nprint(username)\u003e\u003e\u003e\n\u003e\u003e\u003e test = 'sagar'\n\u003e\u003e\u003e if not test:\n...     print('chai')\n...\n\u003e\u003e\u003e test = ''\n\u003e\u003e\u003e if not test:\n...     print('chai')\n...\nchai\n\u003e\u003e\u003e myList = [1, 2, 3, 4]\n\u003e\u003e\u003e I = iter(myList)\n\u003e\u003e\u003e I\n\u003clist_iterator object at 0x000001605938A440\u003e\n\u003e\u003e\u003e I.__next__()\n1\n\u003e\u003e\u003e I\n\u003clist_iterator object at 0x000001605938A440\u003e\n\u003e\u003e\u003e I.__next__()\n2\n\u003e\u003e\u003e I.__next__()\n3\n\u003e\u003e\u003e I.__next__()\n4\n\u003e\u003e\u003e I.__next__()\nTraceback (most recent call last):\n  File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\nStopIteration\n\u003e\u003e\u003e file = open('chai.py')\n\u003e\u003e\u003e iter(file) is file\nTrue\n\u003e\u003e\u003e iter(file) is file.__iter__()\nTrue\n\u003e\u003e\u003e myNewList = [1, 2, 3]\n\u003e\u003e\u003e iter(myNewList) is myNewList\nFalse\n\u003e\u003e\u003e D = {'a': 1, 'b': 2}\n\u003e\u003e\u003e for key in D.keys():\n...     print(key)\n...\na\nb\n\u003e\u003e\u003e I = iter(D)\n\u003e\u003e\u003e I\n\u003cdict_keyiterator object at 0x00000160593935B0\u003e\n\u003e\u003e\u003e next(I)\n'a'\n\u003e\u003e\u003e next(I)\n'b'\n\u003e\u003e\u003e next(I)\nTraceback (most recent call last):\n  File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\nStopIteration\n\u003e\u003e\u003e range(5)\nrange(0, 5)\n\u003e\u003e\u003e R = range(5)\n\u003e\u003e\u003e R\nrange(0, 5)\n\u003e\u003e\u003e I = iter(R)\n\u003e\u003e\u003e I\n\u003crange_iterator object at 0x00000160593A7C50\u003e\n\u003e\u003e\u003e next(I)\n0\n\u003e\u003e\u003e next(I)\n1\n\u003e\u003e\u003e next(I)\n2\n\u003e\u003e\u003e next(I)\n3\n\u003e\u003e\u003e next(I)\n4\n\u003e\u003e\u003e next(I)\nTraceback (most recent call last):\n  File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\nStopIteration\n\u003e\u003e\u003e\n```\n\n\u003chr style= \"border-top: 1px dotted #ccc;\"\u003e\n\n# 🎯 Problems on functions in python ✅\n\n-\u003e In python, functions are most commonly know as `definition` or `function definition`.\n\n```\ndef square_of_num(number):\n    print(number ** 2)\n\nsquare_of_num(5)\n```\n\n### 🤔 Questions:\n\n🌲 \u003cb\u003eBasic Function Syntax\u003c/b\u003e\\\n \u003cb\u003eProblem:\u003c/b\u003e Write a function to calculate and return the square of a number.\n\n🌲 \u003cb\u003eFunction with Multiple Parameters\u003c/b\u003e\\\n \u003cb\u003eProblem:\u003c/b\u003e Create a function that takes two numbers as parameters and returns their sum.\n\n🌲 \u003cb\u003ePolymorphism in Functions\u003c/b\u003e\\\n \u003cb\u003eProblem:\u003c/b\u003e Write a function `multiply` that multiplies two numbers, but can also accept and multiply strings.\n\n🌲 \u003cb\u003eFunction Returning Multiple Values\u003c/b\u003e\\\n \u003cb\u003eProblem:\u003c/b\u003e Create a function that returns both the area and circumference of a circle given it's radius.\n\n🌲 \u003cb\u003eDefault Parameter Value\u003c/b\u003e\\\n \u003cb\u003eProblem:\u003c/b\u003e Write a function that greets a user. If no name is provided, it should greet with a default name.\n\n🌲 \u003cb\u003eLambda Function\u003c/b\u003e\\\n \u003cb\u003eProblem:\u003c/b\u003e Create a lambda function to compute the cube of a number.\n\n🌲 \u003cb\u003eFunction with \\*args\u003c/b\u003e\\\n \u003cb\u003eProblem:\u003c/b\u003e Write a function that takes variable number of arguments and return their sum.\n\n🌲 \u003cb\u003eFunction with \\*\\*kwargs\u003c/b\u003e\\\n \u003cb\u003eProblem:\u003c/b\u003e Create a function that accepts any number of keyword arguments and prints them in the format `key:value`.\n\n🌲 \u003cb\u003eGenerate Function with yield\u003c/b\u003e\\\n \u003cb\u003eProblem:\u003c/b\u003e Write a generator function that yields even numbers up to a specified limit.\n\n🌲 \u003cb\u003eRecursive Function\u003c/b\u003e\\\n \u003cb\u003eProblem:\u003c/b\u003e Create a recursive function to calculate the factorila of a number.\n\n\u003chr style= \"border-top: 1px dotted #ccc;\"\u003e\n\n# 🎯 Scopes and closure in python ✅\n\nbag theory\nclousure are also know as factory function\n\n```\nusername = \"thecoderwiz\"\n\ndef func():\n    # username = \"coder\"\n    print(username)\n\nprint(username)\nfunc()\n```\n\n```\nx = 99\n\ndef func2(y):\n    z = x + y\n    return z\n\nresult = func2(1)\nprint(result)\n\ndef func3():\n    global x\n    x = 88\nfunc3()\nprint(x)\n\n```\n\nClousure\n\n```\ndef f1():\n    x = 38\n    def f2():\n        print(x)\n    # f2()\n    return f2\nresult = f1()\nresult()\nprint(result)\n```\n\n```\ndef chaicoder(num):\n    def actual(x):\n        return x ** num\n    return actual\n\nresult = chaicoder(2)\nprint(result(2))\nprint(result)\n\n```\n\n\u003chr style= \"border-top: 1px dotted #ccc;\"\u003e\n\n# 🎯 Object Oriented Programming in python (OOPs) ✅\n\n🌲 \u003cb\u003eBasic Class and Object\u003c/b\u003e\\\n \u003cb\u003eProblem:\u003c/b\u003e Create a Car class with attributes like brand and model. Then create an instance of this class.\n\n🌲 \u003cb\u003eClass Method and Self\u003c/b\u003e\\\n \u003cb\u003eProblem:\u003c/b\u003e Add a method to the Car class that displays the full name of the car (brand and model).\n\n🌲 \u003cb\u003eInheritance\u003c/b\u003e\\\n \u003cb\u003eProblem:\u003c/b\u003e Create an ElectricCar class that inherits from the Car class and has an additional attribute battery_size.\n\n🌲 \u003cb\u003eEncapsulation\u003c/b\u003e\\\n \u003cb\u003eProblem:\u003c/b\u003e Modify the Car class to encapsulate the brand attribute, making it private, and provide a getter method for it.\n\n🌲 \u003cb\u003ePolymorphism\u003c/b\u003e\\\n \u003cb\u003eProblem:\u003c/b\u003e Demonstrate polymorphism by defining a method fuel_type in both Car and ElectricCar classes, but with different behaviours.\n\n🌲 \u003cb\u003eClass Variables\u003c/b\u003e\\\n \u003cb\u003eProblem:\u003c/b\u003e Add a class variable to Car that keeps track of the number of cars created.\n\n🌲 \u003cb\u003eStatic Method\u003c/b\u003e\\\n \u003cb\u003eProblem:\u003c/b\u003e Add a static method to the Car class that returns a general description of a car.\n\n🌲 \u003cb\u003eProperty Decorators\u003c/b\u003e\\\n \u003cb\u003eProblem:\u003c/b\u003e Use a property decorator in the Car class to make the model attribute read-only.\n\n🌲 \u003cb\u003eClass Inheritance and isinstance() Function\u003c/b\u003e\\\n \u003cb\u003eProblem:\u003c/b\u003e Demonstrate the use of isinstance() to check if my_tesla is an instance of Car and ElectricCar.\n\n🌲 \u003cb\u003eMultiple Inheritance\u003c/b\u003e\\\n \u003cb\u003eProblem:\u003c/b\u003e Create two classes Battery and Engine, and let the ElectricCar class inherit from both, demonstrating multiple inheritance.\n\n\u003chr style= \"border-top: 1px dotted #ccc;\"\u003e\n\n# 🎯 Decorators in python ✅\n\n🌲 \u003cb\u003eTiming Function Execution\u003c/b\u003e\\\n \u003cb\u003eProblem:\u003c/b\u003e Write a decorator that measures the time a function takes to execute.\n\n🌲 \u003cb\u003eDebugging Function Calls\u003c/b\u003e\\\n \u003cb\u003eProblem:\u003c/b\u003e Create a decorator to print the function name and the value of its arguments every time the function is called.\n\n🌲 \u003cb\u003eCache Return Values\u003c/b\u003e\\\n \u003cb\u003eProblem:\u003c/b\u003e Implement a decorator that chaches the return values of a function, so that when it's called with the same arguments, the cached value is returned instead of re-executing the function.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fagent-006%2Fpython","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fagent-006%2Fpython","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fagent-006%2Fpython/lists"}