{"id":18734556,"url":"https://github.com/aditya8raj/python","last_synced_at":"2025-11-15T03:30:16.306Z","repository":{"id":238358370,"uuid":"796388889","full_name":"aditya8Raj/python","owner":"aditya8Raj","description":"Notes that I made while learning Python","archived":false,"fork":false,"pushed_at":"2024-05-05T19:45:05.000Z","size":37,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-28T16:23:49.415Z","etag":null,"topics":["coding","coding-journey","learning-python","programming","python"],"latest_commit_sha":null,"homepage":"","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/aditya8Raj.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-05-05T19:38:52.000Z","updated_at":"2024-05-05T19:45:08.000Z","dependencies_parsed_at":"2024-05-05T20:49:16.212Z","dependency_job_id":null,"html_url":"https://github.com/aditya8Raj/python","commit_stats":null,"previous_names":["aditya8raj/python"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aditya8Raj%2Fpython","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aditya8Raj%2Fpython/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aditya8Raj%2Fpython/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aditya8Raj%2Fpython/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aditya8Raj","download_url":"https://codeload.github.com/aditya8Raj/python/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239606348,"owners_count":19667223,"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","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":["coding","coding-journey","learning-python","programming","python"],"created_at":"2024-11-07T15:14:11.328Z","updated_at":"2025-11-15T03:30:16.252Z","avatar_url":"https://github.com/aditya8Raj.png","language":"Python","readme":"\u003cbr\u003e\n\u003ca href='#'\u003e\n\u003cp align=\"center\"\u003e\n   \u003cimg width=\"100\" src=\"./python-logo.png\"\u003e\n\u003c/p\u003e\n\u003c/a\u003e\n\n\u003ch1 align='center'\u003ePython Notes\u003c/h1\u003e\n\n\u003ch6 align='center'\u003eThis is my notes that I made while learning to code in \u003cul\u003e\u003cb\u003ePython\u003c/b\u003e\u003c/ul\u003e\u003c/h6\u003e\n\u003cbr\u003e\n\n- Python is a high-level, interpreted, interactive and object-oriented scripting language. Python is designed to be highly readable. It uses English keywords frequently where as other languages use punctuation, and it has fewer syntactical constructions than other languages.\n\n- Python can be used for:\n  - Web Development (Server-Side)\n  - Software Development\n  - Mathematics\n  - System Scripting\n\n### 🔴 1. Variables\n\n- Variables are containers for storing data values.\n- Unlike other programming languages, Python has no command for declaring a variable.\n  eg:\n\n```python\nx = 5\ny = \"Hello, World!\"\nprint(x)\nprint(y)\n```\n\nOutput:\n\n```python\n5\nHello, World!\n```\n\n- Variable Names:\n  - A variable name must start with a letter or the underscore character.\n  - A variable name cannot start with a number.\n  - A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and \\_ ).\n  - Variable names are case-sensitive (age, Age and AGE are three different variables).\n  - The variable name must not contain any special characters like !, @, #, $, % etc.\n  - A variable name cannot be any of the Python keywords\n\n### 🔴 2. Comments\n\n- Comments can be used to explain Python code.\n- Comments can be used to make the code more readable.\n  eg:\n\n```python\n# This is a comment\nprint(\"Hello, World!\")\n```\n\nOutput:\n\n```python\nHello, World!\n```\n\n- Multi Line Comments\n\n```python\n\"\"\" This is a comment\nwritten in\nmore than just one line \"\"\"\nprint(\"Hello, World!\")\n```\n\nOutput:\n\n```python\nHello, World!\n```\n\n### 🔴 3. Concatanation\n\n- To combine both text and a variable, Python uses the + character:\n  eg:\n\n```python\nx = \"awesome\"\nprint(\"Python is \" + x)\n```\n\nOutput:\n\n```python\nPython is awesome\n```\n\n- You can also use the + character to add a variable to another variable:\n  eg:\n\n```python\nx = \"Python is \"\ny = \"awesome\"\nz = x + y\nprint(z)\n```\n\nOutput:\n\n```python\nPython is awesome\n```\n\n### 🔴 Data Types\n\n- In programming, data type is an important concept.\n- Variables can store data of different types, and different types can do different things.\n- Python has the following data types built-in by default, in these categories:\n\n  - Text Type: `str`\n  - Numeric Types: `int`, `float`, `complex`\n  - Sequence Types: `list`, `tuple`, `range`\n  - Mapping Type: `dict`\n  - Set Types: `set`, `frozenset`\n  - Boolean Type: `bool`\n  - Binary Types: `bytes`, `bytearray`, `memoryview`\n  - None Type: `NoneType`\n\n- Setting data types:\n\n```python\nx = \"Hello World\" # str\nx = 20 # int\nx = 20.5 # float\nx = 1j # complex\nx = [\"apple\", \"banana\", \"cherry\"] # list\nx = (\"apple\", \"banana\", \"cherry\") # tuple\nx = range(6) # range\nx = {\"name\" : \"John\", \"age\" : 36} # dict\nx = {\"apple\", \"banana\", \"cherry\"} # set\nx = frozenset({\"apple\", \"banana\", \"cherry\"}) # frozenset\nx = True # bool\nx = b\"Hello\" # bytes\nx = bytearray(5) # bytearray\nx = memoryview(bytes(5)) # memoryview\nx = None # NoneType\n```\n\n- Setting the Specific Data Type:\n\n```python\nx = str(\"Hello World\") # str\nx = int(20) # int\nx = float(20.5) # float\nx = complex(1j) # complex\nx = list((\"apple\", \"banana\", \"cherry\")) # list\nx = tuple((\"apple\", \"banana\", \"cherry\")) # tuple\nx = range(6) # range\nx = dict(name=\"John\", age=36) # dict\nx = set((\"apple\", \"banana\", \"cherry\")) # set\nx = frozenset((\"apple\", \"banana\", \"cherry\")) # frozenset\nx = bool(5) # bool\nx = bytes(5) # bytes\nx = bytearray(5) # bytearray\nx = memoryview(bytes(5)) # memoryview\n```\n\n### 🔴 4. Numbers\n\n- There are three numeric types in Python:\n\n  - int\n    - Int, or integer, is a whole number, positive or negative, without decimals, of unlimited length.\n  - float\n    - Float, or \"floating point number\" is a number, positive or negative, containing one or more decimals.\n  - complex\n    - Complex numbers are written with a \"j\" as the imaginary part.\n\n- Variables of numeric types are created when you assign a value to them:\n  eg:\n  ```python\n  x = 1 # int\n  y = 2.8 # float\n  z = 1j # complex\n  ```\n- Note: You cannot convert complext numbers into another number type.\n\n- Random Number:\n\n```python\nimport random\nprint(random.randrange(1, 10))\n```\n\nOutput:\n\n```python\n4\n```\n\n### 🔴 5. Casting\n\n- There may be times when you want to specify a type on to a variable. This can be done with casting.\n- Casting in python is therefore done using constructor functions:\n\n  - `int()`\n  - `float()`\n  - `str()`\n\n- Integers:\n\n  ```python\n  x = int(1) # x will be 1\n  y = int(2.8) # y will be 2\n  z = int(\"3\") # z will be 3\n  ```\n\n- Floats:\n\n  ```python\n  x = float(1) # x will be 1.0\n  y = float(2.8) # y will be 2.8\n  z = float(\"3\") # z will be 3.0\n  w = float(\"4.2\") # w will be 4.2\n  ```\n\n- Strings:\n\n  ```python\n  x = str(\"s1\") # x will be 's1'\n  y = str(2) # y will be '2'\n  z = str(3.0) # z will be '3.0'\n  ```\n\n### 🔴 6. Strings\n\n- Strings in python are surrounded by either single quotation marks, or double quotation marks.\n- `str` is the data type for strings in python.\n- You can display a string literal with the `print()` function:\n\n```python\nprint(\"Hello\")\nprint('Hello')\n```\n\nOutput:\n\n```python\nHello\nHello\n```\n\n- Assigning a string to a variable:\n\n```python\na = \"Hello\"\nprint(a)\n```\n\nOutput:\n\n```python\nHello\n```\n\n- Multiline Strings:\n\n```python\na = \"\"\"This is a multiline string,\ncome back, I still miss you,\nbut whocares,\nhahaha\"\"\"\nprint(a)\n```\n\nOutput:\n\n```python\nThis is a multiline string,\ncome back, I still miss you,\nbut whocares,\nhahaha\n```\n\n- Strings are Arrays:\n\n```python\na = \"Hello, World!\"\nprint(a[1])\n```\n\nOutput:\n\n```python\ne\n```\n\n- Slicing:\n\n```python\nb = \"Hello, World!\"\nprint(b[2:5])\n```\n\nOutput:\n\n```python\nllo\n```\n\n- Negative Indexing:\n\n```python\nb = \"Hello, World!\"\nprint(b[-5:-2])\n```\n\nOutput:\n\n```python\norl\n```\n\n- String Length:\n\n```python\na = \"Hello, World!\"\nprint(len(a))\n```\n\nOutput:\n\n```python\n13\n```\n\n- String Methods:\n\n  - `strip()` - Removes any whitespace from the beginning or the end\n  - `lower()` - Returns the string in lower case\n  - `upper()` - Returns the string in upper case\n  - `replace()` - Replaces a string with another string\n  - `split()` - Splits the string into substrings if it finds instances of the separator\n  - `capitalize()` - Converts the first character to upper case\n  - `casefold()` - Converts string into lower case\n  - `center()` - Returns a centered string\n  - `count()` - Returns the number of times a specified value occurs in a string\n  - `encode()` - Returns an encoded version of the string\n  - `endswith()` - Returns true if the string ends with the specified value\n  - `expandtabs()` - Sets the tab size of the string\n  - `find()` - Searches the string for a specified value and returns the position of where it was found\n  - `format()` - Formats specified values in a string\n  - `index()` - Searches the string for a specified value and returns the position of where it was found\n  - `isalnum()` - Returns True if all characters in the string are alphanumeric\n  - `isalpha()` - Returns True if all characters in the string are in the alphabet\n  - `isdecimal()` - Returns True if all characters in the string are decimals\n  - `isdigit()` - Returns True if all characters in the string are digits\n  - `isidentifier()` - Returns True if the string is an identifier\n  - `islower()` - Returns True if all characters in the string are lower case\n  - `isnumeric()` - Returns True if all characters in the string are numeric\n  - `isprintable()` - Returns True if all characters in the string are printable\n  - `isspace()` - Returns True if all characters in the string are whitespaces\n  - `istitle()` - Returns True if the string follows the rules of a title\n  - `isupper()` - Returns True if all characters in the string are upper case\n  - `join()` - Joins the elements of an iterable to the end of the string\n  - `ljust()` - Returns a left justified version of the string\n  - `lstrip()` - Returns a left trim version of the string\n  - `maketrans()` - Returns a translation table to be used in translations\n  - `partition()` - Returns a tuple where the string is parted into three parts\n  - `rfind()` - Searches the string for a specified value and returns the last position of where it was found\n  - `rindex()` - Searches the string for a specified value and returns the last position of where it was found\n  - `rjust()` - Returns a right justified version of the string\n  - `rpartition()` - Returns a tuple where the string is parted into three parts\n  - `rsplit()` - Splits the string at the specified separator, and returns a list\n  - `rstrip()` - Returns a right trim version of the string\n  - `splitlines()` - Splits the string at line breaks and returns a list\n  - `startswith()` - Returns true if the string starts with the specified value\n  - `swapcase()` - Swaps cases, lower case becomes upper case and vice versa\n  - `title()` - Converts the first character of each word to upper case\n  - `translate()` - Returns a translated string\n  - `zfill()` - Fills the string with a specified number of 0 values at the beginning\n\n- Check String:\n\n  - `isalnum()` - Returns True if all characters in the string are alphanumeric\n  - `isalpha()` - Returns True if all characters in the string are in the alphabet\n  - `isdecimal()` - Returns True if all characters in the string are decimals\n  - `isdigit()` - Returns True if all characters in the string are digits\n  - `isidentifier()` - Returns True if the string is an identifier\n  - `islower()` - Returns True if all characters in the string are lower case\n  - `isnumeric()` - Returns True if all characters in the string are numeric\n  - `isprintable()` - Returns True if all characters in the string are printable\n  - `isspace()` - Returns True if all characters in the string are whitespaces\n  - `istitle()` - Returns True if the string follows the rules of a title\n  - `isupper()` - Returns True if all characters in the string are upper case\n\n- String Format:\n\n  - `format()` - Formats specified values in a string\n  - `capitalize()` - Converts the first character to upper case\n  - `casefold()` - Converts string into lower case\n  - `center()` - Returns a centered string\n  - `count()` - Returns the number of times a specified value occurs in a string\n  - `encode()` - Returns an encoded version of the string\n  - `endswith()` - Returns true if the string ends with the specified value\n  - `expandtabs()` - Sets the tab size of the string\n  - `find()` - Searches the string for a specified value and returns the position of where it was found\n  - `index()` - Searches the string for a specified value and returns the position of where it was found\n  - `join()` - Joins the elements of an iterable to the end of the string\n  - `ljust()` - Returns a left justified version of the string\n  - `lower()` - Converts a string into lower case\n  - `lstrip()` - Returns a left trim version of the string\n  - `maketrans()` - Returns a translation table to be used in translations\n  - `partition()` - Returns a tuple where the string is parted into three parts\n  - `replace()` - Returns a string where a specified value is replaced with a specified value\n  - `rfind()` - Searches the string for a specified value and returns the last position of where it was found\n  - `rindex()` - Searches the string for a specified value and returns the last position of where it was found\n  - `rjust()` - Returns a right justified version of the string\n  - `rpartition()` - Returns a tuple where the string is parted into three parts\n  - `rsplit()` - Splits the string at the specified separator, and returns a list\n  - `rstrip()` - Returns a right trim version of the string\n  - `split()` - Splits the string at the specified separator, and returns a list\n  - `splitlines()` - Splits the string at line breaks and returns a list\n  - `startswith()` - Returns true if the string starts with the specified value\n  - `strip()` - Returns a trimmed version of the string\n  - `swapcase()` - Swaps cases, lower case becomes upper case and vice versa\n  - `title()` - Converts the first character of each word to upper case\n\n- Check if a certain phrase or character is present in a string\n\n  ```python\n  txt = \"God is watching.\"\n  x = \"NOT\" in txt\n  print(x)\n  ```\n\n  Output:\n\n  ```python\n  False\n  ```\n\n- Check if a certain phrase or character is NOT present in a string\n\n  ```python\n  txt = \"Saturn is my favourite planet.\"\n  x = \"Earth\" not in txt\n  print(x)\n  ```\n\n  Output:\n\n  ```python\n  True\n  ```\n\n- String Concatenation:\n\n  ```python\n  a = \"Hello\"\n  b = \"World\"\n  c = a + b\n  print(c)\n  ```\n\n  Output:\n\n  ```python\n  HelloWorld\n  ```\n\n- String Format:\n\n  ```python\n  age = 36\n  txt = \"My name is John, and I am {}\"\n  print(txt.format(age))\n  ```\n\n  Output:\n\n  ```python\n  My name is John, and I am 36\n  ```\n\n- Escape Character:\n\n  - To insert characters that are illegal in a string, use an escape character.\n  - An escape character is a backslash `\\` followed by the character you want to insert.\n  - An example of an illegal character is a double quote inside a string that is surrounded by double quotes:\n\n  ```python\n  txt = \"We are the so-called \\\"Vikings\\\" from the north.\"\n  print(txt)\n  ```\n\n  Output:\n\n  ```python\n  We are the so-called \"Vikings\" from the north.\n  ```\n\n### 🔴 7. Booleans\n\n- Booleans represent one of two values: `True` or `False`.\n- In programming you often need to know if an expression is `True` or `False`.\n\n### 🔴 8. Python Operators\n\n- Operators are used to perform operations on variables and values.\n- Python divides the operators in the following groups:\n\n  - Arithmetic operators\n  - Assignment operators\n  - Comparison operators\n  - Logical operators\n  - Identity operators\n  - Membership operators\n  - Bitwise operators\n\n- Arithmetic Operators:\n\n  - `+` - Addition\n  - `-` - Subtraction\n  - `*` - Multiplication\n  - `/` - Division\n  - `%` - Modulus\n  - `**` - Exponentiation\n  - `//` - Floor division\n\n- Assignment Operators:\n\n  - `=` - x = 5\n  - `+=` - x += 3\n  - `-=` - x -= 3\n  - `*=` - x \\*= 3\n  - `/=` - x /= 3\n  - `%=` - x %= 3\n  - `//=` - x //= 3\n  - `**=` - x \\*\\*= 3\n  - `\u0026=` - x \u0026= 3\n  - `|=` - x |= 3\n  - `^=` - x ^= 3\n  - `\u003e\u003e=` - x \u003e\u003e= 3\n  - `\u003c\u003c=` - x \u003c\u003c= 3\n\n- Comparison Operators:\n\n  - `==` - Equal\n  - `!=` - Not equal\n  - `\u003e` - Greater than\n  - `\u003c` - Less than\n  - `\u003e=` - Greater than or equal to\n  - `\u003c=` - Less than or equal to\n\n- Logical Operators:\n\n  - `and` - Returns True if both statements are true\n  - `or` - Returns True if one of the statements is true\n  - `not` - Reverse the result, returns False if the result is true\n\n- Identity Operators:\n\n  - `is` - Returns True if both variables are the same object\n  - `is not` - Returns True if both variables are not the same object\n\n- Membership Operators:\n\n  - `in` - Returns True if a sequence with the specified value is present in the object\n  - `not in` - Returns True if a sequence with the specified value is not present in the object\n\n- Bitwise Operators:\n  - `\u0026` - AND\n  - `|` - OR\n  - `^` - XOR\n  - `~` - NOT\n  - `\u003c\u003c` - Zero fill left shift\n  - `\u003e\u003e` - Signed right shift\n\n### 🔴 9. Lists\n\n- Lists are used to store multiple items in a single variable.\n- Lists are created using square brackets:\n\n```python\nthislist = [\"apple\", \"banana\", \"cherry\"]\nprint(thislist)\n```\n\nOutput:\n\n```python\n['apple', 'banana', 'cherry']\n```\n\n- List Items:\n\n  - List items are ordered, changeable, and allow duplicate values.\n  - List items are indexed, the first item has index [0], the second item has index [1] etc.\n\n- List Items - Data Types:\n\n  - List items can be of any data type:\n\n  ```python\n  list1 = [\"apple\", \"banana\", \"cherry\"]\n  list2 = [1, 5, 7, 9, 3]\n  list3 = [True, False, False]\n  ```\n\n- A list can contain different data types:\n\n  ```python\n  list1 = [\"apple\", \"banana\", \"cherry\"]\n  list2 = [1, 5, 7, 9, 3]\n  list3 = [True, False, False]\n  list4 = [\"apple\", 5, True, \"banana\", \"cherry\"]\n  ```\n\n- type():\n\n  - From Python's perspective, lists are defined as objects with the data type 'list':\n\n  ```python\n  mylist = [\"apple\", \"banana\", \"cherry\"]\n  print(type(mylist))\n  ```\n\n  Output:\n\n  ```python\n  \u003cclass 'list'\u003e\n  ```\n\n### 🔴 10. Tuples\n\n- Tuples are used to store multiple items in a single variable.\n- A tuple is a collection which is ordered and unchangeable.\n- Tuples are written with round brackets.\n\n```python\nthistuple = (\"apple\", \"banana\", \"cherry\")\nprint(thistuple)\n```\n\nOutput:\n\n```python\n('apple', 'banana', 'cherry')\n```\n\n- Tuple Items:\n\n  - Tuple items are ordered, unchangeable, and allow duplicate values.\n  - Tuple items are indexed, the first item has index [0], the second item has index [1] etc.\n\n- Tuple Items - Data Types:\n\n  - Tuple items can be of any data type:\n\n  ```python\n  tuple1 = (\"apple\", \"banana\", \"cherry\")\n  tuple2 = (1, 5, 7, 9, 3)\n  tuple3 = (True, False, False)\n  ```\n\n- A tuple can contain different data types:\n\n  ```python\n  tuple1 = (\"apple\", \"banana\", \"cherry\")\n  tuple2 = (1, 5, 7, 9, 3)\n  tuple3 = (True, False, False)\n  tuple4 = (\"apple\", 5, True, \"banana\", \"cherry\")\n  ```\n\n- type(): - From Python's perspective, tuples are defined as objects with the data type 'tuple':\n\n  ```python\n    mytuple = (\"apple\", \"banana\", \"cherry\")\n    print(type(mytuple))\n  ```\n\n  Output:\n\n  ```python\n    \u003cclass 'tuple'\u003e\n  ```\n\n### 🔴 11. Sets\n\n- Sets are used to store multiple items in a single variable.\n- A set is a collection which is both unordered and unindexed.\n- Sets are written with curly brackets.\n\n```python\nthisset = {\"apple\", \"banana\", \"cherry\"}\nprint(thisset)\n```\n\nOutput:\n\n```python\n{'apple', 'banana', 'cherry'}\n```\n\n- Set Items:\n\n  - Set items are unordered, unchangeable, and do not allow duplicate values.\n  - Set items are indexed, the first item has index [0], the second item has index [1] etc.\n\n- Set Items - Data Types:\n\n  - Set items can be of any data type:\n\n  ```python\n  set1 = {\"apple\", \"banana\", \"cherry\"}\n  set2 = {1, 5, 7, 9, 3}\n  set3 = {True, False, False}\n  ```\n\n- A set can contain different data types:\n\n  ```python\n  set1 = {\"apple\", \"banana\", \"cherry\"}\n  set2 = {1, 5, 7, 9, 3}\n  set3 = {True, False, False}\n  set4 = {\"apple\", 5, True, \"banana\", \"cherry\"}\n  ```\n\n- type(): - From Python's perspective, sets are defined as objects with the data type 'set':\n\n  ```python\n    myset = {\"apple\", \"banana\", \"cherry\"}\n    print(type(myset))\n  ```\n\n  Output:\n\n  ```python\n    \u003cclass 'set'\u003e\n  ```\n\n### 🔴 12. Dictionaries\n\n- Dictionaries are used to store data values in key:value pairs.\n- A dictionary is a collection which is ordered\\*, changeable and does not allow duplicates.\n- Dictionaries are written with curly brackets, and have keys and values.\n\n```python\nthisdict = {\n  \"brand\": \"Ford\",\n  \"model\": \"Mustang\",\n  \"year\": 1964\n}\nprint(thisdict)\n```\n\nOutput:\n\n```python\n{'brand': 'Ford', 'model': 'Mustang', 'year': 1964}\n```\n\n- Dictionary Items:\n\n  - Dictionary items are ordered, changeable, and does not allow duplicates.\n  - Dictionary items are indexed, the first item has index [0], the second item has index [1] etc.\n\n- Dictionary Items - Data Types:\n\n  - Dictionary items can be of any data type:\n\n  ```python\n  thisdict = {\n    \"brand\": \"Ford\",\n    \"electric\": False,\n    \"year\": 1964,\n    \"colors\": [\"red\", \"white\", \"blue\"]\n  }\n  ```\n\n- type(): - From Python's perspective, dictionaries are defined as objects with the data type 'dict':\n\n  ```python\n    mydict = {\n      \"brand\": \"Ford\",\n      \"model\": \"Mustang\",\n      \"year\": 1964\n    }\n    print(type(mydict))\n  ```\n\n  Output:\n\n  ```python\n    \u003cclass 'dict'\u003e\n  ```\n\n### 🔴 13. If...Else\n\n- Python supports the usual logical conditions from mathematics:\n\n  - Equals: `a == b`\n  - Not Equals: `a != b`\n  - Less than: `a \u003c b`\n  - Less than or equal to: `a \u003c= b`\n  - Greater than: `a \u003e b`\n  - Greater than or equal to: `a \u003e= b`\n\n```python\na = 33\nb = 200\nif b \u003e a:\n  print(\"b is greater than a\")\n```\n\nOutput:\n\n```python\nb is greater than a\n```\n\n- Elif:\n\n  - The `elif` keyword is pythons way of saying \"if the previous conditions were not true, then try this condition\".\n\n```python\na = 33\nb = 33\nif b \u003e a:\n  print(\"b is greater than a\")\nelif a == b:\n  print(\"a and b are equal\")\n```\n\nOutput:\n\n```python\na and b are equal\n```\n\n- Else:\n\n  - The `else` keyword catches anything which isn't caught by the preceding conditions.\n\n```python\na = 200\nb = 33\nif b \u003e a:\n  print(\"b is greater than a\")\nelif a == b:\n  print(\"a and b are equal\")\nelse:\n  print(\"a is greater than b\")\n```\n\nOutput:\n\n```python\na is greater than b\n```\n\n- Short Hand If:\n\n  - If you have only one statement to execute, you can put it on the same line as the `if` statement.\n\n```python\nif a \u003e b: print(\"a is greater than b\")\n```\n\nOutput:\n\n```python\na is greater than b\n```\n\n- Short Hand If...Else:\n\n  - If you have only one statement to execute, one for if, and one for else, you can put it all on the same line.\n\n```python\na = 2\nb = 330\nprint(\"A\") if a \u003e b else print(\"B\")\n```\n\nOutput:\n\n```python\nB\n```\n\n- And:\n\n  - The `and` keyword is a logical operator, and is used to combine conditional statements.\n\n```python\na = 200\nb = 33\nc = 500\nif a \u003e b and c \u003e a:\n  print(\"Both conditions are True\")\n```\n\nOutput:\n\n```python\nBoth conditions are True\n```\n\n- Or:\n\n  - The `or` keyword is a logical operator, and is used to combine conditional statements.\n\n```python\na = 200\nb = 33\nc = 500\nif a \u003e b or a \u003e c:\n  print(\"At least one of the conditions is True\")\n```\n\nOutput:\n\n```python\nAt least one of the conditions is True\n```\n\n- Nested If:\n\n  - You can have `if` statements inside `if` statements, this is called nested `if` statements.\n\n```python\nx = 41\nif x \u003e 10:\n  print(\"Above ten,\")\n  if x \u003e 20:\n    print(\"and also above 20!\")\n  else:\n    print(\"but not above 20.\")\n```\n\nOutput:\n\n```python\nAbove ten,\nand also above 20!\n```\n\n### 🔴 14. While Loops\n\n- With the `while` loop we can execute a set of statements as long as a condition is true.\n\n```python\ni = 1\nwhile i \u003c 6:\n  print(i)\n  i += 1\n```\n\nOutput:\n\n```python\n1\n2\n3\n4\n5\n```\n\n- The `break` Statement:\n\n  - With the `break` statement we can stop the loop even if the while condition is true.\n\n```python\ni = 1\nwhile i \u003c 6:\n  print(i)\n  if i == 3:\n    break\n  i += 1\n```\n\nOutput:\n\n```python\n1\n2\n3\n```\n\n- The `continue` Statement:\n\n  - With the `continue` statement we can stop the current iteration, and continue with the next.\n\n```python\ni = 0\nwhile i \u003c 6:\n  i += 1\n  if i == 3:\n    continue\n  print(i)\n```\n\nOutput:\n\n```python\n1\n2\n4\n5\n6\n```\n\n- The `else` Statement:\n\n  - With the `else` statement we can run a block of code once when the condition no longer is true.\n\n```python\ni = 1\nwhile i \u003c 6:\n  print(i)\n  i += 1\nelse:\n  print(\"i is no longer less than 6\")\n```\n\nOutput:\n\n```python\n1\n2\n3\n4\n5\ni is no longer less than 6\n```\n\n### 🔴 15. For Loops\n\n- A `for` loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a string).\n\n```python\nfruits = [\"apple\", \"banana\", \"cherry\"]\nfor x in fruits:\n  print(x)\n```\n\nOutput:\n\n```python\napple\nbanana\ncherry\n```\n\n- Looping Through a String:\n\n```python\nfor x in \"banana\":\n  print(x)\n```\n\nOutput:\n\n```python\nb\na\nn\na\nn\na\n```\n\n- The `break` Statement:\n\n  - With the `break` statement we can stop the loop before it has looped through all the items.\n\n```python\nfruits = [\"apple\", \"banana\", \"cherry\"]\nfor x in fruits:\n  print(x)\n  if x == \"banana\":\n    break\n```\n\nOutput:\n\n```python\napple\nbanana\n```\n\n- The `continue` Statement:\n\n  - With the `continue` statement we can stop the current iteration of the loop, and continue with the next.\n\n```python\nfruits = [\"apple\", \"banana\", \"cherry\"]\nfor x in fruits:\n  if x == \"banana\":\n    continue\n  print(x)\n```\n\nOutput:\n\n```python\napple\ncherry\n```\n\n- The `range()` Function:\n\n  - To loop through a set of code a specified number of times, we can use the `range()` function.\n\n```python\nfor x in range(6):\n  print(x)\n```\n\nOutput:\n\n```python\n0\n1\n2\n3\n4\n5\n```\n\n- The `range()` Function:\n\n  - The `range()` function defaults to 0 as a starting value, however it is possible to specify the starting value by adding a parameter: `range(2, 6)`, which means values from 2 to 6 (but not including 6):\n\n```python\nfor x in range(2, 6):\n  print(x)\n```\n\nOutput:\n\n```python\n2\n3\n4\n5\n```\n\n- The `range()` Function:\n\n  - The `range()` function defaults to increment the sequence by 1, however it is possible to specify the increment value by adding a third parameter: `range(2, 30, 3)`:\n\n```python\nfor x in range(2, 30, 3):\n  print(x)\n```\n\nOutput:\n\n```python\n2\n5\n8\n11\n14\n17\n20\n23\n26\n29\n```\n\n- Else in For Loop:\n\n  - The `else` keyword in a `for` loop specifies a block of code to be executed when the loop is finished.\n\n```python\nfor x in range(6):\n  print(x)\nelse:\n  print(\"Finally finished!\")\n```\n\nOutput:\n\n```python\n0\n1\n2\n3\n4\n5\nFinally finished!\n```\n\n- Nested Loops:\n\n  - A nested loop is a loop inside a loop.\n  - The \"inner loop\" will be executed one time for each iteration of the \"outer loop\".\n\n```python\nadj = [\"red\", \"big\", \"tasty\"]\nfruits = [\"apple\", \"banana\", \"cherry\"]\n\nfor x in adj:\n  for y in fruits:\n    print(x, y)\n```\n\nOutput:\n\n```python\nred apple\nred banana\nred cherry\nbig apple\nbig banana\nbig cherry\ntasty apple\ntasty banana\ntasty cherry\n```\n\n### 🔴 16. Functions\n\n- A function is a block of code which only runs when it is called.\n- You can pass data, known as parameters, into a function.\n- A function can return data as a result.\n\n```python\ndef my_function():\n  print(\"Hello from a function\")\n\nmy_function()\n```\n\nOutput:\n\n```python\nHello from a function\n```\n\n- Arguments:\n\n  - Information can be passed into functions as arguments.\n\n```python\ndef my_function(fname):\n  print(fname + \" Kumar\")\n\nmy_function(\"Rahul\")\nmy_function(\"Rohit\")\nmy_function(\"Raj\")\n```\n\nOutput:\n\n```python\nRahul Kumar\nRohit Kumar\nRaj Kumar\n```\n\n- Number of Arguments:\n\n  - By default, a function must be called with the correct number of arguments. Meaning that if your function expects 2 arguments, you have to call the function with 2 arguments, not more, and not less.\n\n```python\ndef my_function(fname, lname):\n  print(fname + \" \" + lname)\n\nmy_function(\"Rahul\", \"Kumar\")\n```\n\nOutput:\n\n```python\nRahul Kumar\n```\n\n- Arbitrary Arguments, `*args`:\n\n  - If you do not know how many arguments that will be passed into your function, add a `*` before the parameter name in the function definition.\n\n```python\ndef my_function(*kids):\n  print(\"The youngest child is \" + kids[2])\n\nmy_function(\"Emil\", \"Tobias\", \"Linus\")\n```\n\nOutput:\n\n```python\nThe youngest child is Linus\n```\n\n- Keyword Arguments:\n\n  - You can also send arguments with the key = value syntax.\n\n```python\ndef my_function(child3, child2, child1):\n  print(\"The youngest child is \" + child3)\n\nmy_function(child1 = \"Emil\", child2 = \"Tobias\", child3 = \"Linus\")\n```\n\nOutput:\n\n```python\nThe youngest child is Linus\n```\n\n- Arbitrary Keyword Arguments, `**kwargs`:\n\n  - If you do not know how many keyword arguments that will be passed into your function, add two asterisk: `**` before the parameter name in the function definition.\n\n```python\ndef my_function(**kid):\n  print(\"His last name is \" + kid[\"lname\"])\n\nmy_function(fname = \"Aditya\", lname = \"Raj\")\n```\n\nOutput:\n\n```python\nHis last name is Raj\n```\n\n- Default Parameter Value:\n\n  - The following example shows how to use a default parameter value.\n\n```python\ndef my_function(country = \"India\"):\n  print(\"I am from \" + country)\n\nmy_function(\"Sweden\")\nmy_function(\"Norway\")\nmy_function()\nmy_function(\"Brazil\")\n```\n\nOutput:\n\n```python\nI am from Sweden\nI am from Norway\nI am from India\nI am from Brazil\n```\n\n- Passing a List as an Argument:\n\n  - You can send any data types of argument to a function (string, number, list, dictionary etc.), and it will be treated as the same data type inside the function.\n\n```python\ndef my_function(food):\n  for x in food:\n    print(x)\n\nfruits = [\"apple\", \"banana\", \"cherry\"]\nmy_function(fruits)\n```\n\nOutput:\n\n```python\napple\nbanana\ncherry\n```\n\n- Return Values:\n\n  - To let a function return a value, use the `return` statement.\n\n```python\ndef my_function(x):\n  return 5 * x\n\nprint(my_function(3))\nprint(my_function(5))\nprint(my_function(9))\n```\n\nOutput:\n\n```python\n15\n25\n45\n```\n\n- The `pass` Statement:\n\n  - function definitions cannot be empty, but if you for some reason have a function definition with no content, put in the `pass` statement to avoid getting an error.\n\n```python\ndef myfunction():\n  pass\n```\n\n### 🔴 17. Lambda\n\n- A lambda function is a small anonymous function.\n- A lambda function can take any number of arguments, but can only have one expression.\n\n```python\nx = lambda a : a + 10\nprint(x(5))\n```\n\nOutput:\n\n```python\n15\n```\n\n- Lambda functions can take any number of arguments:\n\n```python\nx = lambda a, b : a * b\nprint(x(5, 6))\n```\n\nOutput:\n\n```python\n30\n```\n\n```python\nx = lambda a, b, c : a + b + c\nprint(x(5, 6, 2))\n```\n\nOutput:\n\n```python\n13\n```\n\n- Why Use Lambda Functions?\n\n  - The power of lambda is better shown when you use them as an anonymous function inside another function.\n\n```python\ndef myfunc(n):\n  return lambda a : a * n\n\nmydoubler = myfunc(2)\nmytripler = myfunc(3)\n\nprint(mydoubler(11))\nprint(mytripler(11))\n```\n\nOutput:\n\n```python\n22\n33\n```\n\n### 🔴 18. Arrays\n\n- Arrays are used to store multiple values in one single variable.\n\n```python\ncars = [\"Ford\", \"Volvo\", \"BMW\"]\n```\n\n- Access the Elements of an Array:\n\n  - You refer to an array element by referring to the index number.\n\n```python\nx = cars[0]\n```\n\n- Modify the value of the first array item:\n\n```python\ncars[0] = \"Toyota\"\n```\n\n- The Length of an Array:\n\n  - Use the `len()` method to return the length of an array (the number of elements in an array).\n\n```python\nx = len(cars)\n```\n\n- Looping Array Elements:\n\n  - You can use the `for` in loop to loop through all the elements of an array.\n\n```python\nfor x in cars:\n  print(x)\n```\n\n- Adding Array Elements:\n\n  - You can use the `append()` method to add an element to an array.\n\n```python\ncars.append(\"Honda\")\n```\n\n- Removing Array Elements:\n\n  - You can use the `pop()` method to remove an element from the array.\n\n```python\ncars.pop(1)\n```\n\n- Array Methods:\n\n  - `append()` - Adds an element at the end of the list\n  - `clear()` - Removes all the elements from the list\n  - `copy()` - Returns a copy of the list\n  - `count()` - Returns the number of elements with the specified value\n  - `extend()` - Add the elements of a list (or any iterable), to the end of the current list\n  - `index()` - Returns the index of the first element with the specified value\n  - `insert()` - Adds an element at the specified position\n  - `pop()` - Removes the element at the specified position\n  - `remove()` - Removes the first item with the specified value\n  - `reverse()` - Reverses the order of the list\n  - `sort()` - Sorts the list\n\n### 🔴 19. Classes/Objects\n\n- Python is an object oriented programming language.\n- Almost everything in Python is an object, with its properties and methods.\n\n- A Class is like an object constructor, or a \"blueprint\" for creating objects.\n\n```python\nclass MyClass:\n  x = 5\n```\n\n- Create an Object:\n\n  - Now we can use the class named `MyClass` to create objects.\n\n```python\np1 = MyClass()\nprint(p1.x)\n```\n\nOutput:\n\n```python\n5\n```\n\n- The `__init__()` Function:\n\n  - The examples above are classes and objects in their simplest form, and are not really useful in real life applications.\n  - To understand the meaning of classes we have to understand the built-in `__init__()` function.\n  - All classes have a function called `__init__()`, which is always executed when the class is being initiated.\n  - Use the `__init__()` function to assign values to object properties, or other operations that are necessary to do when the object is being created.\n\n```python\nclass Person:\n  def __init__(self, name, age):\n    self.name = name\n    self.age = age\n\np1 = Person(\"John\", 36)\n\nprint(p1.name)\nprint(p1.age)\n```\n\nOutput:\n\n```python\nJohn\n36\n```\n\n- Object Methods:\n\n  - Objects can also contain methods. Methods in objects are functions that belong to the object.\n\n```python\nclass Person:\n  def __init__(self, name, age):\n    self.name = name\n    self.age = age\n\n  def myfunc(self):\n    print(\"Hello my name is \" + self.name)\n\np1 = Person(\"John\", 36)\np1.myfunc()\n```\n\nOutput:\n\n```python\nHello my name is John\n```\n\n- The `self` Parameter:\n\n  - The `self` parameter is a reference to the current instance of the class, and is used to access variables that belong to the class.\n\n```python\nclass Person:\n  def __init__(mysillyobject, name, age):\n    mysillyobject.name = name\n    mysillyobject.age = age\n\n  def myfunc(abc):\n    print(\"Hello my name is \" + abc.name)\n\np1 = Person(\"John\", 36)\np1.myfunc()\n```\n\nOutput:\n\n```python\nHello my name is John\n```\n\n- Modify Object Properties:\n\n  - You can modify properties on objects like this:\n\n```python\np1.age = 40\n```\n\n- Delete Object Properties:\n\n  - You can delete properties on objects by using the `del` keyword:\n\n```python\ndel p1.age\n```\n\n- Delete Objects:\n\n  - You can delete objects by using the `del` keyword:\n\n```python\ndel p1\n```\n\n### 🔴 20. Inheritance\n\n- Inheritance allows us to define a class that inherits all the methods and properties from another class.\n\n- Parent Class:\n\n  - The class being inherited from is called the parent class.\n\n```python\nclass Person:\n  def __init__(self, fname, lname):\n    self.firstname = fname\n    self.lastname = lname\n\n  def printname(self):\n    print(self.firstname, self.lastname)\n\nx = Person(\"John\", \"Doe\")\nx.printname()\n```\n\nOutput:\n\n```python\nJohn Doe\n```\n\n- Child Class:\n\n  - The class that inherits from another class is called the child class.\n\n```python\nclass Student(Person):\n  pass\n```\n\n- Use the `super()` Function:\n\n  - The `super()` function is used to give access to methods and properties of a parent or sibling class.\n\n```python\nclass Student(Person):\n  def __init__(self, fname, lname):\n    super().__init__(fname, lname)\n\nx = Student(\"Aditya\", \"Raj\")\nx.printname()\n```\n\nOutput:\n\n```python\nAditya Raj\n```\n\n- Add Properties:\n\n  - Add a property called `graduationyear` to the `Student` class.\n\n```python\nclass Student(Person):\n  def __init__(self, fname, lname, year):\n    super().__init__(fname, lname)\n    self.graduationyear = year\n\nx = Student(\"Aditya\", \"Raj\", 2027)\n```\n\n- Add Methods:\n\n  - Add a method called `welcome` to the `Student` class.\n\n```python\nclass Student(Person):\n  def __init__(self, fname, lname, year):\n    super().__init__(fname, lname)\n    self.graduationyear = year\n\n  def welcome(self):\n    print(\"Welcome\", self.firstname, self.lastname, \"to the class of\", self.graduationyear)\n\nx = Student\n```\n\n### 🔴 21. User Input\n\n- Python allows for user input.\n\n```python\nusername = input(\"Enter username:\")\nprint(\"Username is: \" + username)\n```\n\nOutput:\n\n```python\nEnter username: Aditya\nUsername is: Aditya\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faditya8raj%2Fpython","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faditya8raj%2Fpython","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faditya8raj%2Fpython/lists"}