├── img ├── d0.png ├── l0.png ├── l1.png ├── s0.png ├── s3.png ├── t0.png ├── t5.png ├── t6.png ├── exlc.png ├── l6_1.png ├── l6_2.png ├── nd0.png ├── s16.png ├── set1.png ├── set2.png ├── set3.png ├── set4.png ├── set5.png ├── set6.png ├── set7.png ├── set8.png ├── set9.png ├── l14_1.png ├── set10.png ├── set11.png ├── set12.png └── dnld_rep.png ├── 006_Python_Sets_Methods ├── img │ ├── union.png │ ├── issubset.png │ ├── difference.png │ ├── isdisjoint.png │ ├── issuperset.png │ ├── intersection.png │ ├── symmetric_difference.png │ └── symmetric_difference_update.png ├── README.md ├── 012_Python_Set_issuperset().ipynb ├── 006_Python_Set_difference_update().ipynb ├── 015_Python_Set_symmetric_difference_update().ipynb ├── 011_Python_Set_issubset().ipynb ├── 013_Python_Set_pop().ipynb ├── 014_Python_Set_symmetric_difference().ipynb ├── 005_Python_Set_difference().ipynb ├── 003_Python_Set_copy().ipynb ├── 007_Python_Set_discard().ipynb └── 016_Python_Set_union().ipynb ├── 002_Python_String_Methods ├── img │ ├── find.png │ ├── rfind.png │ ├── format1.png │ └── format2.png ├── README.md ├── 031_Python_String_partition().ipynb ├── 033_Python_String_rpartition().ipynb ├── 001_Python_String_capitalize().ipynb ├── 002_Python_String_center().ipynb ├── 027_Python_String_swapcase().ipynb ├── 003_Python_String_casefold().ipynb ├── 040_Python_String_splitlines().ipynb ├── 021_Python_String_isupper().ipynb ├── 029_Python_String_rstrip().ipynb ├── 028_Python_String_lstrip().ipynb ├── 025_Python_String_lower().ipynb ├── 026_Python_String_upper().ipynb ├── 043_Python_String_zfill().ipynb ├── 018_Python_String_isprintable().ipynb ├── 015_Python_String_isidentifier().ipynb ├── 042_Python_String_title().ipynb └── 016_Python_String_islower().ipynb ├── 005_Python_Dictionary_Methods ├── img │ ├── nd0.png │ └── dictcomprehension.png ├── README.md ├── 001_Python_Dictionary_clear().ipynb ├── 008_Python_Dictionary_popitem().ipynb ├── 011_Python_Dictionary_values().ipynb ├── 006_Python_Dictionary_keys().ipynb ├── 005_Python_Dictionary_items().ipynb ├── 009_Python_Dictionary_setdefault().ipynb └── 010_Python_Dictionary_update().ipynb ├── 003_Python_List_Methods ├── README.md ├── 011_Python_List_clear().ipynb ├── 006_Python_List_count().ipynb ├── 004_Python_List_insert().ipynb └── 002_Python_List_append().ipynb ├── 004_Python_Tuple_Methods ├── README.md └── 001_Python_Tuple_count().ipynb ├── LICENSE └── countries_data.py /img/d0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/milaan9/02_Python_Datatypes/HEAD/img/d0.png -------------------------------------------------------------------------------- /img/l0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/milaan9/02_Python_Datatypes/HEAD/img/l0.png -------------------------------------------------------------------------------- /img/l1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/milaan9/02_Python_Datatypes/HEAD/img/l1.png -------------------------------------------------------------------------------- /img/s0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/milaan9/02_Python_Datatypes/HEAD/img/s0.png -------------------------------------------------------------------------------- /img/s3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/milaan9/02_Python_Datatypes/HEAD/img/s3.png -------------------------------------------------------------------------------- /img/t0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/milaan9/02_Python_Datatypes/HEAD/img/t0.png -------------------------------------------------------------------------------- /img/t5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/milaan9/02_Python_Datatypes/HEAD/img/t5.png -------------------------------------------------------------------------------- /img/t6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/milaan9/02_Python_Datatypes/HEAD/img/t6.png -------------------------------------------------------------------------------- /img/exlc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/milaan9/02_Python_Datatypes/HEAD/img/exlc.png -------------------------------------------------------------------------------- /img/l6_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/milaan9/02_Python_Datatypes/HEAD/img/l6_1.png -------------------------------------------------------------------------------- /img/l6_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/milaan9/02_Python_Datatypes/HEAD/img/l6_2.png -------------------------------------------------------------------------------- /img/nd0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/milaan9/02_Python_Datatypes/HEAD/img/nd0.png -------------------------------------------------------------------------------- /img/s16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/milaan9/02_Python_Datatypes/HEAD/img/s16.png -------------------------------------------------------------------------------- /img/set1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/milaan9/02_Python_Datatypes/HEAD/img/set1.png -------------------------------------------------------------------------------- /img/set2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/milaan9/02_Python_Datatypes/HEAD/img/set2.png -------------------------------------------------------------------------------- /img/set3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/milaan9/02_Python_Datatypes/HEAD/img/set3.png -------------------------------------------------------------------------------- /img/set4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/milaan9/02_Python_Datatypes/HEAD/img/set4.png -------------------------------------------------------------------------------- /img/set5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/milaan9/02_Python_Datatypes/HEAD/img/set5.png -------------------------------------------------------------------------------- /img/set6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/milaan9/02_Python_Datatypes/HEAD/img/set6.png -------------------------------------------------------------------------------- /img/set7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/milaan9/02_Python_Datatypes/HEAD/img/set7.png -------------------------------------------------------------------------------- /img/set8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/milaan9/02_Python_Datatypes/HEAD/img/set8.png -------------------------------------------------------------------------------- /img/set9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/milaan9/02_Python_Datatypes/HEAD/img/set9.png -------------------------------------------------------------------------------- /img/l14_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/milaan9/02_Python_Datatypes/HEAD/img/l14_1.png -------------------------------------------------------------------------------- /img/set10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/milaan9/02_Python_Datatypes/HEAD/img/set10.png -------------------------------------------------------------------------------- /img/set11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/milaan9/02_Python_Datatypes/HEAD/img/set11.png -------------------------------------------------------------------------------- /img/set12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/milaan9/02_Python_Datatypes/HEAD/img/set12.png -------------------------------------------------------------------------------- /img/dnld_rep.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/milaan9/02_Python_Datatypes/HEAD/img/dnld_rep.png -------------------------------------------------------------------------------- /006_Python_Sets_Methods/img/union.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/milaan9/02_Python_Datatypes/HEAD/006_Python_Sets_Methods/img/union.png -------------------------------------------------------------------------------- /002_Python_String_Methods/img/find.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/milaan9/02_Python_Datatypes/HEAD/002_Python_String_Methods/img/find.png -------------------------------------------------------------------------------- /002_Python_String_Methods/img/rfind.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/milaan9/02_Python_Datatypes/HEAD/002_Python_String_Methods/img/rfind.png -------------------------------------------------------------------------------- /006_Python_Sets_Methods/img/issubset.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/milaan9/02_Python_Datatypes/HEAD/006_Python_Sets_Methods/img/issubset.png -------------------------------------------------------------------------------- /002_Python_String_Methods/img/format1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/milaan9/02_Python_Datatypes/HEAD/002_Python_String_Methods/img/format1.png -------------------------------------------------------------------------------- /002_Python_String_Methods/img/format2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/milaan9/02_Python_Datatypes/HEAD/002_Python_String_Methods/img/format2.png -------------------------------------------------------------------------------- /005_Python_Dictionary_Methods/img/nd0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/milaan9/02_Python_Datatypes/HEAD/005_Python_Dictionary_Methods/img/nd0.png -------------------------------------------------------------------------------- /006_Python_Sets_Methods/img/difference.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/milaan9/02_Python_Datatypes/HEAD/006_Python_Sets_Methods/img/difference.png -------------------------------------------------------------------------------- /006_Python_Sets_Methods/img/isdisjoint.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/milaan9/02_Python_Datatypes/HEAD/006_Python_Sets_Methods/img/isdisjoint.png -------------------------------------------------------------------------------- /006_Python_Sets_Methods/img/issuperset.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/milaan9/02_Python_Datatypes/HEAD/006_Python_Sets_Methods/img/issuperset.png -------------------------------------------------------------------------------- /006_Python_Sets_Methods/img/intersection.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/milaan9/02_Python_Datatypes/HEAD/006_Python_Sets_Methods/img/intersection.png -------------------------------------------------------------------------------- /006_Python_Sets_Methods/img/symmetric_difference.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/milaan9/02_Python_Datatypes/HEAD/006_Python_Sets_Methods/img/symmetric_difference.png -------------------------------------------------------------------------------- /005_Python_Dictionary_Methods/img/dictcomprehension.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/milaan9/02_Python_Datatypes/HEAD/005_Python_Dictionary_Methods/img/dictcomprehension.png -------------------------------------------------------------------------------- /006_Python_Sets_Methods/img/symmetric_difference_update.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/milaan9/02_Python_Datatypes/HEAD/006_Python_Sets_Methods/img/symmetric_difference_update.png -------------------------------------------------------------------------------- /003_Python_List_Methods/README.md: -------------------------------------------------------------------------------- 1 |

2 | Last Commit 3 | 4 |

5 | 6 | 7 | 8 | # Python List Methods 9 | 10 | In this class, you'll learn about python list methods. 11 | -------------------------------------------------------------------------------- /006_Python_Sets_Methods/README.md: -------------------------------------------------------------------------------- 1 |

2 | Last Commit 3 | 4 |

5 | 6 | 7 | 8 | # Python Sets Methods 9 | 10 | In this class, you'll learn about python sets methods. 11 | -------------------------------------------------------------------------------- /002_Python_String_Methods/README.md: -------------------------------------------------------------------------------- 1 |

2 | Last Commit 3 | 4 |

5 | 6 | 7 | 8 | # Python String Methods 9 | 10 | In this class, you'll learn about python string methods. 11 | -------------------------------------------------------------------------------- /004_Python_Tuple_Methods/README.md: -------------------------------------------------------------------------------- 1 |

2 | Last Commit 3 | 4 |

5 | 6 | 7 | 8 | # Python Tuple Methods 9 | 10 | In this class, you'll learn about python tuple methods. 11 | -------------------------------------------------------------------------------- /005_Python_Dictionary_Methods/README.md: -------------------------------------------------------------------------------- 1 |

2 | Last Commit 3 | 4 |

5 | 6 | 7 | 8 | # Python Dictionary Methods 9 | 10 | In this class, you'll learn about python dictionary methods. 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 milaan9 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /005_Python_Dictionary_Methods/001_Python_Dictionary_clear().ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\n", 8 | "All the IPython Notebooks in this lecture series by Dr. Milan Parmar are available @ **[GitHub](https://github.com/milaan9/02_Python_Datatypes/tree/main/005_Python_Dictionary_Methods)**\n", 9 | "" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "# Python Dictionary `clear()`\n", 17 | "\n", 18 | "The **`clear()`** method removes all items from the dictionary.\n", 19 | "\n", 20 | "**Syntax**:\n", 21 | "\n", 22 | "```python\n", 23 | "dict.clear()\n", 24 | "```" 25 | ] 26 | }, 27 | { 28 | "cell_type": "markdown", 29 | "metadata": {}, 30 | "source": [ 31 | "## `clear()` Parameters\n", 32 | "\n", 33 | "The **`clear()`** method doesn't take any parameters." 34 | ] 35 | }, 36 | { 37 | "cell_type": "markdown", 38 | "metadata": {}, 39 | "source": [ 40 | "## Return Value from `clear()`\n", 41 | "\n", 42 | "The **`clear()`** method doesn't return any value (returns **`None`**)." 43 | ] 44 | }, 45 | { 46 | "cell_type": "code", 47 | "execution_count": 1, 48 | "metadata": { 49 | "ExecuteTime": { 50 | "end_time": "2021-06-09T18:09:38.615061Z", 51 | "start_time": "2021-06-09T18:09:38.599481Z" 52 | } 53 | }, 54 | "outputs": [ 55 | { 56 | "name": "stdout", 57 | "output_type": "stream", 58 | "text": [ 59 | "d = {}\n" 60 | ] 61 | } 62 | ], 63 | "source": [ 64 | "# Example 1: How clear() method works for dictionaries?\n", 65 | "\n", 66 | "d = {1: \"one\", 2: \"two\"}\n", 67 | "\n", 68 | "d.clear()\n", 69 | "print('d =', d)" 70 | ] 71 | }, 72 | { 73 | "cell_type": "code", 74 | "execution_count": null, 75 | "metadata": {}, 76 | "outputs": [], 77 | "source": [] 78 | } 79 | ], 80 | "metadata": { 81 | "hide_input": false, 82 | "kernelspec": { 83 | "display_name": "Python 3", 84 | "language": "python", 85 | "name": "python3" 86 | }, 87 | "language_info": { 88 | "codemirror_mode": { 89 | "name": "ipython", 90 | "version": 3 91 | }, 92 | "file_extension": ".py", 93 | "mimetype": "text/x-python", 94 | "name": "python", 95 | "nbconvert_exporter": "python", 96 | "pygments_lexer": "ipython3", 97 | "version": "3.8.8" 98 | }, 99 | "toc": { 100 | "base_numbering": 1, 101 | "nav_menu": {}, 102 | "number_sections": true, 103 | "sideBar": true, 104 | "skip_h1_title": false, 105 | "title_cell": "Table of Contents", 106 | "title_sidebar": "Contents", 107 | "toc_cell": false, 108 | "toc_position": {}, 109 | "toc_section_display": true, 110 | "toc_window_display": false 111 | }, 112 | "varInspector": { 113 | "cols": { 114 | "lenName": 16, 115 | "lenType": 16, 116 | "lenVar": 40 117 | }, 118 | "kernels_config": { 119 | "python": { 120 | "delete_cmd_postfix": "", 121 | "delete_cmd_prefix": "del ", 122 | "library": "var_list.py", 123 | "varRefreshCmd": "print(var_dic_list())" 124 | }, 125 | "r": { 126 | "delete_cmd_postfix": ") ", 127 | "delete_cmd_prefix": "rm(", 128 | "library": "var_list.r", 129 | "varRefreshCmd": "cat(var_dic_list()) " 130 | } 131 | }, 132 | "types_to_exclude": [ 133 | "module", 134 | "function", 135 | "builtin_function_or_method", 136 | "instance", 137 | "_Feature" 138 | ], 139 | "window_display": false 140 | } 141 | }, 142 | "nbformat": 4, 143 | "nbformat_minor": 2 144 | } 145 | -------------------------------------------------------------------------------- /countries_data.py: -------------------------------------------------------------------------------- 1 | countries = [ 2 | 'Afghanistan', 3 | 'Albania', 4 | 'Algeria', 5 | 'Andorra', 6 | 'Angola', 7 | 'Antigua and Barbuda', 8 | 'Argentina', 9 | 'Armenia', 10 | 'Australia', 11 | 'Austria', 12 | 'Azerbaijan', 13 | 'Bahamas', 14 | 'Bahrain', 15 | 'Bangladesh', 16 | 'Barbados', 17 | 'Belarus', 18 | 'Belgium', 19 | 'Belize', 20 | 'Benin', 21 | 'Bhutan', 22 | 'Bolivia', 23 | 'Bosnia and Herzegovina', 24 | 'Botswana', 25 | 'Brazil', 26 | 'Brunei', 27 | 'Bulgaria', 28 | 'Burkina Faso', 29 | 'Burundi', 30 | 'Cambodia', 31 | 'Cameroon', 32 | 'Canada', 33 | 'Cape Verde', 34 | 'Central African Republic', 35 | 'Chad', 36 | 'Chile', 37 | 'China', 38 | 'Colombi', 39 | 'Comoros', 40 | 'Congo (Brazzaville)', 41 | 'Congo', 42 | 'Costa Rica', 43 | "Cote d'Ivoire", 44 | 'Croatia', 45 | 'Cuba', 46 | 'Cyprus', 47 | 'Czech Republic', 48 | 'Denmark', 49 | 'Djibouti', 50 | 'Dominica', 51 | 'Dominican Republic', 52 | 'East Timor (Timor Timur)', 53 | 'Ecuador', 54 | 'Egypt', 55 | 'El Salvador', 56 | 'Equatorial Guinea', 57 | 'Eritrea', 58 | 'Estonia', 59 | 'Ethiopia', 60 | 'Fiji', 61 | 'Finland', 62 | 'France', 63 | 'Gabon', 64 | 'Gambia, The', 65 | 'Georgia', 66 | 'Germany', 67 | 'Ghana', 68 | 'Greece', 69 | 'Grenada', 70 | 'Guatemala', 71 | 'Guinea', 72 | 'Guinea-Bissau', 73 | 'Guyana', 74 | 'Haiti', 75 | 'Honduras', 76 | 'Hungary', 77 | 'Iceland', 78 | 'India', 79 | 'Indonesia', 80 | 'Iran', 81 | 'Iraq', 82 | 'Ireland', 83 | 'Israel', 84 | 'Italy', 85 | 'Jamaica', 86 | 'Japan', 87 | 'Jordan', 88 | 'Kazakhstan', 89 | 'Kenya', 90 | 'Kiribati', 91 | 'Korea, North', 92 | 'Korea, South', 93 | 'Kuwait', 94 | 'Kyrgyzstan', 95 | 'Laos', 96 | 'Latvia', 97 | 'Lebanon', 98 | 'Lesotho', 99 | 'Liberia', 100 | 'Libya', 101 | 'Liechtenstein', 102 | 'Lithuania', 103 | 'Luxembourg', 104 | 'Macedonia', 105 | 'Madagascar', 106 | 'Malawi', 107 | 'Malaysia', 108 | 'Maldives', 109 | 'Mali', 110 | 'Malta', 111 | 'Marshall Islands', 112 | 'Mauritania', 113 | 'Mauritius', 114 | 'Mexico', 115 | 'Micronesia', 116 | 'Moldova', 117 | 'Monaco', 118 | 'Mongolia', 119 | 'Morocco', 120 | 'Mozambique', 121 | 'Myanmar', 122 | 'Namibia', 123 | 'Nauru', 124 | 'Nepal', 125 | 'Netherlands', 126 | 'New Zealand', 127 | 'Nicaragua', 128 | 'Niger', 129 | 'Nigeria', 130 | 'Norway', 131 | 'Oman', 132 | 'Pakistan', 133 | 'Palau', 134 | 'Panama', 135 | 'Papua New Guinea', 136 | 'Paraguay', 137 | 'Peru', 138 | 'Philippines', 139 | 'Poland', 140 | 'Portugal', 141 | 'Qatar', 142 | 'Romania', 143 | 'Russia', 144 | 'Rwanda', 145 | 'Saint Kitts and Nevis', 146 | 'Saint Lucia', 147 | 'Saint Vincent', 148 | 'Samoa', 149 | 'San Marino', 150 | 'Sao Tome and Principe', 151 | 'Saudi Arabia', 152 | 'Senegal', 153 | 'Serbia and Montenegro', 154 | 'Seychelles', 155 | 'Sierra Leone', 156 | 'Singapore', 157 | 'Slovakia', 158 | 'Slovenia', 159 | 'Solomon Islands', 160 | 'Somalia', 161 | 'South Africa', 162 | 'Spain', 163 | 'Sri Lanka', 164 | 'Sudan', 165 | 'Suriname', 166 | 'Swaziland', 167 | 'Sweden', 168 | 'Switzerland', 169 | 'Syria', 170 | 'Taiwan', 171 | 'Tajikistan', 172 | 'Tanzania', 173 | 'Thailand', 174 | 'Togo', 175 | 'Tonga', 176 | 'Trinidad and Tobago', 177 | 'Tunisia', 178 | 'Turkey', 179 | 'Turkmenistan', 180 | 'Tuvalu', 181 | 'Uganda', 182 | 'Ukraine', 183 | 'United Arab Emirates', 184 | 'United Kingdom', 185 | 'United States', 186 | 'Uruguay', 187 | 'Uzbekistan', 188 | 'Vanuatu', 189 | 'Vatican City', 190 | 'Venezuela', 191 | 'Vietnam', 192 | 'Yemen', 193 | 'Zambia', 194 | 'Zimbabwe', 195 | ] -------------------------------------------------------------------------------- /002_Python_String_Methods/031_Python_String_partition().ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\n", 8 | "All the IPython Notebooks in this lecture series by Dr. Milan Parmar are available @ **[GitHub](https://github.com/milaan9/02_Python_Datatypes/tree/main/002_Python_String_Methods)**\n", 9 | "" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "# Python String `partition()`\n", 17 | "\n", 18 | "The string **`partition()`** method splits the string at the first occurrence of the argument string and returns a tuple containing the part the before separator, argument string and the part after the separator.\n", 19 | "\n", 20 | "**Syntax**:\n", 21 | "\n", 22 | "```python\n", 23 | "string.partition(separator)\n", 24 | "```" 25 | ] 26 | }, 27 | { 28 | "cell_type": "markdown", 29 | "metadata": { 30 | "heading_collapsed": true 31 | }, 32 | "source": [ 33 | "## `partition()` Parameters\n", 34 | "\n", 35 | "The **`partition()`** method takes a string parameter **`separator`** that separates the string at the first occurrence of it." 36 | ] 37 | }, 38 | { 39 | "cell_type": "markdown", 40 | "metadata": {}, 41 | "source": [ 42 | "## Return Value from `partition()`\n", 43 | "\n", 44 | "The **`partition()`** method returns a 3-tuple containing:\n", 45 | "\n", 46 | "* the part before the separator, separator parameter, and the part after the separator if the separator parameter is found in the string.\n", 47 | "* the string itself and two empty strings if the separator parameter is not found." 48 | ] 49 | }, 50 | { 51 | "cell_type": "code", 52 | "execution_count": 1, 53 | "metadata": { 54 | "ExecuteTime": { 55 | "end_time": "2021-06-10T18:13:38.815889Z", 56 | "start_time": "2021-06-10T18:13:38.797388Z" 57 | }, 58 | "scrolled": true 59 | }, 60 | "outputs": [ 61 | { 62 | "name": "stdout", 63 | "output_type": "stream", 64 | "text": [ 65 | "('Python ', 'is ', 'fun')\n", 66 | "('Python is fun', '', '')\n", 67 | "('Python ', 'is', \" fun, isn't it\")\n" 68 | ] 69 | } 70 | ], 71 | "source": [ 72 | "# Example 1: How partition() works?\n", 73 | "\n", 74 | "string = \"Python is fun\"\n", 75 | "\n", 76 | "# 'is' separator is found\n", 77 | "print(string.partition('is '))\n", 78 | "\n", 79 | "# 'not' separator is not found\n", 80 | "print(string.partition('not '))\n", 81 | "\n", 82 | "string = \"Python is fun, isn't it\"\n", 83 | "\n", 84 | "# splits at first occurence of 'is'\n", 85 | "print(string.partition('is'))" 86 | ] 87 | }, 88 | { 89 | "cell_type": "code", 90 | "execution_count": null, 91 | "metadata": {}, 92 | "outputs": [], 93 | "source": [] 94 | } 95 | ], 96 | "metadata": { 97 | "hide_input": false, 98 | "kernelspec": { 99 | "display_name": "Python 3", 100 | "language": "python", 101 | "name": "python3" 102 | }, 103 | "language_info": { 104 | "codemirror_mode": { 105 | "name": "ipython", 106 | "version": 3 107 | }, 108 | "file_extension": ".py", 109 | "mimetype": "text/x-python", 110 | "name": "python", 111 | "nbconvert_exporter": "python", 112 | "pygments_lexer": "ipython3", 113 | "version": "3.8.8" 114 | }, 115 | "toc": { 116 | "base_numbering": 1, 117 | "nav_menu": {}, 118 | "number_sections": true, 119 | "sideBar": true, 120 | "skip_h1_title": false, 121 | "title_cell": "Table of Contents", 122 | "title_sidebar": "Contents", 123 | "toc_cell": false, 124 | "toc_position": {}, 125 | "toc_section_display": true, 126 | "toc_window_display": false 127 | }, 128 | "varInspector": { 129 | "cols": { 130 | "lenName": 16, 131 | "lenType": 16, 132 | "lenVar": 40 133 | }, 134 | "kernels_config": { 135 | "python": { 136 | "delete_cmd_postfix": "", 137 | "delete_cmd_prefix": "del ", 138 | "library": "var_list.py", 139 | "varRefreshCmd": "print(var_dic_list())" 140 | }, 141 | "r": { 142 | "delete_cmd_postfix": ") ", 143 | "delete_cmd_prefix": "rm(", 144 | "library": "var_list.r", 145 | "varRefreshCmd": "cat(var_dic_list()) " 146 | } 147 | }, 148 | "types_to_exclude": [ 149 | "module", 150 | "function", 151 | "builtin_function_or_method", 152 | "instance", 153 | "_Feature" 154 | ], 155 | "window_display": false 156 | } 157 | }, 158 | "nbformat": 4, 159 | "nbformat_minor": 2 160 | } 161 | -------------------------------------------------------------------------------- /002_Python_String_Methods/033_Python_String_rpartition().ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\n", 8 | "All the IPython Notebooks in this lecture series by Dr. Milan Parmar are available @ **[GitHub](https://github.com/milaan9/02_Python_Datatypes/tree/main/002_Python_String_Methods)**\n", 9 | "" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "# Python String `rpartition()`\n", 17 | "\n", 18 | "The string **`rpartition()`** method splits the string at the last occurrence of the argument string and returns a tuple containing the part the before separator, argument string and the part after the separator.\n", 19 | "\n", 20 | "**Syntax**:\n", 21 | "\n", 22 | "```python\n", 23 | "string.rpartition(separator)\n", 24 | "```" 25 | ] 26 | }, 27 | { 28 | "cell_type": "markdown", 29 | "metadata": { 30 | "heading_collapsed": true 31 | }, 32 | "source": [ 33 | "## `rpartition()` Parameters\n", 34 | "\n", 35 | "The **`rpartition()`** method takes a string parameter **`separator`** that separates the string at the last occurrence of it." 36 | ] 37 | }, 38 | { 39 | "cell_type": "markdown", 40 | "metadata": {}, 41 | "source": [ 42 | "## Return Value from `rpartition()`\n", 43 | "\n", 44 | "The **`rpartition()`** method returns a 3-tuple containing:\n", 45 | "\n", 46 | "* the part before the separator, separator parameter, and the part after the separator if the separator parameter is found in the string\n", 47 | "* two empty strings, followed by the string itself if the separator parameter is not found" 48 | ] 49 | }, 50 | { 51 | "cell_type": "code", 52 | "execution_count": 1, 53 | "metadata": { 54 | "ExecuteTime": { 55 | "end_time": "2021-06-10T18:14:11.035361Z", 56 | "start_time": "2021-06-10T18:14:11.027571Z" 57 | }, 58 | "scrolled": true 59 | }, 60 | "outputs": [ 61 | { 62 | "name": "stdout", 63 | "output_type": "stream", 64 | "text": [ 65 | "('Python ', 'is ', 'fun')\n", 66 | "('', '', 'Python is fun')\n", 67 | "('Python is fun, ', 'is', \"n't it\")\n" 68 | ] 69 | } 70 | ], 71 | "source": [ 72 | "# Example 1: How rpartition() works?\n", 73 | "\n", 74 | "string = \"Python is fun\"\n", 75 | "\n", 76 | "# 'is' separator is found\n", 77 | "print(string.rpartition('is '))\n", 78 | "\n", 79 | "# 'not' separator is not found\n", 80 | "print(string.rpartition('not '))\n", 81 | "\n", 82 | "string = \"Python is fun, isn't it\"\n", 83 | "\n", 84 | "# splits at last occurence of 'is'\n", 85 | "print(string.rpartition('is'))" 86 | ] 87 | }, 88 | { 89 | "cell_type": "code", 90 | "execution_count": null, 91 | "metadata": {}, 92 | "outputs": [], 93 | "source": [] 94 | } 95 | ], 96 | "metadata": { 97 | "hide_input": false, 98 | "kernelspec": { 99 | "display_name": "Python 3", 100 | "language": "python", 101 | "name": "python3" 102 | }, 103 | "language_info": { 104 | "codemirror_mode": { 105 | "name": "ipython", 106 | "version": 3 107 | }, 108 | "file_extension": ".py", 109 | "mimetype": "text/x-python", 110 | "name": "python", 111 | "nbconvert_exporter": "python", 112 | "pygments_lexer": "ipython3", 113 | "version": "3.8.8" 114 | }, 115 | "toc": { 116 | "base_numbering": 1, 117 | "nav_menu": {}, 118 | "number_sections": true, 119 | "sideBar": true, 120 | "skip_h1_title": false, 121 | "title_cell": "Table of Contents", 122 | "title_sidebar": "Contents", 123 | "toc_cell": false, 124 | "toc_position": {}, 125 | "toc_section_display": true, 126 | "toc_window_display": false 127 | }, 128 | "varInspector": { 129 | "cols": { 130 | "lenName": 16, 131 | "lenType": 16, 132 | "lenVar": 40 133 | }, 134 | "kernels_config": { 135 | "python": { 136 | "delete_cmd_postfix": "", 137 | "delete_cmd_prefix": "del ", 138 | "library": "var_list.py", 139 | "varRefreshCmd": "print(var_dic_list())" 140 | }, 141 | "r": { 142 | "delete_cmd_postfix": ") ", 143 | "delete_cmd_prefix": "rm(", 144 | "library": "var_list.r", 145 | "varRefreshCmd": "cat(var_dic_list()) " 146 | } 147 | }, 148 | "types_to_exclude": [ 149 | "module", 150 | "function", 151 | "builtin_function_or_method", 152 | "instance", 153 | "_Feature" 154 | ], 155 | "window_display": false 156 | } 157 | }, 158 | "nbformat": 4, 159 | "nbformat_minor": 2 160 | } 161 | -------------------------------------------------------------------------------- /006_Python_Sets_Methods/012_Python_Set_issuperset().ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\n", 8 | "All the IPython Notebooks in this lecture series by Dr. Milan Parmar are available @ **[GitHub](https://github.com/milaan9/02_Python_Datatypes/tree/main/006_Python_Sets_Methods)**\n", 9 | "" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "# Python Set `issuperset()`\n", 17 | "\n", 18 | "The **`issuperset()`** method returns **`True`** if a set has every elements of another set (passed as an argument). If not, it returns **`False`**.\n", 19 | "\n", 20 | "Set **`A`** is said to be the subset of set **`B`** if all elements of **`A`** are in **`B`**.\n", 21 | "\n", 22 | "
\n", 23 | "\n", 24 | "
\n", 25 | "\n", 26 | "Here, set **`B`** is a superset of set **`A`** and **`A`** is a subset of set **`B`**." 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "metadata": {}, 32 | "source": [ 33 | "**Syntax**:\n", 34 | "\n", 35 | "```python\n", 36 | "A.issuperset(B)\n", 37 | "```\n", 38 | "The above code checks if **`A`** is a superset of **`B`**." 39 | ] 40 | }, 41 | { 42 | "cell_type": "markdown", 43 | "metadata": {}, 44 | "source": [ 45 | "## Return Value from `issuperset()`\n", 46 | "\n", 47 | "The **`issuperset()`** returns\n", 48 | "\n", 49 | "* **`True`** if **`A`** is a superset of **`B`**\n", 50 | "* **`False`** if **`A`** is not a superset of **`B`**" 51 | ] 52 | }, 53 | { 54 | "cell_type": "code", 55 | "execution_count": 1, 56 | "metadata": { 57 | "ExecuteTime": { 58 | "end_time": "2021-06-10T17:44:59.487523Z", 59 | "start_time": "2021-06-10T17:44:59.473889Z" 60 | } 61 | }, 62 | "outputs": [ 63 | { 64 | "name": "stdout", 65 | "output_type": "stream", 66 | "text": [ 67 | "True\n", 68 | "False\n", 69 | "True\n" 70 | ] 71 | } 72 | ], 73 | "source": [ 74 | "# Example: How issuperset() works?\n", 75 | "\n", 76 | "A = {1, 2, 3, 4, 5}\n", 77 | "B = {1, 2, 3}\n", 78 | "C = {1, 2, 3}\n", 79 | "\n", 80 | "# Returns True\n", 81 | "print(A.issuperset(B))\n", 82 | "\n", 83 | "# Returns False\n", 84 | "print(B.issuperset(A))\n", 85 | "\n", 86 | "# Returns True\n", 87 | "print(C.issuperset(B))" 88 | ] 89 | }, 90 | { 91 | "cell_type": "markdown", 92 | "metadata": {}, 93 | "source": [ 94 | "If you need to check if a set is a superset of another set, you can use **[issubset() in Python](http://localhost:8888/notebooks/01_Learn_Python4Data/02_Python_Datatypes/006_Python_Sets_Methods/011_Python_Set_issubset%28%29.ipynb)**." 95 | ] 96 | }, 97 | { 98 | "cell_type": "code", 99 | "execution_count": null, 100 | "metadata": {}, 101 | "outputs": [], 102 | "source": [] 103 | } 104 | ], 105 | "metadata": { 106 | "hide_input": false, 107 | "kernelspec": { 108 | "display_name": "Python 3", 109 | "language": "python", 110 | "name": "python3" 111 | }, 112 | "language_info": { 113 | "codemirror_mode": { 114 | "name": "ipython", 115 | "version": 3 116 | }, 117 | "file_extension": ".py", 118 | "mimetype": "text/x-python", 119 | "name": "python", 120 | "nbconvert_exporter": "python", 121 | "pygments_lexer": "ipython3", 122 | "version": "3.8.8" 123 | }, 124 | "toc": { 125 | "base_numbering": 1, 126 | "nav_menu": {}, 127 | "number_sections": true, 128 | "sideBar": true, 129 | "skip_h1_title": false, 130 | "title_cell": "Table of Contents", 131 | "title_sidebar": "Contents", 132 | "toc_cell": false, 133 | "toc_position": {}, 134 | "toc_section_display": true, 135 | "toc_window_display": false 136 | }, 137 | "varInspector": { 138 | "cols": { 139 | "lenName": 16, 140 | "lenType": 16, 141 | "lenVar": 40 142 | }, 143 | "kernels_config": { 144 | "python": { 145 | "delete_cmd_postfix": "", 146 | "delete_cmd_prefix": "del ", 147 | "library": "var_list.py", 148 | "varRefreshCmd": "print(var_dic_list())" 149 | }, 150 | "r": { 151 | "delete_cmd_postfix": ") ", 152 | "delete_cmd_prefix": "rm(", 153 | "library": "var_list.r", 154 | "varRefreshCmd": "cat(var_dic_list()) " 155 | } 156 | }, 157 | "types_to_exclude": [ 158 | "module", 159 | "function", 160 | "builtin_function_or_method", 161 | "instance", 162 | "_Feature" 163 | ], 164 | "window_display": false 165 | } 166 | }, 167 | "nbformat": 4, 168 | "nbformat_minor": 2 169 | } 170 | -------------------------------------------------------------------------------- /006_Python_Sets_Methods/006_Python_Set_difference_update().ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\n", 8 | "All the IPython Notebooks in this lecture series by Dr. Milan Parmar are available @ **[GitHub](https://github.com/milaan9/02_Python_Datatypes/tree/main/006_Python_Sets_Methods)**\n", 9 | "" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "# Python Set `difference_update()`\n", 17 | "\n", 18 | "The **`difference_update()`** updates the set calling difference_update() method with the difference of sets." 19 | ] 20 | }, 21 | { 22 | "cell_type": "markdown", 23 | "metadata": {}, 24 | "source": [ 25 | "If **`A`** and **`B`** are two sets. The set difference of **`A`** and **`B`** is a set of elements that exists only in set **`A`** but not in **`B`**.\n", 26 | "\n", 27 | "To learn more, visit **[Python set difference()](https://github.com/milaan9/02_Python_Datatypes/blob/main/006_Python_Sets_Methods/005_Python_Set_difference%28%29.ipynb)**." 28 | ] 29 | }, 30 | { 31 | "cell_type": "markdown", 32 | "metadata": {}, 33 | "source": [ 34 | "**Syntax**:\n", 35 | "\n", 36 | "```python\n", 37 | "A.difference_update(B)\n", 38 | "```\n", 39 | "\n", 40 | "Here, **`A`** and **`B`** are two sets. **`difference_update()`** updates set **`A`** with the set difference of **`A-B`**." 41 | ] 42 | }, 43 | { 44 | "cell_type": "markdown", 45 | "metadata": {}, 46 | "source": [ 47 | "## Return Value from `difference_update()`\n", 48 | "\n", 49 | "The **`difference_update()`** returns **`None`** indicating the object (set) is mutated.\n", 50 | "\n", 51 | "Suppose,\n", 52 | "```python\n", 53 | "result = A.difference_update(B)\n", 54 | "```\n", 55 | "\n", 56 | "When you run the code,\n", 57 | "\n", 58 | "* **`result`** will be **`None`**\n", 59 | "* **`A`** will be equal to **`A-B`**\n", 60 | "* **`B`** will be unchanged" 61 | ] 62 | }, 63 | { 64 | "cell_type": "code", 65 | "execution_count": 1, 66 | "metadata": { 67 | "ExecuteTime": { 68 | "end_time": "2021-06-10T17:21:28.054231Z", 69 | "start_time": "2021-06-10T17:21:28.033780Z" 70 | } 71 | }, 72 | "outputs": [ 73 | { 74 | "name": "stdout", 75 | "output_type": "stream", 76 | "text": [ 77 | "A = {'a', 'd'}\n", 78 | "B = {'c', 'g', 'f'}\n", 79 | "result = None\n" 80 | ] 81 | } 82 | ], 83 | "source": [ 84 | "# Example: How difference_update() works?\n", 85 | "\n", 86 | "A = {'a', 'c', 'g', 'd'}\n", 87 | "B = {'c', 'f', 'g'}\n", 88 | "\n", 89 | "result = A.difference_update(B)\n", 90 | "\n", 91 | "print('A = ', A)\n", 92 | "print('B = ', B)\n", 93 | "print('result = ', result)" 94 | ] 95 | }, 96 | { 97 | "cell_type": "code", 98 | "execution_count": null, 99 | "metadata": {}, 100 | "outputs": [], 101 | "source": [] 102 | } 103 | ], 104 | "metadata": { 105 | "hide_input": false, 106 | "kernelspec": { 107 | "display_name": "Python 3", 108 | "language": "python", 109 | "name": "python3" 110 | }, 111 | "language_info": { 112 | "codemirror_mode": { 113 | "name": "ipython", 114 | "version": 3 115 | }, 116 | "file_extension": ".py", 117 | "mimetype": "text/x-python", 118 | "name": "python", 119 | "nbconvert_exporter": "python", 120 | "pygments_lexer": "ipython3", 121 | "version": "3.8.8" 122 | }, 123 | "toc": { 124 | "base_numbering": 1, 125 | "nav_menu": {}, 126 | "number_sections": true, 127 | "sideBar": true, 128 | "skip_h1_title": false, 129 | "title_cell": "Table of Contents", 130 | "title_sidebar": "Contents", 131 | "toc_cell": false, 132 | "toc_position": {}, 133 | "toc_section_display": true, 134 | "toc_window_display": false 135 | }, 136 | "varInspector": { 137 | "cols": { 138 | "lenName": 16, 139 | "lenType": 16, 140 | "lenVar": 40 141 | }, 142 | "kernels_config": { 143 | "python": { 144 | "delete_cmd_postfix": "", 145 | "delete_cmd_prefix": "del ", 146 | "library": "var_list.py", 147 | "varRefreshCmd": "print(var_dic_list())" 148 | }, 149 | "r": { 150 | "delete_cmd_postfix": ") ", 151 | "delete_cmd_prefix": "rm(", 152 | "library": "var_list.r", 153 | "varRefreshCmd": "cat(var_dic_list()) " 154 | } 155 | }, 156 | "types_to_exclude": [ 157 | "module", 158 | "function", 159 | "builtin_function_or_method", 160 | "instance", 161 | "_Feature" 162 | ], 163 | "window_display": false 164 | } 165 | }, 166 | "nbformat": 4, 167 | "nbformat_minor": 2 168 | } 169 | -------------------------------------------------------------------------------- /006_Python_Sets_Methods/015_Python_Set_symmetric_difference_update().ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\n", 8 | "All the IPython Notebooks in this lecture series by Dr. Milan Parmar are available @ **[GitHub](https://github.com/milaan9/02_Python_Datatypes/tree/main/006_Python_Sets_Methods)**\n", 9 | "" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "# Python Set `symmetric_difference_update()`\n", 17 | "\n", 18 | "The **`symmetric_difference_update()`** method finds the symmetric difference of two sets and updates the set calling it.\n", 19 | "\n", 20 | "The symmetric difference of two sets **`A`** and **`B`** is the set of elements that are in either **`A`** or **`B`**, but not in their intersection.\n", 21 | "\n", 22 | "
\n", 23 | "\n", 24 | "
" 25 | ] 26 | }, 27 | { 28 | "cell_type": "markdown", 29 | "metadata": {}, 30 | "source": [ 31 | "**Syntax**:\n", 32 | "\n", 33 | "```python\n", 34 | "A.symmetric_difference_update(B)\n", 35 | "```" 36 | ] 37 | }, 38 | { 39 | "cell_type": "markdown", 40 | "metadata": {}, 41 | "source": [ 42 | "## Return Value from `symmetric_difference_update()`\n", 43 | "\n", 44 | "The **`symmetric_difference_update()`** returns None (returns nothing). Rather, it updates the set calling it." 45 | ] 46 | }, 47 | { 48 | "cell_type": "code", 49 | "execution_count": 1, 50 | "metadata": { 51 | "ExecuteTime": { 52 | "end_time": "2021-06-10T17:45:52.872978Z", 53 | "start_time": "2021-06-10T17:45:52.861775Z" 54 | }, 55 | "scrolled": true 56 | }, 57 | "outputs": [ 58 | { 59 | "name": "stdout", 60 | "output_type": "stream", 61 | "text": [ 62 | "A = {'a', 'e'}\n", 63 | "B = {'d', 'e', 'c'}\n", 64 | "result = None\n" 65 | ] 66 | } 67 | ], 68 | "source": [ 69 | "# Example: Working of symmetric_difference_update()\n", 70 | "\n", 71 | "A = {'a', 'c', 'd'}\n", 72 | "B = {'c', 'd', 'e' }\n", 73 | "\n", 74 | "result = A.symmetric_difference_update(B)\n", 75 | "\n", 76 | "print('A =', A)\n", 77 | "print('B =', B)\n", 78 | "print('result =', result)" 79 | ] 80 | }, 81 | { 82 | "cell_type": "markdown", 83 | "metadata": {}, 84 | "source": [ 85 | "Here, the set **`A`** is updated with the symmetric difference of set **`A`** and **`B`**. However, the set **`B`** is unchanged." 86 | ] 87 | }, 88 | { 89 | "cell_type": "markdown", 90 | "metadata": {}, 91 | "source": [ 92 | "**Recommended Reading:** **[Python Set symmetric_difference()](https://github.com/milaan9/02_Python_Datatypes/blob/main/006_Python_Sets_Methods/014_Python_Set_symmetric_difference%28%29.ipynb)**" 93 | ] 94 | }, 95 | { 96 | "cell_type": "code", 97 | "execution_count": null, 98 | "metadata": {}, 99 | "outputs": [], 100 | "source": [] 101 | } 102 | ], 103 | "metadata": { 104 | "hide_input": false, 105 | "kernelspec": { 106 | "display_name": "Python 3", 107 | "language": "python", 108 | "name": "python3" 109 | }, 110 | "language_info": { 111 | "codemirror_mode": { 112 | "name": "ipython", 113 | "version": 3 114 | }, 115 | "file_extension": ".py", 116 | "mimetype": "text/x-python", 117 | "name": "python", 118 | "nbconvert_exporter": "python", 119 | "pygments_lexer": "ipython3", 120 | "version": "3.8.8" 121 | }, 122 | "toc": { 123 | "base_numbering": 1, 124 | "nav_menu": {}, 125 | "number_sections": true, 126 | "sideBar": true, 127 | "skip_h1_title": false, 128 | "title_cell": "Table of Contents", 129 | "title_sidebar": "Contents", 130 | "toc_cell": false, 131 | "toc_position": {}, 132 | "toc_section_display": true, 133 | "toc_window_display": false 134 | }, 135 | "varInspector": { 136 | "cols": { 137 | "lenName": 16, 138 | "lenType": 16, 139 | "lenVar": 40 140 | }, 141 | "kernels_config": { 142 | "python": { 143 | "delete_cmd_postfix": "", 144 | "delete_cmd_prefix": "del ", 145 | "library": "var_list.py", 146 | "varRefreshCmd": "print(var_dic_list())" 147 | }, 148 | "r": { 149 | "delete_cmd_postfix": ") ", 150 | "delete_cmd_prefix": "rm(", 151 | "library": "var_list.r", 152 | "varRefreshCmd": "cat(var_dic_list()) " 153 | } 154 | }, 155 | "types_to_exclude": [ 156 | "module", 157 | "function", 158 | "builtin_function_or_method", 159 | "instance", 160 | "_Feature" 161 | ], 162 | "window_display": false 163 | } 164 | }, 165 | "nbformat": 4, 166 | "nbformat_minor": 2 167 | } 168 | -------------------------------------------------------------------------------- /006_Python_Sets_Methods/011_Python_Set_issubset().ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\n", 8 | "All the IPython Notebooks in this lecture series by Dr. Milan Parmar are available @ **[GitHub](https://github.com/milaan9/02_Python_Datatypes/tree/main/006_Python_Sets_Methods)**\n", 9 | "" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "# Python Set `issubset()`\n", 17 | "\n", 18 | "The **`issubset()`** method returns **`True`** if all elements of a set are present in another set (passed as an argument). If not, it returns **`False`**.\n", 19 | "\n", 20 | "Set **`A`** is said to be the subset of set **`B`** if all elements of **`A`** are in **`B`**.\n", 21 | "\n", 22 | "
\n", 23 | "\n", 24 | "
\n", 25 | "\n", 26 | "Here, set **`A`** is a subset of **`B`**." 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "metadata": {}, 32 | "source": [ 33 | "**Syntax**:\n", 34 | "\n", 35 | "```python\n", 36 | "A.issubset(B)\n", 37 | "```\n", 38 | "The above code checks if **`A`** is a subset of **`B`**." 39 | ] 40 | }, 41 | { 42 | "cell_type": "markdown", 43 | "metadata": {}, 44 | "source": [ 45 | "## Return Value from `issubset()`\n", 46 | "\n", 47 | "The **`issubset()`** returns\n", 48 | "\n", 49 | "* **`True`** if **`A`** is a subset of **`B`**\n", 50 | "* **`False`** if **`A`** is not a subset of **`B`**" 51 | ] 52 | }, 53 | { 54 | "cell_type": "code", 55 | "execution_count": 1, 56 | "metadata": { 57 | "ExecuteTime": { 58 | "end_time": "2021-06-10T17:44:47.102443Z", 59 | "start_time": "2021-06-10T17:44:47.079071Z" 60 | } 61 | }, 62 | "outputs": [ 63 | { 64 | "name": "stdout", 65 | "output_type": "stream", 66 | "text": [ 67 | "True\n", 68 | "False\n", 69 | "False\n", 70 | "True\n" 71 | ] 72 | } 73 | ], 74 | "source": [ 75 | "# Example: How issubset() works?\n", 76 | "\n", 77 | "A = {1, 2, 3}\n", 78 | "B = {1, 2, 3, 4, 5}\n", 79 | "C = {1, 2, 4, 5}\n", 80 | "\n", 81 | "# Returns True\n", 82 | "print(A.issubset(B))\n", 83 | "\n", 84 | "# Returns False\n", 85 | "# B is not subset of A\n", 86 | "print(B.issubset(A))\n", 87 | "\n", 88 | "# Returns False\n", 89 | "print(A.issubset(C))\n", 90 | "\n", 91 | "# Returns True\n", 92 | "print(C.issubset(B))" 93 | ] 94 | }, 95 | { 96 | "cell_type": "markdown", 97 | "metadata": {}, 98 | "source": [ 99 | "If you need to check if a set is a superset of another set, you can use **[issuperset() in Python](https://github.com/milaan9/02_Python_Datatypes/blob/main/006_Python_Sets_Methods/012_Python_Set_issuperset%28%29.ipynb)**." 100 | ] 101 | }, 102 | { 103 | "cell_type": "code", 104 | "execution_count": null, 105 | "metadata": {}, 106 | "outputs": [], 107 | "source": [] 108 | } 109 | ], 110 | "metadata": { 111 | "hide_input": false, 112 | "kernelspec": { 113 | "display_name": "Python 3", 114 | "language": "python", 115 | "name": "python3" 116 | }, 117 | "language_info": { 118 | "codemirror_mode": { 119 | "name": "ipython", 120 | "version": 3 121 | }, 122 | "file_extension": ".py", 123 | "mimetype": "text/x-python", 124 | "name": "python", 125 | "nbconvert_exporter": "python", 126 | "pygments_lexer": "ipython3", 127 | "version": "3.8.8" 128 | }, 129 | "toc": { 130 | "base_numbering": 1, 131 | "nav_menu": {}, 132 | "number_sections": true, 133 | "sideBar": true, 134 | "skip_h1_title": false, 135 | "title_cell": "Table of Contents", 136 | "title_sidebar": "Contents", 137 | "toc_cell": false, 138 | "toc_position": {}, 139 | "toc_section_display": true, 140 | "toc_window_display": false 141 | }, 142 | "varInspector": { 143 | "cols": { 144 | "lenName": 16, 145 | "lenType": 16, 146 | "lenVar": 40 147 | }, 148 | "kernels_config": { 149 | "python": { 150 | "delete_cmd_postfix": "", 151 | "delete_cmd_prefix": "del ", 152 | "library": "var_list.py", 153 | "varRefreshCmd": "print(var_dic_list())" 154 | }, 155 | "r": { 156 | "delete_cmd_postfix": ") ", 157 | "delete_cmd_prefix": "rm(", 158 | "library": "var_list.r", 159 | "varRefreshCmd": "cat(var_dic_list()) " 160 | } 161 | }, 162 | "types_to_exclude": [ 163 | "module", 164 | "function", 165 | "builtin_function_or_method", 166 | "instance", 167 | "_Feature" 168 | ], 169 | "window_display": false 170 | } 171 | }, 172 | "nbformat": 4, 173 | "nbformat_minor": 2 174 | } 175 | -------------------------------------------------------------------------------- /002_Python_String_Methods/001_Python_String_capitalize().ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\n", 8 | "All the IPython Notebooks in this lecture series by Dr. Milan Parmar are available @ **[GitHub](https://github.com/milaan9/02_Python_Datatypes/tree/main/002_Python_String_Methods)**\n", 9 | "" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "# Python String `capitalize()`\n", 17 | "\n", 18 | "In Python, the **`capitalize()`** method converts first character of a string to uppercase letter and lowercases all other characters, if any.\n", 19 | "\n", 20 | "**Syntax**:\n", 21 | "\n", 22 | "```python\n", 23 | "string.capitalize()\n", 24 | "```" 25 | ] 26 | }, 27 | { 28 | "cell_type": "markdown", 29 | "metadata": {}, 30 | "source": [ 31 | "## `capitalize()` Parameters\n", 32 | "\n", 33 | "The **`capitalize()`** function doesn't take any parameter." 34 | ] 35 | }, 36 | { 37 | "cell_type": "markdown", 38 | "metadata": {}, 39 | "source": [ 40 | "## Return Value from `capitalize()`\n", 41 | "\n", 42 | "The **`capitalize()`** function returns a string with the first letter capitalized and all other characters lowercased. It doesn't modify the original string." 43 | ] 44 | }, 45 | { 46 | "cell_type": "code", 47 | "execution_count": 1, 48 | "metadata": { 49 | "ExecuteTime": { 50 | "end_time": "2021-06-10T18:03:22.140236Z", 51 | "start_time": "2021-06-10T18:03:22.118813Z" 52 | } 53 | }, 54 | "outputs": [ 55 | { 56 | "name": "stdout", 57 | "output_type": "stream", 58 | "text": [ 59 | "Old String: python is AWesome.\n", 60 | "Capitalized String: Python is awesome.\n" 61 | ] 62 | } 63 | ], 64 | "source": [ 65 | "# Example 1: Capitalize a Sentence\n", 66 | "\n", 67 | "string = \"python is AWesome.\"\n", 68 | "\n", 69 | "capitalized_string = string.capitalize()\n", 70 | "\n", 71 | "print('Old String: ', string)\n", 72 | "print('Capitalized String:', capitalized_string)" 73 | ] 74 | }, 75 | { 76 | "cell_type": "code", 77 | "execution_count": 2, 78 | "metadata": { 79 | "ExecuteTime": { 80 | "end_time": "2021-06-10T18:03:23.076080Z", 81 | "start_time": "2021-06-10T18:03:23.057092Z" 82 | } 83 | }, 84 | "outputs": [ 85 | { 86 | "name": "stdout", 87 | "output_type": "stream", 88 | "text": [ 89 | "Old String: + is an operator.\n", 90 | "New String: + is an operator.\n" 91 | ] 92 | } 93 | ], 94 | "source": [ 95 | "# Example 2: Non-alphabetic First Character\n", 96 | "\n", 97 | "string = \"+ is an operator.\"\n", 98 | "\n", 99 | "new_string = string.capitalize()\n", 100 | "\n", 101 | "print('Old String:', string)\n", 102 | "print('New String:', new_string)" 103 | ] 104 | }, 105 | { 106 | "cell_type": "code", 107 | "execution_count": null, 108 | "metadata": {}, 109 | "outputs": [], 110 | "source": [] 111 | } 112 | ], 113 | "metadata": { 114 | "hide_input": false, 115 | "kernelspec": { 116 | "display_name": "Python 3", 117 | "language": "python", 118 | "name": "python3" 119 | }, 120 | "language_info": { 121 | "codemirror_mode": { 122 | "name": "ipython", 123 | "version": 3 124 | }, 125 | "file_extension": ".py", 126 | "mimetype": "text/x-python", 127 | "name": "python", 128 | "nbconvert_exporter": "python", 129 | "pygments_lexer": "ipython3", 130 | "version": "3.8.8" 131 | }, 132 | "toc": { 133 | "base_numbering": 1, 134 | "nav_menu": {}, 135 | "number_sections": true, 136 | "sideBar": true, 137 | "skip_h1_title": false, 138 | "title_cell": "Table of Contents", 139 | "title_sidebar": "Contents", 140 | "toc_cell": false, 141 | "toc_position": {}, 142 | "toc_section_display": true, 143 | "toc_window_display": false 144 | }, 145 | "varInspector": { 146 | "cols": { 147 | "lenName": 16, 148 | "lenType": 16, 149 | "lenVar": 40 150 | }, 151 | "kernels_config": { 152 | "python": { 153 | "delete_cmd_postfix": "", 154 | "delete_cmd_prefix": "del ", 155 | "library": "var_list.py", 156 | "varRefreshCmd": "print(var_dic_list())" 157 | }, 158 | "r": { 159 | "delete_cmd_postfix": ") ", 160 | "delete_cmd_prefix": "rm(", 161 | "library": "var_list.r", 162 | "varRefreshCmd": "cat(var_dic_list()) " 163 | } 164 | }, 165 | "types_to_exclude": [ 166 | "module", 167 | "function", 168 | "builtin_function_or_method", 169 | "instance", 170 | "_Feature" 171 | ], 172 | "window_display": false 173 | } 174 | }, 175 | "nbformat": 4, 176 | "nbformat_minor": 2 177 | } 178 | -------------------------------------------------------------------------------- /002_Python_String_Methods/002_Python_String_center().ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\n", 8 | "All the IPython Notebooks in this lecture series by Dr. Milan Parmar are available @ **[GitHub](https://github.com/milaan9/02_Python_Datatypes/tree/main/002_Python_String_Methods)**\n", 9 | "" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "# Python String `center()`\n", 17 | "\n", 18 | "The **`center()`** method returns a string which is padded with the specified character.\n", 19 | "\n", 20 | "**Syntax**:\n", 21 | "\n", 22 | "```python\n", 23 | "string.center(width[, fillchar])\n", 24 | "```" 25 | ] 26 | }, 27 | { 28 | "cell_type": "markdown", 29 | "metadata": {}, 30 | "source": [ 31 | "## `center()` Parameters\n", 32 | "\n", 33 | "The **`center()`** method takes two arguments:\n", 34 | "\n", 35 | "* **width** - length of the string with padded characters\n", 36 | "* **fillchar** (optional) - padding character\n", 37 | "\n", 38 | "The **`fillchar`** argument is optional. If it's not provided, space is taken as default argument." 39 | ] 40 | }, 41 | { 42 | "cell_type": "markdown", 43 | "metadata": {}, 44 | "source": [ 45 | "## Return Value from `center()`\n", 46 | "\n", 47 | "The **`center()`** method returns a string padded with specified **`fillchar`**. It doesn't modify the original string." 48 | ] 49 | }, 50 | { 51 | "cell_type": "code", 52 | "execution_count": 1, 53 | "metadata": { 54 | "ExecuteTime": { 55 | "end_time": "2021-06-10T18:03:38.021362Z", 56 | "start_time": "2021-06-10T18:03:38.014546Z" 57 | } 58 | }, 59 | "outputs": [ 60 | { 61 | "name": "stdout", 62 | "output_type": "stream", 63 | "text": [ 64 | "Centered String: Python is awesome \n" 65 | ] 66 | } 67 | ], 68 | "source": [ 69 | "# Example 1: center() Method With Default fillchar\n", 70 | "\n", 71 | "string = \"Python is awesome\"\n", 72 | "\n", 73 | "new_string = string.center(24)\n", 74 | "\n", 75 | "print(\"Centered String: \", new_string)" 76 | ] 77 | }, 78 | { 79 | "cell_type": "code", 80 | "execution_count": 2, 81 | "metadata": { 82 | "ExecuteTime": { 83 | "end_time": "2021-06-10T18:03:39.957811Z", 84 | "start_time": "2021-06-10T18:03:39.944664Z" 85 | } 86 | }, 87 | "outputs": [ 88 | { 89 | "name": "stdout", 90 | "output_type": "stream", 91 | "text": [ 92 | "Centered String: ***Python is awesome****\n" 93 | ] 94 | } 95 | ], 96 | "source": [ 97 | "# Example 2: center() Method With * fillchar\n", 98 | "\n", 99 | "string = \"Python is awesome\"\n", 100 | "\n", 101 | "new_string = string.center(24, '*')\n", 102 | "\n", 103 | "print(\"Centered String: \", new_string)" 104 | ] 105 | }, 106 | { 107 | "cell_type": "code", 108 | "execution_count": null, 109 | "metadata": {}, 110 | "outputs": [], 111 | "source": [] 112 | } 113 | ], 114 | "metadata": { 115 | "hide_input": false, 116 | "kernelspec": { 117 | "display_name": "Python 3", 118 | "language": "python", 119 | "name": "python3" 120 | }, 121 | "language_info": { 122 | "codemirror_mode": { 123 | "name": "ipython", 124 | "version": 3 125 | }, 126 | "file_extension": ".py", 127 | "mimetype": "text/x-python", 128 | "name": "python", 129 | "nbconvert_exporter": "python", 130 | "pygments_lexer": "ipython3", 131 | "version": "3.8.8" 132 | }, 133 | "toc": { 134 | "base_numbering": 1, 135 | "nav_menu": {}, 136 | "number_sections": true, 137 | "sideBar": true, 138 | "skip_h1_title": false, 139 | "title_cell": "Table of Contents", 140 | "title_sidebar": "Contents", 141 | "toc_cell": false, 142 | "toc_position": {}, 143 | "toc_section_display": true, 144 | "toc_window_display": false 145 | }, 146 | "varInspector": { 147 | "cols": { 148 | "lenName": 16, 149 | "lenType": 16, 150 | "lenVar": 40 151 | }, 152 | "kernels_config": { 153 | "python": { 154 | "delete_cmd_postfix": "", 155 | "delete_cmd_prefix": "del ", 156 | "library": "var_list.py", 157 | "varRefreshCmd": "print(var_dic_list())" 158 | }, 159 | "r": { 160 | "delete_cmd_postfix": ") ", 161 | "delete_cmd_prefix": "rm(", 162 | "library": "var_list.r", 163 | "varRefreshCmd": "cat(var_dic_list()) " 164 | } 165 | }, 166 | "types_to_exclude": [ 167 | "module", 168 | "function", 169 | "builtin_function_or_method", 170 | "instance", 171 | "_Feature" 172 | ], 173 | "window_display": false 174 | } 175 | }, 176 | "nbformat": 4, 177 | "nbformat_minor": 2 178 | } 179 | -------------------------------------------------------------------------------- /004_Python_Tuple_Methods/001_Python_Tuple_count().ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\n", 8 | "All the IPython Notebooks in this lecture series by Dr. Milan Parmar are available @ **[GitHub](https://github.com/milaan9/02_Python_Datatypes/tree/main/004_Python_Tuple_Methods)**\n", 9 | "" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "# Python Tuple `count()`\n", 17 | "\n", 18 | "The **`count()`** method returns the number of times the specified element appears in the tuple.\n", 19 | "\n", 20 | "**Syntax**:\n", 21 | "\n", 22 | "```python\n", 23 | "tuple.count(element)\n", 24 | "```" 25 | ] 26 | }, 27 | { 28 | "cell_type": "markdown", 29 | "metadata": {}, 30 | "source": [ 31 | "## `count()` Parameters\n", 32 | "\n", 33 | "The tuple **`count()`** method takes a single argument:\n", 34 | "\n", 35 | "* **element** - the element to be counted" 36 | ] 37 | }, 38 | { 39 | "cell_type": "markdown", 40 | "metadata": {}, 41 | "source": [ 42 | "## Return Value from `count()`\n", 43 | "\n", 44 | "The **`count()`** method returns the number of times **`element`** appears in the tuple." 45 | ] 46 | }, 47 | { 48 | "cell_type": "code", 49 | "execution_count": 1, 50 | "metadata": { 51 | "ExecuteTime": { 52 | "end_time": "2021-06-09T14:25:45.608647Z", 53 | "start_time": "2021-06-09T14:25:45.595986Z" 54 | } 55 | }, 56 | "outputs": [ 57 | { 58 | "name": "stdout", 59 | "output_type": "stream", 60 | "text": [ 61 | "The count of i is: 2\n", 62 | "The count of p is: 0\n" 63 | ] 64 | } 65 | ], 66 | "source": [ 67 | "# Example 1: Use of Tuple count()\n", 68 | "\n", 69 | "# vowels tuple\n", 70 | "vowels = ('a', 'e', 'i', 'o', 'i', 'u')\n", 71 | "\n", 72 | "# count element 'i'\n", 73 | "count = vowels.count('i')\n", 74 | "\n", 75 | "# print count\n", 76 | "print('The count of i is:', count)\n", 77 | "\n", 78 | "# count element 'p'\n", 79 | "count = vowels.count('p')\n", 80 | "\n", 81 | "# print count\n", 82 | "print('The count of p is:', count)" 83 | ] 84 | }, 85 | { 86 | "cell_type": "code", 87 | "execution_count": 2, 88 | "metadata": { 89 | "ExecuteTime": { 90 | "end_time": "2021-06-09T14:25:46.903830Z", 91 | "start_time": "2021-06-09T14:25:46.891169Z" 92 | } 93 | }, 94 | "outputs": [ 95 | { 96 | "name": "stdout", 97 | "output_type": "stream", 98 | "text": [ 99 | "The count of ('a', 'b') is: 2\n", 100 | "The count of [3, 4] is: 1\n" 101 | ] 102 | } 103 | ], 104 | "source": [ 105 | "# Example 2: Count List and Tuple Elements Inside Tuple\n", 106 | "\n", 107 | "# random tuple\n", 108 | "random = ('a', ('a', 'b'), ('a', 'b'), [3, 4])\n", 109 | "\n", 110 | "# count element ('a', 'b')\n", 111 | "count = random.count(('a', 'b'))\n", 112 | "\n", 113 | "# print count\n", 114 | "print(\"The count of ('a', 'b') is:\", count)\n", 115 | "\n", 116 | "# count element [3, 4]\n", 117 | "count = random.count([3, 4])\n", 118 | "\n", 119 | "# print count\n", 120 | "print(\"The count of [3, 4] is:\", count)" 121 | ] 122 | }, 123 | { 124 | "cell_type": "code", 125 | "execution_count": null, 126 | "metadata": {}, 127 | "outputs": [], 128 | "source": [] 129 | } 130 | ], 131 | "metadata": { 132 | "hide_input": false, 133 | "kernelspec": { 134 | "display_name": "Python 3", 135 | "language": "python", 136 | "name": "python3" 137 | }, 138 | "language_info": { 139 | "codemirror_mode": { 140 | "name": "ipython", 141 | "version": 3 142 | }, 143 | "file_extension": ".py", 144 | "mimetype": "text/x-python", 145 | "name": "python", 146 | "nbconvert_exporter": "python", 147 | "pygments_lexer": "ipython3", 148 | "version": "3.8.3" 149 | }, 150 | "varInspector": { 151 | "cols": { 152 | "lenName": 16, 153 | "lenType": 16, 154 | "lenVar": 40 155 | }, 156 | "kernels_config": { 157 | "python": { 158 | "delete_cmd_postfix": "", 159 | "delete_cmd_prefix": "del ", 160 | "library": "var_list.py", 161 | "varRefreshCmd": "print(var_dic_list())" 162 | }, 163 | "r": { 164 | "delete_cmd_postfix": ") ", 165 | "delete_cmd_prefix": "rm(", 166 | "library": "var_list.r", 167 | "varRefreshCmd": "cat(var_dic_list()) " 168 | } 169 | }, 170 | "types_to_exclude": [ 171 | "module", 172 | "function", 173 | "builtin_function_or_method", 174 | "instance", 175 | "_Feature" 176 | ], 177 | "window_display": false 178 | } 179 | }, 180 | "nbformat": 4, 181 | "nbformat_minor": 2 182 | } 183 | -------------------------------------------------------------------------------- /006_Python_Sets_Methods/013_Python_Set_pop().ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\n", 8 | "All the IPython Notebooks in this lecture series by Dr. Milan Parmar are available @ **[GitHub](https://github.com/milaan9/02_Python_Datatypes/tree/main/006_Python_Sets_Methods)**\n", 9 | "" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "# Python Set `pop()`\n", 17 | "\n", 18 | "The **`pop()`** method removes an arbitrary element from the set and returns the element removed.\n", 19 | "\n", 20 | "**Syntax**:\n", 21 | "\n", 22 | "```python\n", 23 | "set.pop()\n", 24 | "```" 25 | ] 26 | }, 27 | { 28 | "cell_type": "markdown", 29 | "metadata": {}, 30 | "source": [ 31 | "## `pop()` Parameters\n", 32 | "\n", 33 | "The **`pop()`** method doesn't take any arguments." 34 | ] 35 | }, 36 | { 37 | "cell_type": "markdown", 38 | "metadata": {}, 39 | "source": [ 40 | "## Return Value from `pop()`\n", 41 | "\n", 42 | "The **`pop()`** method returns an arbitrary (random) element from the set. Also, the set is updated and will not contain the element (which is returned).\n", 43 | "\n", 44 | "If the set is empty, **`TypeError`** exception is raised." 45 | ] 46 | }, 47 | { 48 | "cell_type": "code", 49 | "execution_count": 1, 50 | "metadata": { 51 | "ExecuteTime": { 52 | "end_time": "2021-06-10T17:45:26.148841Z", 53 | "start_time": "2021-06-10T17:45:26.131312Z" 54 | } 55 | }, 56 | "outputs": [ 57 | { 58 | "name": "stdout", 59 | "output_type": "stream", 60 | "text": [ 61 | "Return Value is c\n", 62 | "A = {'a', 'd', 'b'}\n" 63 | ] 64 | } 65 | ], 66 | "source": [ 67 | "# Example 1: How pop() works for Python Sets?\n", 68 | "\n", 69 | "A ={'a', 'b', 'c', 'd'}\n", 70 | "\n", 71 | "print('Return Value is', A.pop())\n", 72 | "print('A = ', A)\n", 73 | "\n", 74 | "# When you run the program, we got the following output as below:" 75 | ] 76 | }, 77 | { 78 | "cell_type": "markdown", 79 | "metadata": {}, 80 | "source": [ 81 | ">**Note:** You may get different output as **`pop()`** returns and removes a random element." 82 | ] 83 | }, 84 | { 85 | "cell_type": "code", 86 | "execution_count": 2, 87 | "metadata": { 88 | "ExecuteTime": { 89 | "end_time": "2021-06-10T17:45:27.631976Z", 90 | "start_time": "2021-06-10T17:45:27.620288Z" 91 | } 92 | }, 93 | "outputs": [ 94 | { 95 | "name": "stdout", 96 | "output_type": "stream", 97 | "text": [ 98 | "course\n", 99 | "{'Welcome', 'to', 'Python'}\n" 100 | ] 101 | } 102 | ], 103 | "source": [ 104 | "# Example 2: How pop() works for Python Sets?\n", 105 | "\n", 106 | "set1 = {\"Welcome\", \"to\", \"Python\", \"course\"}\n", 107 | "print(set1.pop())\n", 108 | "print(set1)" 109 | ] 110 | }, 111 | { 112 | "cell_type": "code", 113 | "execution_count": null, 114 | "metadata": {}, 115 | "outputs": [], 116 | "source": [] 117 | } 118 | ], 119 | "metadata": { 120 | "hide_input": false, 121 | "kernelspec": { 122 | "display_name": "Python 3", 123 | "language": "python", 124 | "name": "python3" 125 | }, 126 | "language_info": { 127 | "codemirror_mode": { 128 | "name": "ipython", 129 | "version": 3 130 | }, 131 | "file_extension": ".py", 132 | "mimetype": "text/x-python", 133 | "name": "python", 134 | "nbconvert_exporter": "python", 135 | "pygments_lexer": "ipython3", 136 | "version": "3.8.8" 137 | }, 138 | "toc": { 139 | "base_numbering": 1, 140 | "nav_menu": {}, 141 | "number_sections": true, 142 | "sideBar": true, 143 | "skip_h1_title": false, 144 | "title_cell": "Table of Contents", 145 | "title_sidebar": "Contents", 146 | "toc_cell": false, 147 | "toc_position": {}, 148 | "toc_section_display": true, 149 | "toc_window_display": false 150 | }, 151 | "varInspector": { 152 | "cols": { 153 | "lenName": 16, 154 | "lenType": 16, 155 | "lenVar": 40 156 | }, 157 | "kernels_config": { 158 | "python": { 159 | "delete_cmd_postfix": "", 160 | "delete_cmd_prefix": "del ", 161 | "library": "var_list.py", 162 | "varRefreshCmd": "print(var_dic_list())" 163 | }, 164 | "r": { 165 | "delete_cmd_postfix": ") ", 166 | "delete_cmd_prefix": "rm(", 167 | "library": "var_list.r", 168 | "varRefreshCmd": "cat(var_dic_list()) " 169 | } 170 | }, 171 | "types_to_exclude": [ 172 | "module", 173 | "function", 174 | "builtin_function_or_method", 175 | "instance", 176 | "_Feature" 177 | ], 178 | "window_display": false 179 | } 180 | }, 181 | "nbformat": 4, 182 | "nbformat_minor": 2 183 | } 184 | -------------------------------------------------------------------------------- /002_Python_String_Methods/027_Python_String_swapcase().ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\n", 8 | "All the IPython Notebooks in this lecture series by Dr. Milan Parmar are available @ **[GitHub](https://github.com/milaan9/02_Python_Datatypes/tree/main/002_Python_String_Methods)**\n", 9 | "" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "# Python String `swapcase()`\n", 17 | "\n", 18 | "The string **`swapcase()`** method converts all uppercase characters to lowercase and all lowercase characters to uppercase characters of the given string, and returns it.\n", 19 | "\n", 20 | "**Syntax**:\n", 21 | "\n", 22 | "```python\n", 23 | "string.swapcase()\n", 24 | "```\n", 25 | "\n", 26 | ">**Note:** Not necessarily, **`string.swapcase().swapcase() == string`**" 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "metadata": { 32 | "heading_collapsed": true 33 | }, 34 | "source": [ 35 | "## `swapcase()` Parameters\n", 36 | "\n", 37 | "The **`swapcase()`** method doesn't take any parameters." 38 | ] 39 | }, 40 | { 41 | "cell_type": "markdown", 42 | "metadata": {}, 43 | "source": [ 44 | "## Return Value from `swapcase()`\n", 45 | "\n", 46 | "The **`swapcase()`** method returns the string where all uppercase characters are converted to lowercase, and lowercase characters are converted to uppercase." 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "execution_count": 1, 52 | "metadata": { 53 | "ExecuteTime": { 54 | "end_time": "2021-06-10T18:12:49.198569Z", 55 | "start_time": "2021-06-10T18:12:49.190774Z" 56 | }, 57 | "scrolled": true 58 | }, 59 | "outputs": [ 60 | { 61 | "name": "stdout", 62 | "output_type": "stream", 63 | "text": [ 64 | "this should all be lowercase.\n", 65 | "THIS SHOULD ALL BE UPPERCASE.\n", 66 | "tHiS sHoUlD bE mIxEd CaSeD.\n" 67 | ] 68 | } 69 | ], 70 | "source": [ 71 | "# Example 1: Swap lowercase to uppercase and vice versa using swapcase()\n", 72 | "\n", 73 | "# example string\n", 74 | "string = \"THIS SHOULD ALL BE LOWERCASE.\"\n", 75 | "print(string.swapcase())\n", 76 | "\n", 77 | "string = \"this should all be uppercase.\"\n", 78 | "print(string.swapcase())\n", 79 | "\n", 80 | "string = \"ThIs ShOuLd Be MiXeD cAsEd.\"\n", 81 | "print(string.swapcase())" 82 | ] 83 | }, 84 | { 85 | "cell_type": "markdown", 86 | "metadata": {}, 87 | "source": [ 88 | ">**Note:** If you want to convert string to lowercase only, use **[lower()](https://github.com/milaan9/02_Python_Datatypes/blob/main/002_Python_String_Methods/025_Python_String_lower%28%29.ipynb)**. Likewise, if you want to convert string to uppercase only, use **[upper()](https://github.com/milaan9/02_Python_Datatypes/blob/main/002_Python_String_Methods/026_Python_String_upper%28%29.ipynb)**." 89 | ] 90 | }, 91 | { 92 | "cell_type": "code", 93 | "execution_count": null, 94 | "metadata": {}, 95 | "outputs": [], 96 | "source": [] 97 | } 98 | ], 99 | "metadata": { 100 | "hide_input": false, 101 | "kernelspec": { 102 | "display_name": "Python 3", 103 | "language": "python", 104 | "name": "python3" 105 | }, 106 | "language_info": { 107 | "codemirror_mode": { 108 | "name": "ipython", 109 | "version": 3 110 | }, 111 | "file_extension": ".py", 112 | "mimetype": "text/x-python", 113 | "name": "python", 114 | "nbconvert_exporter": "python", 115 | "pygments_lexer": "ipython3", 116 | "version": "3.8.8" 117 | }, 118 | "toc": { 119 | "base_numbering": 1, 120 | "nav_menu": {}, 121 | "number_sections": true, 122 | "sideBar": true, 123 | "skip_h1_title": false, 124 | "title_cell": "Table of Contents", 125 | "title_sidebar": "Contents", 126 | "toc_cell": false, 127 | "toc_position": {}, 128 | "toc_section_display": true, 129 | "toc_window_display": false 130 | }, 131 | "varInspector": { 132 | "cols": { 133 | "lenName": 16, 134 | "lenType": 16, 135 | "lenVar": 40 136 | }, 137 | "kernels_config": { 138 | "python": { 139 | "delete_cmd_postfix": "", 140 | "delete_cmd_prefix": "del ", 141 | "library": "var_list.py", 142 | "varRefreshCmd": "print(var_dic_list())" 143 | }, 144 | "r": { 145 | "delete_cmd_postfix": ") ", 146 | "delete_cmd_prefix": "rm(", 147 | "library": "var_list.r", 148 | "varRefreshCmd": "cat(var_dic_list()) " 149 | } 150 | }, 151 | "types_to_exclude": [ 152 | "module", 153 | "function", 154 | "builtin_function_or_method", 155 | "instance", 156 | "_Feature" 157 | ], 158 | "window_display": false 159 | } 160 | }, 161 | "nbformat": 4, 162 | "nbformat_minor": 2 163 | } 164 | -------------------------------------------------------------------------------- /005_Python_Dictionary_Methods/008_Python_Dictionary_popitem().ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\n", 8 | "All the IPython Notebooks in this lecture series by Dr. Milan Parmar are available @ **[GitHub](https://github.com/milaan9/02_Python_Datatypes/tree/main/005_Python_Dictionary_Methods)**\n", 9 | "" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "# Python Dictionary `popitem()`\n", 17 | "\n", 18 | "The **`popitem()`** method removes and returns the last element (key, value) pair inserted into the dictionary.\n", 19 | "\n", 20 | "**Syntax**:\n", 21 | "\n", 22 | "```python\n", 23 | "dictionary.popitem() \n", 24 | "```" 25 | ] 26 | }, 27 | { 28 | "cell_type": "markdown", 29 | "metadata": {}, 30 | "source": [ 31 | "## `popitem()` Parameters\n", 32 | "\n", 33 | "The **`popitem()`** method doesn't take any parameters." 34 | ] 35 | }, 36 | { 37 | "cell_type": "markdown", 38 | "metadata": {}, 39 | "source": [ 40 | "## Return Value from `popitem()`\n", 41 | "\n", 42 | "The **`popitem()`** method removes and returns the **(key, value)** pair from the dictionary in the **Last In, First Out (LIFO)** order.\n", 43 | "\n", 44 | "* Returns the latest inserted element **(key,value)** pair from the dictionary.\n", 45 | "* Removes the returned element pair from the dictionary.\n", 46 | "\n", 47 | ">**Note:** Before Python 3.7, the **`popitem()`** method returned and removed an arbitrary element (key, value) pair from the dictionary." 48 | ] 49 | }, 50 | { 51 | "cell_type": "code", 52 | "execution_count": 1, 53 | "metadata": { 54 | "ExecuteTime": { 55 | "end_time": "2021-06-09T18:12:28.805038Z", 56 | "start_time": "2021-06-09T18:12:28.783618Z" 57 | } 58 | }, 59 | "outputs": [ 60 | { 61 | "name": "stdout", 62 | "output_type": "stream", 63 | "text": [ 64 | "Return Value = ('salary', 3500.0)\n", 65 | "person = {'name': 'Phill', 'age': 22}\n", 66 | "Return Value = ('profession', 'Plumber')\n", 67 | "person = {'name': 'Phill', 'age': 22}\n" 68 | ] 69 | } 70 | ], 71 | "source": [ 72 | "# Example: Working of popitem() method\n", 73 | "\n", 74 | "person = {'name': 'Phill', 'age': 22, 'salary': 3500.0}\n", 75 | "\n", 76 | "# ('salary', 3500.0) is inserted at the last, so it is removed.\n", 77 | "result = person.popitem()\n", 78 | "\n", 79 | "print('Return Value = ', result)\n", 80 | "print('person = ', person)\n", 81 | "\n", 82 | "# inserting a new element pair\n", 83 | "person['profession'] = 'Plumber'\n", 84 | "\n", 85 | "# now ('profession', 'Plumber') is the latest element\n", 86 | "result = person.popitem()\n", 87 | "\n", 88 | "print('Return Value = ', result)\n", 89 | "print('person = ', person)" 90 | ] 91 | }, 92 | { 93 | "cell_type": "markdown", 94 | "metadata": {}, 95 | "source": [ 96 | "> **Note:** The **`popitem()`** method raises a **`KeyError`** error if the dictionary is empty." 97 | ] 98 | }, 99 | { 100 | "cell_type": "code", 101 | "execution_count": null, 102 | "metadata": {}, 103 | "outputs": [], 104 | "source": [] 105 | } 106 | ], 107 | "metadata": { 108 | "hide_input": false, 109 | "kernelspec": { 110 | "display_name": "Python 3", 111 | "language": "python", 112 | "name": "python3" 113 | }, 114 | "language_info": { 115 | "codemirror_mode": { 116 | "name": "ipython", 117 | "version": 3 118 | }, 119 | "file_extension": ".py", 120 | "mimetype": "text/x-python", 121 | "name": "python", 122 | "nbconvert_exporter": "python", 123 | "pygments_lexer": "ipython3", 124 | "version": "3.8.8" 125 | }, 126 | "toc": { 127 | "base_numbering": 1, 128 | "nav_menu": {}, 129 | "number_sections": true, 130 | "sideBar": true, 131 | "skip_h1_title": false, 132 | "title_cell": "Table of Contents", 133 | "title_sidebar": "Contents", 134 | "toc_cell": false, 135 | "toc_position": {}, 136 | "toc_section_display": true, 137 | "toc_window_display": false 138 | }, 139 | "varInspector": { 140 | "cols": { 141 | "lenName": 16, 142 | "lenType": 16, 143 | "lenVar": 40 144 | }, 145 | "kernels_config": { 146 | "python": { 147 | "delete_cmd_postfix": "", 148 | "delete_cmd_prefix": "del ", 149 | "library": "var_list.py", 150 | "varRefreshCmd": "print(var_dic_list())" 151 | }, 152 | "r": { 153 | "delete_cmd_postfix": ") ", 154 | "delete_cmd_prefix": "rm(", 155 | "library": "var_list.r", 156 | "varRefreshCmd": "cat(var_dic_list()) " 157 | } 158 | }, 159 | "types_to_exclude": [ 160 | "module", 161 | "function", 162 | "builtin_function_or_method", 163 | "instance", 164 | "_Feature" 165 | ], 166 | "window_display": false 167 | } 168 | }, 169 | "nbformat": 4, 170 | "nbformat_minor": 2 171 | } 172 | -------------------------------------------------------------------------------- /006_Python_Sets_Methods/014_Python_Set_symmetric_difference().ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\n", 8 | "All the IPython Notebooks in this lecture series by Dr. Milan Parmar are available @ **[GitHub](https://github.com/milaan9/02_Python_Datatypes/tree/main/006_Python_Sets_Methods)**\n", 9 | "" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "# Python Set `symmetric_difference()`\n", 17 | "\n", 18 | "The **`symmetric_difference()`** method returns the symmetric difference of two sets.\n", 19 | "\n", 20 | "The symmetric difference of two sets **`A`** and **`B`** is the set of elements that are in either **`A`** or **`B`**, but not in their intersection.\n", 21 | "\n", 22 | "
\n", 23 | "\n", 24 | "
\n", 25 | "\n", 26 | "Here, set **`B`** is a superset of set **`A`** and **`A`** is a subset of set **`B`**." 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "metadata": {}, 32 | "source": [ 33 | "**Syntax**:\n", 34 | "\n", 35 | "```python\n", 36 | "A.symmetric_difference(B)\n", 37 | "```" 38 | ] 39 | }, 40 | { 41 | "cell_type": "code", 42 | "execution_count": 1, 43 | "metadata": { 44 | "ExecuteTime": { 45 | "end_time": "2021-06-10T17:45:39.237021Z", 46 | "start_time": "2021-06-10T17:45:39.220467Z" 47 | } 48 | }, 49 | "outputs": [ 50 | { 51 | "name": "stdout", 52 | "output_type": "stream", 53 | "text": [ 54 | "{'a', 'e', 'b'}\n", 55 | "{'a', 'e', 'b'}\n", 56 | "{'a', 'b', 'd', 'c'}\n", 57 | "{'e', 'd', 'c'}\n" 58 | ] 59 | } 60 | ], 61 | "source": [ 62 | "# Example 1: Working of symmetric_difference()\n", 63 | "\n", 64 | "A = {'a', 'b', 'c', 'd'}\n", 65 | "B = {'c', 'd', 'e' }\n", 66 | "C = {}\n", 67 | "\n", 68 | "print(A.symmetric_difference(B))\n", 69 | "print(B.symmetric_difference(A))\n", 70 | "\n", 71 | "print(A.symmetric_difference(C))\n", 72 | "print(B.symmetric_difference(C))" 73 | ] 74 | }, 75 | { 76 | "cell_type": "markdown", 77 | "metadata": {}, 78 | "source": [ 79 | "## Symmetric difference using `^` operator\n", 80 | "\n", 81 | "In Python, we can also find the symmetric difference using the **`^`** operator." 82 | ] 83 | }, 84 | { 85 | "cell_type": "code", 86 | "execution_count": 2, 87 | "metadata": { 88 | "ExecuteTime": { 89 | "end_time": "2021-06-10T17:45:42.157516Z", 90 | "start_time": "2021-06-10T17:45:42.147777Z" 91 | } 92 | }, 93 | "outputs": [ 94 | { 95 | "name": "stdout", 96 | "output_type": "stream", 97 | "text": [ 98 | "{'a', 'e', 'b'}\n", 99 | "{'a', 'e', 'b'}\n", 100 | "set()\n", 101 | "set()\n" 102 | ] 103 | } 104 | ], 105 | "source": [ 106 | "A = {'a', 'b', 'c', 'd'}\n", 107 | "B = {'c', 'd', 'e' }\n", 108 | "\n", 109 | "print(A ^ B)\n", 110 | "print(B ^ A)\n", 111 | "\n", 112 | "print(A ^ A)\n", 113 | "print(B ^ B)" 114 | ] 115 | }, 116 | { 117 | "cell_type": "code", 118 | "execution_count": null, 119 | "metadata": {}, 120 | "outputs": [], 121 | "source": [] 122 | } 123 | ], 124 | "metadata": { 125 | "hide_input": false, 126 | "kernelspec": { 127 | "display_name": "Python 3", 128 | "language": "python", 129 | "name": "python3" 130 | }, 131 | "language_info": { 132 | "codemirror_mode": { 133 | "name": "ipython", 134 | "version": 3 135 | }, 136 | "file_extension": ".py", 137 | "mimetype": "text/x-python", 138 | "name": "python", 139 | "nbconvert_exporter": "python", 140 | "pygments_lexer": "ipython3", 141 | "version": "3.8.8" 142 | }, 143 | "toc": { 144 | "base_numbering": 1, 145 | "nav_menu": {}, 146 | "number_sections": true, 147 | "sideBar": true, 148 | "skip_h1_title": false, 149 | "title_cell": "Table of Contents", 150 | "title_sidebar": "Contents", 151 | "toc_cell": false, 152 | "toc_position": {}, 153 | "toc_section_display": true, 154 | "toc_window_display": false 155 | }, 156 | "varInspector": { 157 | "cols": { 158 | "lenName": 16, 159 | "lenType": 16, 160 | "lenVar": 40 161 | }, 162 | "kernels_config": { 163 | "python": { 164 | "delete_cmd_postfix": "", 165 | "delete_cmd_prefix": "del ", 166 | "library": "var_list.py", 167 | "varRefreshCmd": "print(var_dic_list())" 168 | }, 169 | "r": { 170 | "delete_cmd_postfix": ") ", 171 | "delete_cmd_prefix": "rm(", 172 | "library": "var_list.r", 173 | "varRefreshCmd": "cat(var_dic_list()) " 174 | } 175 | }, 176 | "types_to_exclude": [ 177 | "module", 178 | "function", 179 | "builtin_function_or_method", 180 | "instance", 181 | "_Feature" 182 | ], 183 | "window_display": false 184 | } 185 | }, 186 | "nbformat": 4, 187 | "nbformat_minor": 2 188 | } 189 | -------------------------------------------------------------------------------- /003_Python_List_Methods/011_Python_List_clear().ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\n", 8 | "All the IPython Notebooks in this lecture series by Dr. Milan Parmar are available @ **[GitHub](https://github.com/milaan9/02_Python_Datatypes/tree/main/003_Python_List_Methods)**\n", 9 | "" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "# Python List `clear()`\n", 17 | "\n", 18 | "The **`clear()`** method removes all items from the list.\n", 19 | "\n", 20 | "**Syntax**:\n", 21 | "\n", 22 | "```python\n", 23 | "list.clear()\n", 24 | "```" 25 | ] 26 | }, 27 | { 28 | "cell_type": "markdown", 29 | "metadata": {}, 30 | "source": [ 31 | "## `pop()` Parameters\n", 32 | "\n", 33 | "The **`clear()`** method doesn't take any parameters." 34 | ] 35 | }, 36 | { 37 | "cell_type": "markdown", 38 | "metadata": {}, 39 | "source": [ 40 | "## Return Value from `clear()`\n", 41 | "\n", 42 | "The **`clear()`** method only empties the given **[list](https://github.com/milaan9/02_Python_Datatypes/blob/main/003_Python_List.ipynb)**. It doesn't return any value." 43 | ] 44 | }, 45 | { 46 | "cell_type": "code", 47 | "execution_count": 1, 48 | "metadata": { 49 | "ExecuteTime": { 50 | "end_time": "2021-06-10T17:59:13.265368Z", 51 | "start_time": "2021-06-10T17:59:13.243458Z" 52 | } 53 | }, 54 | "outputs": [ 55 | { 56 | "name": "stdout", 57 | "output_type": "stream", 58 | "text": [ 59 | "List: []\n" 60 | ] 61 | } 62 | ], 63 | "source": [ 64 | "# Example 1: Working of clear() method\n", 65 | "\n", 66 | "# Defining a list\n", 67 | "list = [{1, 2}, ('a'), ['1.1', '2.2']]\n", 68 | "\n", 69 | "# clearing the list\n", 70 | "list.clear()\n", 71 | "\n", 72 | "print('List:', list)" 73 | ] 74 | }, 75 | { 76 | "cell_type": "markdown", 77 | "metadata": {}, 78 | "source": [ 79 | ">**Note:** If you are using Python 2 or Python 3.2 and below, you cannot use the **`clear()`** method. You can use the del operator instead." 80 | ] 81 | }, 82 | { 83 | "cell_type": "code", 84 | "execution_count": 2, 85 | "metadata": { 86 | "ExecuteTime": { 87 | "end_time": "2021-06-10T17:59:14.279606Z", 88 | "start_time": "2021-06-10T17:59:14.265975Z" 89 | } 90 | }, 91 | "outputs": [ 92 | { 93 | "name": "stdout", 94 | "output_type": "stream", 95 | "text": [ 96 | "List: []\n" 97 | ] 98 | } 99 | ], 100 | "source": [ 101 | "# Example 2: Emptying the List Using del\n", 102 | "\n", 103 | "# Defining a list\n", 104 | "list = [{1, 2}, ('a'), ['1.1', '2.2']]\n", 105 | "\n", 106 | "# clearing the list\n", 107 | "del list[:]\n", 108 | "\n", 109 | "print('List:', list)" 110 | ] 111 | }, 112 | { 113 | "cell_type": "markdown", 114 | "metadata": {}, 115 | "source": [ 116 | "Visit **[Python del statement](https://github.com/milaan9/02_Python_Datatypes/blob/main/003_Python_List_Methods/Python_del_statement.ipynb)** to learn how **`del`** operator works in Python." 117 | ] 118 | }, 119 | { 120 | "cell_type": "code", 121 | "execution_count": null, 122 | "metadata": {}, 123 | "outputs": [], 124 | "source": [] 125 | } 126 | ], 127 | "metadata": { 128 | "hide_input": false, 129 | "kernelspec": { 130 | "display_name": "Python 3", 131 | "language": "python", 132 | "name": "python3" 133 | }, 134 | "language_info": { 135 | "codemirror_mode": { 136 | "name": "ipython", 137 | "version": 3 138 | }, 139 | "file_extension": ".py", 140 | "mimetype": "text/x-python", 141 | "name": "python", 142 | "nbconvert_exporter": "python", 143 | "pygments_lexer": "ipython3", 144 | "version": "3.8.8" 145 | }, 146 | "toc": { 147 | "base_numbering": 1, 148 | "nav_menu": {}, 149 | "number_sections": true, 150 | "sideBar": true, 151 | "skip_h1_title": false, 152 | "title_cell": "Table of Contents", 153 | "title_sidebar": "Contents", 154 | "toc_cell": false, 155 | "toc_position": {}, 156 | "toc_section_display": true, 157 | "toc_window_display": false 158 | }, 159 | "varInspector": { 160 | "cols": { 161 | "lenName": 16, 162 | "lenType": 16, 163 | "lenVar": 40 164 | }, 165 | "kernels_config": { 166 | "python": { 167 | "delete_cmd_postfix": "", 168 | "delete_cmd_prefix": "del ", 169 | "library": "var_list.py", 170 | "varRefreshCmd": "print(var_dic_list())" 171 | }, 172 | "r": { 173 | "delete_cmd_postfix": ") ", 174 | "delete_cmd_prefix": "rm(", 175 | "library": "var_list.r", 176 | "varRefreshCmd": "cat(var_dic_list()) " 177 | } 178 | }, 179 | "types_to_exclude": [ 180 | "module", 181 | "function", 182 | "builtin_function_or_method", 183 | "instance", 184 | "_Feature" 185 | ], 186 | "window_display": false 187 | } 188 | }, 189 | "nbformat": 4, 190 | "nbformat_minor": 2 191 | } 192 | -------------------------------------------------------------------------------- /002_Python_String_Methods/003_Python_String_casefold().ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\n", 8 | "All the IPython Notebooks in this lecture series by Dr. Milan Parmar are available @ **[GitHub](https://github.com/milaan9/02_Python_Datatypes/tree/main/002_Python_String_Methods)**\n", 9 | "" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "# Python String `casefold()`\n", 17 | "\n", 18 | "The **`casefold()`** method is an aggressive lower() method which converts strings to case folded strings for caseless matching.\n", 19 | "\n", 20 | "The **`casefold()`** method removes all case distinctions present in a **[string](https://github.com/milaan9/02_Python_Datatypes/blob/main/002_Python_String.ipynb)**. It is used for caseless matching, i.e. ignores cases when comparing.\n", 21 | "\n", 22 | "For example, the German lowercase letter **`ß`** is equivalent to **`ss`**. However, since **`ß`** is already lowercase, the **`lower()`** method does nothing to it. But, **`casefold()`** converts it to **`ss`**.\n", 23 | "\n", 24 | "**Syntax**:\n", 25 | "\n", 26 | "```python\n", 27 | "string.casefold()\n", 28 | "```" 29 | ] 30 | }, 31 | { 32 | "cell_type": "markdown", 33 | "metadata": {}, 34 | "source": [ 35 | "## `casefold()` Parameters\n", 36 | "\n", 37 | "The **`casefold()`** method doesn't take any parameters." 38 | ] 39 | }, 40 | { 41 | "cell_type": "markdown", 42 | "metadata": {}, 43 | "source": [ 44 | "## Return Value from `casefold()`\n", 45 | "\n", 46 | "The **`casefold()`** method returns the case folded string." 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "execution_count": 1, 52 | "metadata": { 53 | "ExecuteTime": { 54 | "end_time": "2021-06-10T18:03:52.468527Z", 55 | "start_time": "2021-06-10T18:03:52.453922Z" 56 | } 57 | }, 58 | "outputs": [ 59 | { 60 | "name": "stdout", 61 | "output_type": "stream", 62 | "text": [ 63 | "Lowercase string: python is awesome\n" 64 | ] 65 | } 66 | ], 67 | "source": [ 68 | "# Example 1: Lowercase using casefold()\n", 69 | "\n", 70 | "string = \"PYTHON IS AWESOME\"\n", 71 | "\n", 72 | "# print lowercase string\n", 73 | "print(\"Lowercase string:\", string.casefold())" 74 | ] 75 | }, 76 | { 77 | "cell_type": "code", 78 | "execution_count": 2, 79 | "metadata": { 80 | "ExecuteTime": { 81 | "end_time": "2021-06-10T18:03:53.390250Z", 82 | "start_time": "2021-06-10T18:03:53.347405Z" 83 | } 84 | }, 85 | "outputs": [ 86 | { 87 | "name": "stdout", 88 | "output_type": "stream", 89 | "text": [ 90 | "The strings are equal.\n" 91 | ] 92 | } 93 | ], 94 | "source": [ 95 | "# Example 2: Comparison using casefold()\n", 96 | "\n", 97 | "firstString = \"der Fluß\"\n", 98 | "secondString = \"der Fluss\"\n", 99 | "\n", 100 | "# ß is equivalent to ss\n", 101 | "if firstString.casefold() == secondString.casefold():\n", 102 | " print('The strings are equal.')\n", 103 | "else:\n", 104 | " print('The strings are not equal.')" 105 | ] 106 | }, 107 | { 108 | "cell_type": "code", 109 | "execution_count": null, 110 | "metadata": {}, 111 | "outputs": [], 112 | "source": [] 113 | } 114 | ], 115 | "metadata": { 116 | "hide_input": false, 117 | "kernelspec": { 118 | "display_name": "Python 3", 119 | "language": "python", 120 | "name": "python3" 121 | }, 122 | "language_info": { 123 | "codemirror_mode": { 124 | "name": "ipython", 125 | "version": 3 126 | }, 127 | "file_extension": ".py", 128 | "mimetype": "text/x-python", 129 | "name": "python", 130 | "nbconvert_exporter": "python", 131 | "pygments_lexer": "ipython3", 132 | "version": "3.8.8" 133 | }, 134 | "toc": { 135 | "base_numbering": 1, 136 | "nav_menu": {}, 137 | "number_sections": true, 138 | "sideBar": true, 139 | "skip_h1_title": false, 140 | "title_cell": "Table of Contents", 141 | "title_sidebar": "Contents", 142 | "toc_cell": false, 143 | "toc_position": {}, 144 | "toc_section_display": true, 145 | "toc_window_display": false 146 | }, 147 | "varInspector": { 148 | "cols": { 149 | "lenName": 16, 150 | "lenType": 16, 151 | "lenVar": 40 152 | }, 153 | "kernels_config": { 154 | "python": { 155 | "delete_cmd_postfix": "", 156 | "delete_cmd_prefix": "del ", 157 | "library": "var_list.py", 158 | "varRefreshCmd": "print(var_dic_list())" 159 | }, 160 | "r": { 161 | "delete_cmd_postfix": ") ", 162 | "delete_cmd_prefix": "rm(", 163 | "library": "var_list.r", 164 | "varRefreshCmd": "cat(var_dic_list()) " 165 | } 166 | }, 167 | "types_to_exclude": [ 168 | "module", 169 | "function", 170 | "builtin_function_or_method", 171 | "instance", 172 | "_Feature" 173 | ], 174 | "window_display": false 175 | } 176 | }, 177 | "nbformat": 4, 178 | "nbformat_minor": 2 179 | } 180 | -------------------------------------------------------------------------------- /003_Python_List_Methods/006_Python_List_count().ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\n", 8 | "All the IPython Notebooks in this lecture series by Dr. Milan Parmar are available @ **[GitHub](https://github.com/milaan9/02_Python_Datatypes/tree/main/003_Python_List_Methods)**\n", 9 | "" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "# Python List `count()`\n", 17 | "\n", 18 | "The **`count()`** method returns the number of times the specified element appears in the list.\n", 19 | "\n", 20 | "**Syntax**:\n", 21 | "\n", 22 | "```python\n", 23 | "list.count(element)\n", 24 | "```" 25 | ] 26 | }, 27 | { 28 | "cell_type": "markdown", 29 | "metadata": {}, 30 | "source": [ 31 | "## `count()` Parameters\n", 32 | "\n", 33 | "The list **`count()`** method takes a single argument:\n", 34 | "\n", 35 | "* **element** - the element to be counted" 36 | ] 37 | }, 38 | { 39 | "cell_type": "markdown", 40 | "metadata": {}, 41 | "source": [ 42 | "## Return Value from `count()`\n", 43 | "\n", 44 | "The **`count()`** method returns the number of times **`element`** appears in the list." 45 | ] 46 | }, 47 | { 48 | "cell_type": "code", 49 | "execution_count": 1, 50 | "metadata": { 51 | "ExecuteTime": { 52 | "end_time": "2021-06-10T17:56:25.192602Z", 53 | "start_time": "2021-06-10T17:56:25.181891Z" 54 | } 55 | }, 56 | "outputs": [ 57 | { 58 | "name": "stdout", 59 | "output_type": "stream", 60 | "text": [ 61 | "The count of i is: 2\n", 62 | "The count of p is: 0\n" 63 | ] 64 | } 65 | ], 66 | "source": [ 67 | "# Example 1: Use of List count()\n", 68 | "\n", 69 | "# vowels list\n", 70 | "vowels = ['a', 'e', 'i', 'o', 'i', 'u']\n", 71 | "\n", 72 | "# count element 'i'\n", 73 | "count = vowels.count('i')\n", 74 | "\n", 75 | "# print count\n", 76 | "print('The count of i is:', count)\n", 77 | "\n", 78 | "# count element 'p'\n", 79 | "count = vowels.count('p')\n", 80 | "\n", 81 | "# print count\n", 82 | "print('The count of p is:', count)" 83 | ] 84 | }, 85 | { 86 | "cell_type": "code", 87 | "execution_count": 2, 88 | "metadata": { 89 | "ExecuteTime": { 90 | "end_time": "2021-06-10T17:56:26.222909Z", 91 | "start_time": "2021-06-10T17:56:26.211220Z" 92 | } 93 | }, 94 | "outputs": [ 95 | { 96 | "name": "stdout", 97 | "output_type": "stream", 98 | "text": [ 99 | "The count of ('a', 'b') is: 2\n", 100 | "The count of [3, 4] is: 1\n" 101 | ] 102 | } 103 | ], 104 | "source": [ 105 | "# Example 2: Count Tuple and List Elements Inside List\n", 106 | "\n", 107 | "# random list\n", 108 | "random = ['a', ('a', 'b'), ('a', 'b'), [3, 4]]\n", 109 | "\n", 110 | "# count element ('a', 'b')\n", 111 | "count = random.count(('a', 'b'))\n", 112 | "\n", 113 | "# print count\n", 114 | "print(\"The count of ('a', 'b') is:\", count)\n", 115 | "\n", 116 | "# count element [3, 4]\n", 117 | "count = random.count([3, 4])\n", 118 | "\n", 119 | "# print count\n", 120 | "print(\"The count of [3, 4] is:\", count)" 121 | ] 122 | }, 123 | { 124 | "cell_type": "code", 125 | "execution_count": null, 126 | "metadata": {}, 127 | "outputs": [], 128 | "source": [] 129 | } 130 | ], 131 | "metadata": { 132 | "hide_input": false, 133 | "kernelspec": { 134 | "display_name": "Python 3", 135 | "language": "python", 136 | "name": "python3" 137 | }, 138 | "language_info": { 139 | "codemirror_mode": { 140 | "name": "ipython", 141 | "version": 3 142 | }, 143 | "file_extension": ".py", 144 | "mimetype": "text/x-python", 145 | "name": "python", 146 | "nbconvert_exporter": "python", 147 | "pygments_lexer": "ipython3", 148 | "version": "3.8.8" 149 | }, 150 | "toc": { 151 | "base_numbering": 1, 152 | "nav_menu": {}, 153 | "number_sections": true, 154 | "sideBar": true, 155 | "skip_h1_title": false, 156 | "title_cell": "Table of Contents", 157 | "title_sidebar": "Contents", 158 | "toc_cell": false, 159 | "toc_position": {}, 160 | "toc_section_display": true, 161 | "toc_window_display": false 162 | }, 163 | "varInspector": { 164 | "cols": { 165 | "lenName": 16, 166 | "lenType": 16, 167 | "lenVar": 40 168 | }, 169 | "kernels_config": { 170 | "python": { 171 | "delete_cmd_postfix": "", 172 | "delete_cmd_prefix": "del ", 173 | "library": "var_list.py", 174 | "varRefreshCmd": "print(var_dic_list())" 175 | }, 176 | "r": { 177 | "delete_cmd_postfix": ") ", 178 | "delete_cmd_prefix": "rm(", 179 | "library": "var_list.r", 180 | "varRefreshCmd": "cat(var_dic_list()) " 181 | } 182 | }, 183 | "types_to_exclude": [ 184 | "module", 185 | "function", 186 | "builtin_function_or_method", 187 | "instance", 188 | "_Feature" 189 | ], 190 | "window_display": false 191 | } 192 | }, 193 | "nbformat": 4, 194 | "nbformat_minor": 2 195 | } 196 | -------------------------------------------------------------------------------- /005_Python_Dictionary_Methods/011_Python_Dictionary_values().ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\n", 8 | "All the IPython Notebooks in this lecture series by Dr. Milan Parmar are available @ **[GitHub](https://github.com/milaan9/02_Python_Datatypes/tree/main/005_Python_Dictionary_Methods)**\n", 9 | "" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "# Python Dictionary `values()`\n", 17 | "\n", 18 | "The **`values()`** method returns a view object that displays a list of all the values in the dictionary.\n", 19 | "\n", 20 | "**Syntax**:\n", 21 | "\n", 22 | "```python\n", 23 | "dictionary.values()\n", 24 | "```" 25 | ] 26 | }, 27 | { 28 | "cell_type": "markdown", 29 | "metadata": {}, 30 | "source": [ 31 | "## `values()` Parameters\n", 32 | "\n", 33 | "The **`values()`** method doesn't take any parameters." 34 | ] 35 | }, 36 | { 37 | "cell_type": "markdown", 38 | "metadata": {}, 39 | "source": [ 40 | "## Return Value from `values()`\n", 41 | "\n", 42 | "The **`values()`** method returns a view object that displays a list of all values in a given dictionary." 43 | ] 44 | }, 45 | { 46 | "cell_type": "code", 47 | "execution_count": 1, 48 | "metadata": { 49 | "ExecuteTime": { 50 | "end_time": "2021-06-09T18:13:06.127849Z", 51 | "start_time": "2021-06-09T18:13:06.112270Z" 52 | } 53 | }, 54 | "outputs": [ 55 | { 56 | "name": "stdout", 57 | "output_type": "stream", 58 | "text": [ 59 | "dict_values([2, 3, 4])\n" 60 | ] 61 | } 62 | ], 63 | "source": [ 64 | "# Example 1: Get all values from the dictionary\n", 65 | "\n", 66 | "# random sales dictionary\n", 67 | "sales = { 'apple': 2, 'orange': 3, 'grapes': 4 }\n", 68 | "\n", 69 | "print(sales.values())" 70 | ] 71 | }, 72 | { 73 | "cell_type": "code", 74 | "execution_count": 2, 75 | "metadata": { 76 | "ExecuteTime": { 77 | "end_time": "2021-06-09T18:13:06.923467Z", 78 | "start_time": "2021-06-09T18:13:06.901069Z" 79 | } 80 | }, 81 | "outputs": [ 82 | { 83 | "name": "stdout", 84 | "output_type": "stream", 85 | "text": [ 86 | "Original items: dict_values([2, 3, 4])\n", 87 | "Updated items: dict_values([3, 4])\n" 88 | ] 89 | } 90 | ], 91 | "source": [ 92 | "# Example 2: How values() works when dictionary is modified?\n", 93 | "\n", 94 | "# random sales dictionary\n", 95 | "sales = { 'apple': 2, 'orange': 3, 'grapes': 4 }\n", 96 | "\n", 97 | "values = sales.values()\n", 98 | "print('Original items:', values)\n", 99 | "\n", 100 | "# delete an item from dictionary\n", 101 | "del[sales['apple']]\n", 102 | "print('Updated items:', values)" 103 | ] 104 | }, 105 | { 106 | "cell_type": "markdown", 107 | "metadata": {}, 108 | "source": [ 109 | "**Explanation:** \n", 110 | "\n", 111 | "The view object **`values`** doesn't itself return a list of **`sales`** item values but it returns a view of all values of the dictionary.\n", 112 | "\n", 113 | "If the list is updated at any time, the changes are reflected on the view object itself, as shown in the above program." 114 | ] 115 | }, 116 | { 117 | "cell_type": "code", 118 | "execution_count": null, 119 | "metadata": {}, 120 | "outputs": [], 121 | "source": [] 122 | } 123 | ], 124 | "metadata": { 125 | "hide_input": false, 126 | "kernelspec": { 127 | "display_name": "Python 3", 128 | "language": "python", 129 | "name": "python3" 130 | }, 131 | "language_info": { 132 | "codemirror_mode": { 133 | "name": "ipython", 134 | "version": 3 135 | }, 136 | "file_extension": ".py", 137 | "mimetype": "text/x-python", 138 | "name": "python", 139 | "nbconvert_exporter": "python", 140 | "pygments_lexer": "ipython3", 141 | "version": "3.8.8" 142 | }, 143 | "toc": { 144 | "base_numbering": 1, 145 | "nav_menu": {}, 146 | "number_sections": true, 147 | "sideBar": true, 148 | "skip_h1_title": false, 149 | "title_cell": "Table of Contents", 150 | "title_sidebar": "Contents", 151 | "toc_cell": false, 152 | "toc_position": {}, 153 | "toc_section_display": true, 154 | "toc_window_display": false 155 | }, 156 | "varInspector": { 157 | "cols": { 158 | "lenName": 16, 159 | "lenType": 16, 160 | "lenVar": 40 161 | }, 162 | "kernels_config": { 163 | "python": { 164 | "delete_cmd_postfix": "", 165 | "delete_cmd_prefix": "del ", 166 | "library": "var_list.py", 167 | "varRefreshCmd": "print(var_dic_list())" 168 | }, 169 | "r": { 170 | "delete_cmd_postfix": ") ", 171 | "delete_cmd_prefix": "rm(", 172 | "library": "var_list.r", 173 | "varRefreshCmd": "cat(var_dic_list()) " 174 | } 175 | }, 176 | "types_to_exclude": [ 177 | "module", 178 | "function", 179 | "builtin_function_or_method", 180 | "instance", 181 | "_Feature" 182 | ], 183 | "window_display": false 184 | } 185 | }, 186 | "nbformat": 4, 187 | "nbformat_minor": 2 188 | } 189 | -------------------------------------------------------------------------------- /005_Python_Dictionary_Methods/006_Python_Dictionary_keys().ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\n", 8 | "All the IPython Notebooks in this lecture series by Dr. Milan Parmar are available @ **[GitHub](https://github.com/milaan9/02_Python_Datatypes/tree/main/005_Python_Dictionary_Methods)**\n", 9 | "" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "# Python Dictionary `keys()`\n", 17 | "\n", 18 | "The **`keys()`** method returns a view object that displays a list of all the keys in the dictionary\n", 19 | "\n", 20 | "**Syntax**:\n", 21 | "\n", 22 | "```python\n", 23 | "dictionary.keys() \n", 24 | "```" 25 | ] 26 | }, 27 | { 28 | "cell_type": "markdown", 29 | "metadata": {}, 30 | "source": [ 31 | "## `keys()` Parameters\n", 32 | "\n", 33 | "The **`keys()`** method doesn't take any parameters." 34 | ] 35 | }, 36 | { 37 | "cell_type": "markdown", 38 | "metadata": {}, 39 | "source": [ 40 | "## Return Value from `keys()`\n", 41 | "\n", 42 | "The **`keys()`** method returns a view object that displays a list of all the keys.\n", 43 | "\n", 44 | "When the dictionary is changed, the view object also reflects these changes." 45 | ] 46 | }, 47 | { 48 | "cell_type": "code", 49 | "execution_count": 1, 50 | "metadata": { 51 | "ExecuteTime": { 52 | "end_time": "2021-06-09T18:12:07.910657Z", 53 | "start_time": "2021-06-09T18:12:07.889233Z" 54 | } 55 | }, 56 | "outputs": [ 57 | { 58 | "name": "stdout", 59 | "output_type": "stream", 60 | "text": [ 61 | "dict_keys(['name', 'age', 'salary'])\n", 62 | "dict_keys([])\n" 63 | ] 64 | } 65 | ], 66 | "source": [ 67 | "# Example 1: How keys() works?\n", 68 | "\n", 69 | "person = {'name': 'Phill', 'age': 22, 'salary': 3500.0}\n", 70 | "print(person.keys())\n", 71 | "\n", 72 | "empty_dict = {}\n", 73 | "print(empty_dict.keys())" 74 | ] 75 | }, 76 | { 77 | "cell_type": "code", 78 | "execution_count": 2, 79 | "metadata": { 80 | "ExecuteTime": { 81 | "end_time": "2021-06-09T18:12:08.643950Z", 82 | "start_time": "2021-06-09T18:12:08.632262Z" 83 | } 84 | }, 85 | "outputs": [ 86 | { 87 | "name": "stdout", 88 | "output_type": "stream", 89 | "text": [ 90 | "Before dictionary is updated\n", 91 | "dict_keys(['name', 'age'])\n", 92 | "\n", 93 | "After dictionary is updated\n", 94 | "dict_keys(['name', 'age', 'salary'])\n" 95 | ] 96 | } 97 | ], 98 | "source": [ 99 | "# Example 2: How keys() works when dictionary is updated?\n", 100 | "\n", 101 | "person = {'name': 'Phill', 'age': 22, }\n", 102 | "\n", 103 | "print('Before dictionary is updated')\n", 104 | "keys = person.keys()\n", 105 | "print(keys)\n", 106 | "\n", 107 | "# adding an element to the dictionary\n", 108 | "person.update({'salary': 3500.0})\n", 109 | "print('\\nAfter dictionary is updated')\n", 110 | "print(keys)" 111 | ] 112 | }, 113 | { 114 | "cell_type": "markdown", 115 | "metadata": {}, 116 | "source": [ 117 | "**Note:** Here, when the dictionary is updated, **`keys`** is also automatically updated to reflect changes." 118 | ] 119 | }, 120 | { 121 | "cell_type": "code", 122 | "execution_count": null, 123 | "metadata": {}, 124 | "outputs": [], 125 | "source": [] 126 | } 127 | ], 128 | "metadata": { 129 | "hide_input": false, 130 | "kernelspec": { 131 | "display_name": "Python 3", 132 | "language": "python", 133 | "name": "python3" 134 | }, 135 | "language_info": { 136 | "codemirror_mode": { 137 | "name": "ipython", 138 | "version": 3 139 | }, 140 | "file_extension": ".py", 141 | "mimetype": "text/x-python", 142 | "name": "python", 143 | "nbconvert_exporter": "python", 144 | "pygments_lexer": "ipython3", 145 | "version": "3.8.8" 146 | }, 147 | "toc": { 148 | "base_numbering": 1, 149 | "nav_menu": {}, 150 | "number_sections": true, 151 | "sideBar": true, 152 | "skip_h1_title": false, 153 | "title_cell": "Table of Contents", 154 | "title_sidebar": "Contents", 155 | "toc_cell": false, 156 | "toc_position": {}, 157 | "toc_section_display": true, 158 | "toc_window_display": false 159 | }, 160 | "varInspector": { 161 | "cols": { 162 | "lenName": 16, 163 | "lenType": 16, 164 | "lenVar": 40 165 | }, 166 | "kernels_config": { 167 | "python": { 168 | "delete_cmd_postfix": "", 169 | "delete_cmd_prefix": "del ", 170 | "library": "var_list.py", 171 | "varRefreshCmd": "print(var_dic_list())" 172 | }, 173 | "r": { 174 | "delete_cmd_postfix": ") ", 175 | "delete_cmd_prefix": "rm(", 176 | "library": "var_list.r", 177 | "varRefreshCmd": "cat(var_dic_list()) " 178 | } 179 | }, 180 | "types_to_exclude": [ 181 | "module", 182 | "function", 183 | "builtin_function_or_method", 184 | "instance", 185 | "_Feature" 186 | ], 187 | "window_display": false 188 | } 189 | }, 190 | "nbformat": 4, 191 | "nbformat_minor": 2 192 | } 193 | -------------------------------------------------------------------------------- /003_Python_List_Methods/004_Python_List_insert().ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\n", 8 | "All the IPython Notebooks in this lecture series by Dr. Milan Parmar are available @ **[GitHub](https://github.com/milaan9/02_Python_Datatypes/tree/main/003_Python_List_Methods)**\n", 9 | "" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "# Python List `insert()`\n", 17 | "\n", 18 | "The list **`insert()`** method inserts an element to the list at the specified index.\n", 19 | "\n", 20 | "**Syntax**:\n", 21 | "\n", 22 | "```python\n", 23 | "list.insert(i, elem)\n", 24 | "```\n", 25 | "\n", 26 | "Here, **`elem`** is inserted to the list at the **$i_{th}$** index. All the elements after **`elem`** are shifted to the right." 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "metadata": {}, 32 | "source": [ 33 | "## `insert()` Parameters\n", 34 | "\n", 35 | "The **`insert()`** method takes two parameters:\n", 36 | "\n", 37 | "* **index** - the index where the element needs to be inserted\n", 38 | "* **element** - this is the element to be inserted in the list\n", 39 | "\n", 40 | ">**Notes:**\n", 41 | "* If **`index`** is 0, the element is inserted at the beginning of the list.\n", 42 | "* If **`index`** is 3, the element is inserted after the 3rd element. Its position will be 4th." 43 | ] 44 | }, 45 | { 46 | "cell_type": "markdown", 47 | "metadata": {}, 48 | "source": [ 49 | "## Return Value from `insert()`\n", 50 | "\n", 51 | "The **`insert()`** method doesn't return anything; returns None. It only updates the current list." 52 | ] 53 | }, 54 | { 55 | "cell_type": "code", 56 | "execution_count": 1, 57 | "metadata": { 58 | "ExecuteTime": { 59 | "end_time": "2021-06-10T17:55:59.469047Z", 60 | "start_time": "2021-06-10T17:55:59.461258Z" 61 | } 62 | }, 63 | "outputs": [ 64 | { 65 | "name": "stdout", 66 | "output_type": "stream", 67 | "text": [ 68 | "Updated List: ['a', 'e', 'i', 'o', 'u']\n" 69 | ] 70 | } 71 | ], 72 | "source": [ 73 | "# Example 1: Inserting an Element to the List\n", 74 | "\n", 75 | "# vowel list\n", 76 | "vowel = ['a', 'e', 'i', 'u']\n", 77 | "\n", 78 | "# 'o' is inserted at index 3\n", 79 | "# the position of 'o' will be 4th\n", 80 | "vowel.insert(3, 'o')\n", 81 | "\n", 82 | "print('Updated List:', vowel)" 83 | ] 84 | }, 85 | { 86 | "cell_type": "code", 87 | "execution_count": 2, 88 | "metadata": { 89 | "ExecuteTime": { 90 | "end_time": "2021-06-10T17:56:00.578235Z", 91 | "start_time": "2021-06-10T17:56:00.570444Z" 92 | } 93 | }, 94 | "outputs": [ 95 | { 96 | "name": "stdout", 97 | "output_type": "stream", 98 | "text": [ 99 | "Updated List: [{1, 2}, (3, 4), [5, 6, 7]]\n" 100 | ] 101 | } 102 | ], 103 | "source": [ 104 | "# Example 2: Inserting a Tuple (as an Element) to the List\n", 105 | "\n", 106 | "mixed_list = [{1, 2}, [5, 6, 7]]\n", 107 | "\n", 108 | "# number tuple\n", 109 | "number_tuple = (3, 4)\n", 110 | "\n", 111 | "# inserting a tuple to the list\n", 112 | "mixed_list.insert(1, number_tuple)\n", 113 | "\n", 114 | "print('Updated List:', mixed_list)" 115 | ] 116 | }, 117 | { 118 | "cell_type": "code", 119 | "execution_count": null, 120 | "metadata": {}, 121 | "outputs": [], 122 | "source": [] 123 | } 124 | ], 125 | "metadata": { 126 | "hide_input": false, 127 | "kernelspec": { 128 | "display_name": "Python 3", 129 | "language": "python", 130 | "name": "python3" 131 | }, 132 | "language_info": { 133 | "codemirror_mode": { 134 | "name": "ipython", 135 | "version": 3 136 | }, 137 | "file_extension": ".py", 138 | "mimetype": "text/x-python", 139 | "name": "python", 140 | "nbconvert_exporter": "python", 141 | "pygments_lexer": "ipython3", 142 | "version": "3.8.8" 143 | }, 144 | "toc": { 145 | "base_numbering": 1, 146 | "nav_menu": {}, 147 | "number_sections": true, 148 | "sideBar": true, 149 | "skip_h1_title": false, 150 | "title_cell": "Table of Contents", 151 | "title_sidebar": "Contents", 152 | "toc_cell": false, 153 | "toc_position": {}, 154 | "toc_section_display": true, 155 | "toc_window_display": false 156 | }, 157 | "varInspector": { 158 | "cols": { 159 | "lenName": 16, 160 | "lenType": 16, 161 | "lenVar": 40 162 | }, 163 | "kernels_config": { 164 | "python": { 165 | "delete_cmd_postfix": "", 166 | "delete_cmd_prefix": "del ", 167 | "library": "var_list.py", 168 | "varRefreshCmd": "print(var_dic_list())" 169 | }, 170 | "r": { 171 | "delete_cmd_postfix": ") ", 172 | "delete_cmd_prefix": "rm(", 173 | "library": "var_list.r", 174 | "varRefreshCmd": "cat(var_dic_list()) " 175 | } 176 | }, 177 | "types_to_exclude": [ 178 | "module", 179 | "function", 180 | "builtin_function_or_method", 181 | "instance", 182 | "_Feature" 183 | ], 184 | "window_display": false 185 | } 186 | }, 187 | "nbformat": 4, 188 | "nbformat_minor": 2 189 | } 190 | -------------------------------------------------------------------------------- /002_Python_String_Methods/040_Python_String_splitlines().ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\n", 8 | "All the IPython Notebooks in this lecture series by Dr. Milan Parmar are available @ **[GitHub](https://github.com/milaan9/02_Python_Datatypes/tree/main/002_Python_String_Methods)**\n", 9 | "" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "# Python String `splitlines()`\n", 17 | "\n", 18 | "The string **`splitlines()`** method splits the string at line breaks and returns a list of lines in the string.\n", 19 | "\n", 20 | "**Syntax**:\n", 21 | "\n", 22 | "```python\n", 23 | "str.splitlines([keepends])\n", 24 | "```" 25 | ] 26 | }, 27 | { 28 | "cell_type": "markdown", 29 | "metadata": { 30 | "heading_collapsed": true 31 | }, 32 | "source": [ 33 | "## `splitlines()` Parameters\n", 34 | "\n", 35 | "The **`splitlines()`** method takes maximum of 1 parameter:\n", 36 | "\n", 37 | "* **`keepends`** (optional)- If **`keepends`** is provided and **`True`**, line breaks are also included in items of the list.\n", 38 | "\n", 39 | "By default, the line breaks are not included." 40 | ] 41 | }, 42 | { 43 | "cell_type": "markdown", 44 | "metadata": {}, 45 | "source": [ 46 | "## Return Value from `splitlines()`\n", 47 | "\n", 48 | "The **`splitlines()`** method returns a list of lines in the string.\n", 49 | "\n", 50 | "If there are not line break characters, it returns a list with a single item (a single line)." 51 | ] 52 | }, 53 | { 54 | "cell_type": "markdown", 55 | "metadata": {}, 56 | "source": [ 57 | "| Representation | Description |\n", 58 | "|:----| :--- |\n", 59 | "| **`\\n`** | **Line Feed** | \n", 60 | "| **`\\r`** | **Carriage Return** | \n", 61 | "| **`\\r\\n`** | **Carriage Return + Line Feed** | \n", 62 | "| **`\\v`** or **`\\x0b`** | **Line Tabulation** | \n", 63 | "| **`\\f`** or **`\\x0c`** | **Form Feed** | \n", 64 | "| **`\\x1c`** | **File Separator** | \n", 65 | "| **`\\x1d`** | **Group Separator** | \n", 66 | "| **`\\x1e`** | **Record Separator** | \n", 67 | "| **`\\x85`** | **Next Line (C1 Control Code)** | \n", 68 | "| **`\\u2028`** | **Line Separator** | \n", 69 | "| **`\\u2029`** | **Paragraph Separator** | " 70 | ] 71 | }, 72 | { 73 | "cell_type": "code", 74 | "execution_count": 1, 75 | "metadata": { 76 | "ExecuteTime": { 77 | "end_time": "2021-06-10T18:16:15.018784Z", 78 | "start_time": "2021-06-10T18:16:14.996390Z" 79 | }, 80 | "scrolled": true 81 | }, 82 | "outputs": [ 83 | { 84 | "name": "stdout", 85 | "output_type": "stream", 86 | "text": [ 87 | "['Milk', 'Coffee', 'Bread', 'Butter']\n", 88 | "['Milk\\n', 'Coffee\\r\\n', 'Bread\\r', 'Butter']\n", 89 | "['Milk Coffee Bread Butter']\n" 90 | ] 91 | } 92 | ], 93 | "source": [ 94 | "# Example 1: How splitlines() works?\n", 95 | "\n", 96 | "grocery = 'Milk\\nCoffee\\r\\nBread\\rButter'\n", 97 | "\n", 98 | "print(grocery.splitlines())\n", 99 | "print(grocery.splitlines(True))\n", 100 | "\n", 101 | "grocery = 'Milk Coffee Bread Butter'\n", 102 | "print(grocery.splitlines())" 103 | ] 104 | }, 105 | { 106 | "cell_type": "code", 107 | "execution_count": null, 108 | "metadata": {}, 109 | "outputs": [], 110 | "source": [] 111 | } 112 | ], 113 | "metadata": { 114 | "hide_input": false, 115 | "kernelspec": { 116 | "display_name": "Python 3", 117 | "language": "python", 118 | "name": "python3" 119 | }, 120 | "language_info": { 121 | "codemirror_mode": { 122 | "name": "ipython", 123 | "version": 3 124 | }, 125 | "file_extension": ".py", 126 | "mimetype": "text/x-python", 127 | "name": "python", 128 | "nbconvert_exporter": "python", 129 | "pygments_lexer": "ipython3", 130 | "version": "3.8.8" 131 | }, 132 | "toc": { 133 | "base_numbering": 1, 134 | "nav_menu": {}, 135 | "number_sections": true, 136 | "sideBar": true, 137 | "skip_h1_title": false, 138 | "title_cell": "Table of Contents", 139 | "title_sidebar": "Contents", 140 | "toc_cell": false, 141 | "toc_position": {}, 142 | "toc_section_display": true, 143 | "toc_window_display": false 144 | }, 145 | "varInspector": { 146 | "cols": { 147 | "lenName": 16, 148 | "lenType": 16, 149 | "lenVar": 40 150 | }, 151 | "kernels_config": { 152 | "python": { 153 | "delete_cmd_postfix": "", 154 | "delete_cmd_prefix": "del ", 155 | "library": "var_list.py", 156 | "varRefreshCmd": "print(var_dic_list())" 157 | }, 158 | "r": { 159 | "delete_cmd_postfix": ") ", 160 | "delete_cmd_prefix": "rm(", 161 | "library": "var_list.r", 162 | "varRefreshCmd": "cat(var_dic_list()) " 163 | } 164 | }, 165 | "types_to_exclude": [ 166 | "module", 167 | "function", 168 | "builtin_function_or_method", 169 | "instance", 170 | "_Feature" 171 | ], 172 | "window_display": false 173 | } 174 | }, 175 | "nbformat": 4, 176 | "nbformat_minor": 2 177 | } 178 | -------------------------------------------------------------------------------- /002_Python_String_Methods/021_Python_String_isupper().ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\n", 8 | "All the IPython Notebooks in this lecture series by Dr. Milan Parmar are available @ **[GitHub](https://github.com/milaan9/02_Python_Datatypes/tree/main/002_Python_String_Methods)**\n", 9 | "" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "# Python String `isupper()`\n", 17 | "\n", 18 | "The string **`isupper()`** method returns **`True`** if all alphabets in a string are uppercase alphabets. If the string contains at least one lowercase alphabet, it returns **`False`**.\n", 19 | "\n", 20 | "**Syntax**:\n", 21 | "\n", 22 | "```python\n", 23 | "string.isupper()\n", 24 | "```" 25 | ] 26 | }, 27 | { 28 | "cell_type": "markdown", 29 | "metadata": { 30 | "heading_collapsed": true 31 | }, 32 | "source": [ 33 | "## `isupper()` Parameters\n", 34 | "\n", 35 | "The **`isupper()`** method doesn't take any parameters." 36 | ] 37 | }, 38 | { 39 | "cell_type": "markdown", 40 | "metadata": {}, 41 | "source": [ 42 | "## Return Value from `isupper()`\n", 43 | "\n", 44 | "The **`isupper()`** returns:\n", 45 | "\n", 46 | "* **`True`** if all characters in a string are uppercase characters.\n", 47 | "* **`False`** if any characters in a string are lowercase characters." 48 | ] 49 | }, 50 | { 51 | "cell_type": "code", 52 | "execution_count": 1, 53 | "metadata": { 54 | "ExecuteTime": { 55 | "end_time": "2021-06-10T18:10:14.834777Z", 56 | "start_time": "2021-06-10T18:10:14.818220Z" 57 | }, 58 | "scrolled": true 59 | }, 60 | "outputs": [ 61 | { 62 | "name": "stdout", 63 | "output_type": "stream", 64 | "text": [ 65 | "True\n", 66 | "True\n", 67 | "False\n" 68 | ] 69 | } 70 | ], 71 | "source": [ 72 | "# Example 1: Return value of isupper()\n", 73 | "\n", 74 | "# example string\n", 75 | "string = \"THIS IS GOOD!\"\n", 76 | "print(string.isupper());\n", 77 | "\n", 78 | "# numbers in place of alphabets\n", 79 | "string = \"THIS IS ALSO G00D!\"\n", 80 | "print(string.isupper());\n", 81 | "\n", 82 | "# lowercase string\n", 83 | "string = \"THIS IS not GOOD!\"\n", 84 | "print(string.isupper());" 85 | ] 86 | }, 87 | { 88 | "cell_type": "code", 89 | "execution_count": 2, 90 | "metadata": { 91 | "ExecuteTime": { 92 | "end_time": "2021-06-10T18:10:16.944080Z", 93 | "start_time": "2021-06-10T18:10:16.931418Z" 94 | } 95 | }, 96 | "outputs": [ 97 | { 98 | "name": "stdout", 99 | "output_type": "stream", 100 | "text": [ 101 | "Does not contain lowercase letter.\n", 102 | "Contains lowercase letter.\n" 103 | ] 104 | } 105 | ], 106 | "source": [ 107 | "# Example 2: How to use isupper() in a program?\n", 108 | "\n", 109 | "string = 'THIS IS GOOD'\n", 110 | "if string.isupper() == True:\n", 111 | " print('Does not contain lowercase letter.')\n", 112 | "else:\n", 113 | " print('Contains lowercase letter.')\n", 114 | " \n", 115 | "string = 'THIS IS gOOD'\n", 116 | "if string.isupper() == True:\n", 117 | " print('Does not contain lowercase letter.')\n", 118 | "else:\n", 119 | " print('Contains lowercase letter.')" 120 | ] 121 | }, 122 | { 123 | "cell_type": "code", 124 | "execution_count": null, 125 | "metadata": {}, 126 | "outputs": [], 127 | "source": [] 128 | } 129 | ], 130 | "metadata": { 131 | "hide_input": false, 132 | "kernelspec": { 133 | "display_name": "Python 3", 134 | "language": "python", 135 | "name": "python3" 136 | }, 137 | "language_info": { 138 | "codemirror_mode": { 139 | "name": "ipython", 140 | "version": 3 141 | }, 142 | "file_extension": ".py", 143 | "mimetype": "text/x-python", 144 | "name": "python", 145 | "nbconvert_exporter": "python", 146 | "pygments_lexer": "ipython3", 147 | "version": "3.8.8" 148 | }, 149 | "toc": { 150 | "base_numbering": 1, 151 | "nav_menu": {}, 152 | "number_sections": true, 153 | "sideBar": true, 154 | "skip_h1_title": false, 155 | "title_cell": "Table of Contents", 156 | "title_sidebar": "Contents", 157 | "toc_cell": false, 158 | "toc_position": {}, 159 | "toc_section_display": true, 160 | "toc_window_display": false 161 | }, 162 | "varInspector": { 163 | "cols": { 164 | "lenName": 16, 165 | "lenType": 16, 166 | "lenVar": 40 167 | }, 168 | "kernels_config": { 169 | "python": { 170 | "delete_cmd_postfix": "", 171 | "delete_cmd_prefix": "del ", 172 | "library": "var_list.py", 173 | "varRefreshCmd": "print(var_dic_list())" 174 | }, 175 | "r": { 176 | "delete_cmd_postfix": ") ", 177 | "delete_cmd_prefix": "rm(", 178 | "library": "var_list.r", 179 | "varRefreshCmd": "cat(var_dic_list()) " 180 | } 181 | }, 182 | "types_to_exclude": [ 183 | "module", 184 | "function", 185 | "builtin_function_or_method", 186 | "instance", 187 | "_Feature" 188 | ], 189 | "window_display": false 190 | } 191 | }, 192 | "nbformat": 4, 193 | "nbformat_minor": 2 194 | } 195 | -------------------------------------------------------------------------------- /006_Python_Sets_Methods/005_Python_Set_difference().ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\n", 8 | "All the IPython Notebooks in this lecture series by Dr. Milan Parmar are available @ **[GitHub](https://github.com/milaan9/02_Python_Datatypes/tree/main/006_Python_Sets_Methods)**\n", 9 | "" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "# Python Set `difference()`\n", 17 | "\n", 18 | "The **`difference()`** method returns the set difference of two sets." 19 | ] 20 | }, 21 | { 22 | "cell_type": "markdown", 23 | "metadata": {}, 24 | "source": [ 25 | "If **`A`** and **`B`** are two sets. The set difference of **`A`** and **`B`** is a set of elements that exists only in set **`A`** but not in **`B`**.\n", 26 | "\n", 27 | "```python\n", 28 | "If A = {1, 2, 3, 4}\n", 29 | "B = {2, 3, 9}\n", 30 | "\n", 31 | "Then,\n", 32 | "A - B = {1, 4}\n", 33 | "B - A = {9}\n", 34 | "```\n", 35 | "\n", 36 | "
\n", 37 | "\n", 38 | "
" 39 | ] 40 | }, 41 | { 42 | "cell_type": "markdown", 43 | "metadata": {}, 44 | "source": [ 45 | "**Syntax**:\n", 46 | "\n", 47 | "```python\n", 48 | "A.difference(B)\n", 49 | "```\n", 50 | "\n", 51 | "Here, **`A`** and **`B`** are two sets. The following syntax is equivalent to **`A-B`**." 52 | ] 53 | }, 54 | { 55 | "cell_type": "markdown", 56 | "metadata": {}, 57 | "source": [ 58 | "## Return Value from `difference()`\n", 59 | "\n", 60 | "The **`difference()`** method returns the difference between two sets which is also a set. It doesn't modify original sets." 61 | ] 62 | }, 63 | { 64 | "cell_type": "code", 65 | "execution_count": 1, 66 | "metadata": { 67 | "ExecuteTime": { 68 | "end_time": "2021-06-10T17:21:03.029399Z", 69 | "start_time": "2021-06-10T17:21:03.014792Z" 70 | } 71 | }, 72 | "outputs": [ 73 | { 74 | "name": "stdout", 75 | "output_type": "stream", 76 | "text": [ 77 | "{'b', 'a', 'd'}\n", 78 | "{'f', 'g'}\n" 79 | ] 80 | } 81 | ], 82 | "source": [ 83 | "# Example 1: How difference() works in Python?\n", 84 | "\n", 85 | "A = {'a', 'b', 'c', 'd'}\n", 86 | "B = {'c', 'f', 'g'}\n", 87 | "\n", 88 | "# Equivalent to A-B\n", 89 | "print(A.difference(B))\n", 90 | "\n", 91 | "# Equivalent to B-A\n", 92 | "print(B.difference(A))" 93 | ] 94 | }, 95 | { 96 | "cell_type": "markdown", 97 | "metadata": {}, 98 | "source": [ 99 | "You can also find the set difference using **`-`** operator in Python." 100 | ] 101 | }, 102 | { 103 | "cell_type": "code", 104 | "execution_count": 2, 105 | "metadata": { 106 | "ExecuteTime": { 107 | "end_time": "2021-06-10T17:21:04.685870Z", 108 | "start_time": "2021-06-10T17:21:04.666397Z" 109 | } 110 | }, 111 | "outputs": [ 112 | { 113 | "name": "stdout", 114 | "output_type": "stream", 115 | "text": [ 116 | "{'b', 'a', 'd'}\n", 117 | "{'f', 'g'}\n" 118 | ] 119 | } 120 | ], 121 | "source": [ 122 | "# Example 2: Set Difference Using - Operator.\n", 123 | "\n", 124 | "A = {'a', 'b', 'c', 'd'}\n", 125 | "B = {'c', 'f', 'g'}\n", 126 | "\n", 127 | "print(A-B)\n", 128 | "\n", 129 | "print(B-A)" 130 | ] 131 | }, 132 | { 133 | "cell_type": "code", 134 | "execution_count": null, 135 | "metadata": {}, 136 | "outputs": [], 137 | "source": [] 138 | } 139 | ], 140 | "metadata": { 141 | "hide_input": false, 142 | "kernelspec": { 143 | "display_name": "Python 3", 144 | "language": "python", 145 | "name": "python3" 146 | }, 147 | "language_info": { 148 | "codemirror_mode": { 149 | "name": "ipython", 150 | "version": 3 151 | }, 152 | "file_extension": ".py", 153 | "mimetype": "text/x-python", 154 | "name": "python", 155 | "nbconvert_exporter": "python", 156 | "pygments_lexer": "ipython3", 157 | "version": "3.8.8" 158 | }, 159 | "toc": { 160 | "base_numbering": 1, 161 | "nav_menu": {}, 162 | "number_sections": true, 163 | "sideBar": true, 164 | "skip_h1_title": false, 165 | "title_cell": "Table of Contents", 166 | "title_sidebar": "Contents", 167 | "toc_cell": false, 168 | "toc_position": {}, 169 | "toc_section_display": true, 170 | "toc_window_display": false 171 | }, 172 | "varInspector": { 173 | "cols": { 174 | "lenName": 16, 175 | "lenType": 16, 176 | "lenVar": 40 177 | }, 178 | "kernels_config": { 179 | "python": { 180 | "delete_cmd_postfix": "", 181 | "delete_cmd_prefix": "del ", 182 | "library": "var_list.py", 183 | "varRefreshCmd": "print(var_dic_list())" 184 | }, 185 | "r": { 186 | "delete_cmd_postfix": ") ", 187 | "delete_cmd_prefix": "rm(", 188 | "library": "var_list.r", 189 | "varRefreshCmd": "cat(var_dic_list()) " 190 | } 191 | }, 192 | "types_to_exclude": [ 193 | "module", 194 | "function", 195 | "builtin_function_or_method", 196 | "instance", 197 | "_Feature" 198 | ], 199 | "window_display": false 200 | } 201 | }, 202 | "nbformat": 4, 203 | "nbformat_minor": 2 204 | } 205 | -------------------------------------------------------------------------------- /005_Python_Dictionary_Methods/005_Python_Dictionary_items().ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\n", 8 | "All the IPython Notebooks in this lecture series by Dr. Milan Parmar are available @ **[GitHub](https://github.com/milaan9/02_Python_Datatypes/tree/main/005_Python_Dictionary_Methods)**\n", 9 | "" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "# Python Dictionary `items()`\n", 17 | "\n", 18 | "The **`items()`** method returns a view object that displays a list of dictionary's (key, value) tuple pairs.\n", 19 | "\n", 20 | "**Syntax**:\n", 21 | "\n", 22 | "```python\n", 23 | "dictionary.items() \n", 24 | "```\n", 25 | "\n", 26 | ">**Note:** **`items()`** method is similar to dictionary's **`viewitems()`** method in Python 2.7." 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "metadata": {}, 32 | "source": [ 33 | "## `items()` Parameters\n", 34 | "\n", 35 | "The **`items()`** method doesn't take any parameters." 36 | ] 37 | }, 38 | { 39 | "cell_type": "markdown", 40 | "metadata": {}, 41 | "source": [ 42 | "## Return Value from `items()`\n", 43 | "\n", 44 | "The **`items()`** method returns a view object that displays a list of a given dictionary's (key, value) tuple pair." 45 | ] 46 | }, 47 | { 48 | "cell_type": "code", 49 | "execution_count": 1, 50 | "metadata": { 51 | "ExecuteTime": { 52 | "end_time": "2021-06-09T18:11:54.690016Z", 53 | "start_time": "2021-06-09T18:11:54.678327Z" 54 | } 55 | }, 56 | "outputs": [ 57 | { 58 | "name": "stdout", 59 | "output_type": "stream", 60 | "text": [ 61 | "dict_items([('apple', 2), ('orange', 3), ('grapes', 4)])\n" 62 | ] 63 | } 64 | ], 65 | "source": [ 66 | "# Example 1: Get all items of a dictionary with items()\n", 67 | "\n", 68 | "# random sales dictionary\n", 69 | "sales = { 'apple': 2, 'orange': 3, 'grapes': 4 }\n", 70 | "\n", 71 | "print(sales.items())" 72 | ] 73 | }, 74 | { 75 | "cell_type": "code", 76 | "execution_count": 2, 77 | "metadata": { 78 | "ExecuteTime": { 79 | "end_time": "2021-06-09T18:11:55.547468Z", 80 | "start_time": "2021-06-09T18:11:55.538701Z" 81 | } 82 | }, 83 | "outputs": [ 84 | { 85 | "name": "stdout", 86 | "output_type": "stream", 87 | "text": [ 88 | "Original items: dict_items([('apple', 2), ('orange', 3), ('grapes', 4)])\n", 89 | "Updated items: dict_items([('orange', 3), ('grapes', 4)])\n" 90 | ] 91 | } 92 | ], 93 | "source": [ 94 | "# Example 2: How items() works when a dictionary is modified?\n", 95 | "\n", 96 | "# random sales dictionary\n", 97 | "sales = { 'apple': 2, 'orange': 3, 'grapes': 4 }\n", 98 | "\n", 99 | "items = sales.items()\n", 100 | "print('Original items:', items)\n", 101 | "\n", 102 | "# delete an item from dictionary\n", 103 | "del[sales['apple']]\n", 104 | "print('Updated items:', items)" 105 | ] 106 | }, 107 | { 108 | "cell_type": "markdown", 109 | "metadata": {}, 110 | "source": [ 111 | "**Note:** The view object **`items`** doesn't itself return a list of sales items but it returns a view of **`sales`**'s (key, value) pair.\n", 112 | "\n", 113 | "If the list is updated at any time, the changes are reflected on the view object itself, as shown in the above program." 114 | ] 115 | }, 116 | { 117 | "cell_type": "code", 118 | "execution_count": null, 119 | "metadata": {}, 120 | "outputs": [], 121 | "source": [] 122 | } 123 | ], 124 | "metadata": { 125 | "hide_input": false, 126 | "kernelspec": { 127 | "display_name": "Python 3", 128 | "language": "python", 129 | "name": "python3" 130 | }, 131 | "language_info": { 132 | "codemirror_mode": { 133 | "name": "ipython", 134 | "version": 3 135 | }, 136 | "file_extension": ".py", 137 | "mimetype": "text/x-python", 138 | "name": "python", 139 | "nbconvert_exporter": "python", 140 | "pygments_lexer": "ipython3", 141 | "version": "3.8.8" 142 | }, 143 | "toc": { 144 | "base_numbering": 1, 145 | "nav_menu": {}, 146 | "number_sections": true, 147 | "sideBar": true, 148 | "skip_h1_title": false, 149 | "title_cell": "Table of Contents", 150 | "title_sidebar": "Contents", 151 | "toc_cell": false, 152 | "toc_position": {}, 153 | "toc_section_display": true, 154 | "toc_window_display": false 155 | }, 156 | "varInspector": { 157 | "cols": { 158 | "lenName": 16, 159 | "lenType": 16, 160 | "lenVar": 40 161 | }, 162 | "kernels_config": { 163 | "python": { 164 | "delete_cmd_postfix": "", 165 | "delete_cmd_prefix": "del ", 166 | "library": "var_list.py", 167 | "varRefreshCmd": "print(var_dic_list())" 168 | }, 169 | "r": { 170 | "delete_cmd_postfix": ") ", 171 | "delete_cmd_prefix": "rm(", 172 | "library": "var_list.r", 173 | "varRefreshCmd": "cat(var_dic_list()) " 174 | } 175 | }, 176 | "types_to_exclude": [ 177 | "module", 178 | "function", 179 | "builtin_function_or_method", 180 | "instance", 181 | "_Feature" 182 | ], 183 | "window_display": false 184 | } 185 | }, 186 | "nbformat": 4, 187 | "nbformat_minor": 2 188 | } 189 | -------------------------------------------------------------------------------- /006_Python_Sets_Methods/003_Python_Set_copy().ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\n", 8 | "All the IPython Notebooks in this lecture series by Dr. Milan Parmar are available @ **[GitHub](https://github.com/milaan9/02_Python_Datatypes/tree/main/006_Python_Sets_Methods)**\n", 9 | "" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "# Python Set `copy()`\n", 17 | "\n", 18 | "The **`copy()`** method adds a given element to a set. If the element is already present, it doesn't add any element." 19 | ] 20 | }, 21 | { 22 | "cell_type": "markdown", 23 | "metadata": {}, 24 | "source": [ 25 | "A **[set](https://github.com/milaan9/02_Python_Datatypes/blob/main/006_Python_Sets.ipynb)** can be copied using = operator in Python. For example:\n", 26 | "```python\n", 27 | "numbers = {1, 2, 3, 4}\n", 28 | "new_numbers = numbers\n", 29 | "```\n", 30 | "\n", 31 | "The problem with copying the set in this way is that if you modify the **`numbers`** set, the **`new_numbers`** set is also modified." 32 | ] 33 | }, 34 | { 35 | "cell_type": "code", 36 | "execution_count": 1, 37 | "metadata": { 38 | "ExecuteTime": { 39 | "end_time": "2021-06-10T17:20:20.124191Z", 40 | "start_time": "2021-06-10T17:20:20.101796Z" 41 | }, 42 | "scrolled": true 43 | }, 44 | "outputs": [ 45 | { 46 | "name": "stdout", 47 | "output_type": "stream", 48 | "text": [ 49 | "numbers: {1, 2, 3, 4, 5}\n", 50 | "new_numbers: {1, 2, 3, 4, 5}\n" 51 | ] 52 | } 53 | ], 54 | "source": [ 55 | "# Example:\n", 56 | "\n", 57 | "numbers = {1, 2, 3, 4}\n", 58 | "new_numbers = numbers\n", 59 | "\n", 60 | "new_numbers.add(5)\n", 61 | "\n", 62 | "print('numbers: ', numbers)\n", 63 | "print('new_numbers: ', new_numbers)" 64 | ] 65 | }, 66 | { 67 | "cell_type": "markdown", 68 | "metadata": {}, 69 | "source": [ 70 | "However, if you need the original set to be unchanged when the new set is modified, you can use the **`copy()`** method.\n", 71 | "\n", 72 | "**Syntax**:\n", 73 | "\n", 74 | "```python\n", 75 | "set.copy()\n", 76 | "```" 77 | ] 78 | }, 79 | { 80 | "cell_type": "markdown", 81 | "metadata": {}, 82 | "source": [ 83 | "## `copy()` Parameters\n", 84 | "\n", 85 | "The **`copy()`** method doesn't take any parameters." 86 | ] 87 | }, 88 | { 89 | "cell_type": "markdown", 90 | "metadata": {}, 91 | "source": [ 92 | "## Return Value from `copy()`\n", 93 | "\n", 94 | "The **`copy()`** method returns a shallow copy of the set." 95 | ] 96 | }, 97 | { 98 | "cell_type": "code", 99 | "execution_count": 2, 100 | "metadata": { 101 | "ExecuteTime": { 102 | "end_time": "2021-06-10T17:20:23.655280Z", 103 | "start_time": "2021-06-10T17:20:23.644568Z" 104 | } 105 | }, 106 | "outputs": [ 107 | { 108 | "name": "stdout", 109 | "output_type": "stream", 110 | "text": [ 111 | "numbers: {1, 2, 3, 4}\n", 112 | "new_numbers: {1, 2, 3, 4, 5}\n" 113 | ] 114 | } 115 | ], 116 | "source": [ 117 | "# Example 1: How the copy() method works for sets?\n", 118 | "\n", 119 | "numbers = {1, 2, 3, 4}\n", 120 | "new_numbers = numbers.copy()\n", 121 | "\n", 122 | "new_numbers.add(5)\n", 123 | "\n", 124 | "print('numbers: ', numbers)\n", 125 | "print('new_numbers: ', new_numbers)" 126 | ] 127 | }, 128 | { 129 | "cell_type": "code", 130 | "execution_count": null, 131 | "metadata": {}, 132 | "outputs": [], 133 | "source": [] 134 | } 135 | ], 136 | "metadata": { 137 | "hide_input": false, 138 | "kernelspec": { 139 | "display_name": "Python 3", 140 | "language": "python", 141 | "name": "python3" 142 | }, 143 | "language_info": { 144 | "codemirror_mode": { 145 | "name": "ipython", 146 | "version": 3 147 | }, 148 | "file_extension": ".py", 149 | "mimetype": "text/x-python", 150 | "name": "python", 151 | "nbconvert_exporter": "python", 152 | "pygments_lexer": "ipython3", 153 | "version": "3.8.8" 154 | }, 155 | "toc": { 156 | "base_numbering": 1, 157 | "nav_menu": {}, 158 | "number_sections": true, 159 | "sideBar": true, 160 | "skip_h1_title": false, 161 | "title_cell": "Table of Contents", 162 | "title_sidebar": "Contents", 163 | "toc_cell": false, 164 | "toc_position": {}, 165 | "toc_section_display": true, 166 | "toc_window_display": false 167 | }, 168 | "varInspector": { 169 | "cols": { 170 | "lenName": 16, 171 | "lenType": 16, 172 | "lenVar": 40 173 | }, 174 | "kernels_config": { 175 | "python": { 176 | "delete_cmd_postfix": "", 177 | "delete_cmd_prefix": "del ", 178 | "library": "var_list.py", 179 | "varRefreshCmd": "print(var_dic_list())" 180 | }, 181 | "r": { 182 | "delete_cmd_postfix": ") ", 183 | "delete_cmd_prefix": "rm(", 184 | "library": "var_list.r", 185 | "varRefreshCmd": "cat(var_dic_list()) " 186 | } 187 | }, 188 | "types_to_exclude": [ 189 | "module", 190 | "function", 191 | "builtin_function_or_method", 192 | "instance", 193 | "_Feature" 194 | ], 195 | "window_display": false 196 | } 197 | }, 198 | "nbformat": 4, 199 | "nbformat_minor": 2 200 | } 201 | -------------------------------------------------------------------------------- /006_Python_Sets_Methods/007_Python_Set_discard().ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\n", 8 | "All the IPython Notebooks in this lecture series by Dr. Milan Parmar are available @ **[GitHub](https://github.com/milaan9/02_Python_Datatypes/tree/main/006_Python_Sets_Methods)**\n", 9 | "" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "# Python Set `discard()`\n", 17 | "\n", 18 | "The **`discard()`** method removes a specified element from the set (if present).\n", 19 | "\n", 20 | "**Syntax**:\n", 21 | "\n", 22 | "```python\n", 23 | "s.discard(x)\n", 24 | "```" 25 | ] 26 | }, 27 | { 28 | "cell_type": "markdown", 29 | "metadata": {}, 30 | "source": [ 31 | "## `discard()` Parameters\n", 32 | "\n", 33 | "The **`discard()`** method takes a single element **`x`** and removes it from the set (if present)." 34 | ] 35 | }, 36 | { 37 | "cell_type": "markdown", 38 | "metadata": {}, 39 | "source": [ 40 | "## Return Value from `discard()`\n", 41 | "\n", 42 | "The **`discard()`** removes element **`x`** from the set if the element is present.\n", 43 | "\n", 44 | "This method returns **`None`** (meaning, absence of a return value)." 45 | ] 46 | }, 47 | { 48 | "cell_type": "code", 49 | "execution_count": 1, 50 | "metadata": { 51 | "ExecuteTime": { 52 | "end_time": "2021-06-10T17:43:41.219959Z", 53 | "start_time": "2021-06-10T17:43:41.212171Z" 54 | } 55 | }, 56 | "outputs": [ 57 | { 58 | "name": "stdout", 59 | "output_type": "stream", 60 | "text": [ 61 | "numbers = {2, 4, 5}\n", 62 | "numbers = {2, 4, 5}\n" 63 | ] 64 | } 65 | ], 66 | "source": [ 67 | "# Example 1: How discard() works?\n", 68 | "\n", 69 | "numbers = {2, 3, 4, 5}\n", 70 | "\n", 71 | "numbers.discard(3)\n", 72 | "print('numbers = ', numbers)\n", 73 | "\n", 74 | "numbers.discard(10)\n", 75 | "print('numbers = ', numbers)" 76 | ] 77 | }, 78 | { 79 | "cell_type": "code", 80 | "execution_count": 2, 81 | "metadata": { 82 | "ExecuteTime": { 83 | "end_time": "2021-06-10T17:43:41.688856Z", 84 | "start_time": "2021-06-10T17:43:41.669378Z" 85 | } 86 | }, 87 | "outputs": [ 88 | { 89 | "name": "stdout", 90 | "output_type": "stream", 91 | "text": [ 92 | "None\n", 93 | "numbers = {2, 4, 5}\n" 94 | ] 95 | } 96 | ], 97 | "source": [ 98 | "# Example 2: How discard() works?\n", 99 | "\n", 100 | "numbers = {2, 3, 5, 4}\n", 101 | "\n", 102 | "# Returns None\n", 103 | "# Meaning, absence of a return value \n", 104 | "print(numbers.discard(3))\n", 105 | "\n", 106 | "print('numbers =', numbers)" 107 | ] 108 | }, 109 | { 110 | "cell_type": "code", 111 | "execution_count": 3, 112 | "metadata": { 113 | "ExecuteTime": { 114 | "end_time": "2021-06-10T17:43:42.126101Z", 115 | "start_time": "2021-06-10T17:43:42.115389Z" 116 | } 117 | }, 118 | "outputs": [ 119 | { 120 | "name": "stdout", 121 | "output_type": "stream", 122 | "text": [ 123 | "{'course', 'Python', 'Welcome', 'to'}\n" 124 | ] 125 | } 126 | ], 127 | "source": [ 128 | "# Example 3: How discard() works?\n", 129 | "\n", 130 | "set1 = {\"Welcome\", \"to\", \"Python\", \"course\"}\n", 131 | "set1.discard(20) # 20 is not an element in set1\n", 132 | "print(set1)" 133 | ] 134 | }, 135 | { 136 | "cell_type": "code", 137 | "execution_count": null, 138 | "metadata": {}, 139 | "outputs": [], 140 | "source": [] 141 | } 142 | ], 143 | "metadata": { 144 | "hide_input": false, 145 | "kernelspec": { 146 | "display_name": "Python 3", 147 | "language": "python", 148 | "name": "python3" 149 | }, 150 | "language_info": { 151 | "codemirror_mode": { 152 | "name": "ipython", 153 | "version": 3 154 | }, 155 | "file_extension": ".py", 156 | "mimetype": "text/x-python", 157 | "name": "python", 158 | "nbconvert_exporter": "python", 159 | "pygments_lexer": "ipython3", 160 | "version": "3.8.8" 161 | }, 162 | "toc": { 163 | "base_numbering": 1, 164 | "nav_menu": {}, 165 | "number_sections": true, 166 | "sideBar": true, 167 | "skip_h1_title": false, 168 | "title_cell": "Table of Contents", 169 | "title_sidebar": "Contents", 170 | "toc_cell": false, 171 | "toc_position": {}, 172 | "toc_section_display": true, 173 | "toc_window_display": false 174 | }, 175 | "varInspector": { 176 | "cols": { 177 | "lenName": 16, 178 | "lenType": 16, 179 | "lenVar": 40 180 | }, 181 | "kernels_config": { 182 | "python": { 183 | "delete_cmd_postfix": "", 184 | "delete_cmd_prefix": "del ", 185 | "library": "var_list.py", 186 | "varRefreshCmd": "print(var_dic_list())" 187 | }, 188 | "r": { 189 | "delete_cmd_postfix": ") ", 190 | "delete_cmd_prefix": "rm(", 191 | "library": "var_list.r", 192 | "varRefreshCmd": "cat(var_dic_list()) " 193 | } 194 | }, 195 | "types_to_exclude": [ 196 | "module", 197 | "function", 198 | "builtin_function_or_method", 199 | "instance", 200 | "_Feature" 201 | ], 202 | "window_display": false 203 | } 204 | }, 205 | "nbformat": 4, 206 | "nbformat_minor": 2 207 | } 208 | -------------------------------------------------------------------------------- /002_Python_String_Methods/029_Python_String_rstrip().ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\n", 8 | "All the IPython Notebooks in this lecture series by Dr. Milan Parmar are available @ **[GitHub](https://github.com/milaan9/02_Python_Datatypes/tree/main/002_Python_String_Methods)**\n", 9 | "" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "# Python String `rstrip()`\n", 17 | "\n", 18 | "The string **`rstrip()`** method returns a copy of the string with trailing characters removed (based on the string argument passed).\n", 19 | "\n", 20 | "The **`rstrip()`** removes characters from the right based on the argument (a string specifying the set of characters to be removed).\n", 21 | "\n", 22 | "**Syntax**:\n", 23 | "\n", 24 | "```python\n", 25 | "string.rstrip([chars])\n", 26 | "```" 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "metadata": { 32 | "heading_collapsed": true 33 | }, 34 | "source": [ 35 | "## `rstrip()` Parameters\n", 36 | "\n", 37 | "The **`rstrip()`** method takes one parameter:\n", 38 | "\n", 39 | "* **`chars`** (optional) - a string specifying the set of characters to be removed.\n", 40 | "\n", 41 | "If **`chars`** argument is not provided, all leading whitespaces on the right are removed from the string." 42 | ] 43 | }, 44 | { 45 | "cell_type": "markdown", 46 | "metadata": {}, 47 | "source": [ 48 | "## Return Value from `rstrip()`\n", 49 | "\n", 50 | "The **`rstrip()`** method returns a copy of the string with trailing characters stripped.\n", 51 | "\n", 52 | "All combinations of characters in **`chars`** argument are removed from the right of the string until first mismatch." 53 | ] 54 | }, 55 | { 56 | "cell_type": "code", 57 | "execution_count": 1, 58 | "metadata": { 59 | "ExecuteTime": { 60 | "end_time": "2021-06-23T09:45:31.749724Z", 61 | "start_time": "2021-06-23T09:45:31.739960Z" 62 | }, 63 | "scrolled": true 64 | }, 65 | "outputs": [ 66 | { 67 | "name": "stdout", 68 | "output_type": "stream", 69 | "text": [ 70 | "this is good\n", 71 | "this is good\n", 72 | "this is g\n", 73 | "www.github.co\n" 74 | ] 75 | } 76 | ], 77 | "source": [ 78 | "# Example 1: Working of rstrip()\n", 79 | "\n", 80 | "random_string = 'this is good '\n", 81 | "\n", 82 | "# Trailing whitepsace are removed\n", 83 | "print(random_string.rstrip())\n", 84 | "\n", 85 | "# Argument doesn't contain 'd'\n", 86 | "# No characters are removed.\n", 87 | "print(random_string.rstrip('si oo'))\n", 88 | "\n", 89 | "print(random_string.rstrip('sid oo'))\n", 90 | "\n", 91 | "website = 'www.github.com/'\n", 92 | "print(website.rstrip('m/.'))" 93 | ] 94 | }, 95 | { 96 | "cell_type": "code", 97 | "execution_count": 2, 98 | "metadata": { 99 | "ExecuteTime": { 100 | "end_time": "2021-06-23T09:45:46.885849Z", 101 | "start_time": "2021-06-23T09:45:46.867297Z" 102 | } 103 | }, 104 | "outputs": [ 105 | { 106 | "name": "stdout", 107 | "output_type": "stream", 108 | "text": [ 109 | " I Love Python Tutorial\n", 110 | "###HelloWorld\n" 111 | ] 112 | } 113 | ], 114 | "source": [ 115 | "# Example 2:\n", 116 | "\n", 117 | "s1=' I Love Python Tutorial '\n", 118 | "print(s1.rstrip())\n", 119 | "\n", 120 | "s2='###HelloWorld###'\n", 121 | "print(s2.rstrip('#'))" 122 | ] 123 | }, 124 | { 125 | "cell_type": "code", 126 | "execution_count": null, 127 | "metadata": {}, 128 | "outputs": [], 129 | "source": [] 130 | } 131 | ], 132 | "metadata": { 133 | "hide_input": false, 134 | "kernelspec": { 135 | "display_name": "Python 3", 136 | "language": "python", 137 | "name": "python3" 138 | }, 139 | "language_info": { 140 | "codemirror_mode": { 141 | "name": "ipython", 142 | "version": 3 143 | }, 144 | "file_extension": ".py", 145 | "mimetype": "text/x-python", 146 | "name": "python", 147 | "nbconvert_exporter": "python", 148 | "pygments_lexer": "ipython3", 149 | "version": "3.8.8" 150 | }, 151 | "toc": { 152 | "base_numbering": 1, 153 | "nav_menu": {}, 154 | "number_sections": true, 155 | "sideBar": true, 156 | "skip_h1_title": false, 157 | "title_cell": "Table of Contents", 158 | "title_sidebar": "Contents", 159 | "toc_cell": false, 160 | "toc_position": {}, 161 | "toc_section_display": true, 162 | "toc_window_display": false 163 | }, 164 | "varInspector": { 165 | "cols": { 166 | "lenName": 16, 167 | "lenType": 16, 168 | "lenVar": 40 169 | }, 170 | "kernels_config": { 171 | "python": { 172 | "delete_cmd_postfix": "", 173 | "delete_cmd_prefix": "del ", 174 | "library": "var_list.py", 175 | "varRefreshCmd": "print(var_dic_list())" 176 | }, 177 | "r": { 178 | "delete_cmd_postfix": ") ", 179 | "delete_cmd_prefix": "rm(", 180 | "library": "var_list.r", 181 | "varRefreshCmd": "cat(var_dic_list()) " 182 | } 183 | }, 184 | "types_to_exclude": [ 185 | "module", 186 | "function", 187 | "builtin_function_or_method", 188 | "instance", 189 | "_Feature" 190 | ], 191 | "window_display": false 192 | } 193 | }, 194 | "nbformat": 4, 195 | "nbformat_minor": 2 196 | } 197 | -------------------------------------------------------------------------------- /003_Python_List_Methods/002_Python_List_append().ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\n", 8 | "All the IPython Notebooks in this lecture series by Dr. Milan Parmar are available @ **[GitHub](https://github.com/milaan9/02_Python_Datatypes/tree/main/003_Python_List_Methods)**\n", 9 | "" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "# Python List `append()`\n", 17 | "\n", 18 | "The **`append()`** method adds an item to the end of the list.\n", 19 | "\n", 20 | "**Syntax**:\n", 21 | "\n", 22 | "```python\n", 23 | "list.append(item)\n", 24 | "```" 25 | ] 26 | }, 27 | { 28 | "cell_type": "markdown", 29 | "metadata": {}, 30 | "source": [ 31 | "## `append()` Parameters\n", 32 | "\n", 33 | "The **`append()`** method takes a single argument\n", 34 | "\n", 35 | "* **item** - an item to be added at the end of the list\n", 36 | "\n", 37 | "The item can be numbers, strings, dictionaries, another list, and so on." 38 | ] 39 | }, 40 | { 41 | "cell_type": "markdown", 42 | "metadata": {}, 43 | "source": [ 44 | "## Return Value from `append()`\n", 45 | "\n", 46 | "The **`append()`** method doesn't return any value (returns **`None`**)." 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "execution_count": 1, 52 | "metadata": { 53 | "ExecuteTime": { 54 | "end_time": "2021-06-10T17:55:03.242901Z", 55 | "start_time": "2021-06-10T17:55:03.234133Z" 56 | } 57 | }, 58 | "outputs": [ 59 | { 60 | "name": "stdout", 61 | "output_type": "stream", 62 | "text": [ 63 | "Updated animals list: ['cat', 'dog', 'rabbit', 'guinea pig']\n" 64 | ] 65 | } 66 | ], 67 | "source": [ 68 | "# Example 1: Adding Element to a List\n", 69 | "\n", 70 | "# animals list\n", 71 | "animals = ['cat', 'dog', 'rabbit']\n", 72 | "\n", 73 | "# 'guinea pig' is appended to the animals list\n", 74 | "animals.append('guinea pig')\n", 75 | "\n", 76 | "# Updated animals list\n", 77 | "print('Updated animals list: ', animals)" 78 | ] 79 | }, 80 | { 81 | "cell_type": "code", 82 | "execution_count": 2, 83 | "metadata": { 84 | "ExecuteTime": { 85 | "end_time": "2021-06-10T17:55:04.117879Z", 86 | "start_time": "2021-06-10T17:55:04.111061Z" 87 | } 88 | }, 89 | "outputs": [ 90 | { 91 | "name": "stdout", 92 | "output_type": "stream", 93 | "text": [ 94 | "Updated animals list: ['cat', 'dog', 'rabbit', ['tiger', 'fox']]\n" 95 | ] 96 | } 97 | ], 98 | "source": [ 99 | "# Example 2: Adding List to a List\n", 100 | "\n", 101 | "# animals list\n", 102 | "animals = ['cat', 'dog', 'rabbit']\n", 103 | "\n", 104 | "# list of wild animals\n", 105 | "wild_animals = ['tiger', 'fox']\n", 106 | "\n", 107 | "# appending wild_animals list to the animals list\n", 108 | "animals.append(wild_animals)\n", 109 | "\n", 110 | "print('Updated animals list: ', animals)" 111 | ] 112 | }, 113 | { 114 | "cell_type": "markdown", 115 | "metadata": {}, 116 | "source": [ 117 | "It is important to notice that, a single item (**`wild_animals`** list) is added to the **`animals`** list in the above program.\n", 118 | "\n", 119 | "If you need to add items of a list to another list (rather than the list itself), use the **[list extend() method](https://github.com/milaan9/02_Python_Datatypes/blob/main/003_Python_List_Methods/003_Python_List_extend%28%29.ipynb)**." 120 | ] 121 | }, 122 | { 123 | "cell_type": "code", 124 | "execution_count": null, 125 | "metadata": {}, 126 | "outputs": [], 127 | "source": [] 128 | } 129 | ], 130 | "metadata": { 131 | "hide_input": false, 132 | "kernelspec": { 133 | "display_name": "Python 3", 134 | "language": "python", 135 | "name": "python3" 136 | }, 137 | "language_info": { 138 | "codemirror_mode": { 139 | "name": "ipython", 140 | "version": 3 141 | }, 142 | "file_extension": ".py", 143 | "mimetype": "text/x-python", 144 | "name": "python", 145 | "nbconvert_exporter": "python", 146 | "pygments_lexer": "ipython3", 147 | "version": "3.8.8" 148 | }, 149 | "toc": { 150 | "base_numbering": 1, 151 | "nav_menu": {}, 152 | "number_sections": true, 153 | "sideBar": true, 154 | "skip_h1_title": false, 155 | "title_cell": "Table of Contents", 156 | "title_sidebar": "Contents", 157 | "toc_cell": false, 158 | "toc_position": {}, 159 | "toc_section_display": true, 160 | "toc_window_display": false 161 | }, 162 | "varInspector": { 163 | "cols": { 164 | "lenName": 16, 165 | "lenType": 16, 166 | "lenVar": 40 167 | }, 168 | "kernels_config": { 169 | "python": { 170 | "delete_cmd_postfix": "", 171 | "delete_cmd_prefix": "del ", 172 | "library": "var_list.py", 173 | "varRefreshCmd": "print(var_dic_list())" 174 | }, 175 | "r": { 176 | "delete_cmd_postfix": ") ", 177 | "delete_cmd_prefix": "rm(", 178 | "library": "var_list.r", 179 | "varRefreshCmd": "cat(var_dic_list()) " 180 | } 181 | }, 182 | "types_to_exclude": [ 183 | "module", 184 | "function", 185 | "builtin_function_or_method", 186 | "instance", 187 | "_Feature" 188 | ], 189 | "window_display": false 190 | } 191 | }, 192 | "nbformat": 4, 193 | "nbformat_minor": 2 194 | } 195 | -------------------------------------------------------------------------------- /002_Python_String_Methods/028_Python_String_lstrip().ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\n", 8 | "All the IPython Notebooks in this lecture series by Dr. Milan Parmar are available @ **[GitHub](https://github.com/milaan9/02_Python_Datatypes/tree/main/002_Python_String_Methods)**\n", 9 | "" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "# Python String `lstrip()`\n", 17 | "\n", 18 | "The string **`lstrip()`** method returns a copy of the string with leading characters removed (based on the string argument passed).\n", 19 | "\n", 20 | "The **`lstrip()`** removes characters from the left based on the argument (a string specifying the set of characters to be removed).\n", 21 | "\n", 22 | "**Syntax**:\n", 23 | "\n", 24 | "```python\n", 25 | "string.lstrip([chars])\n", 26 | "```" 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "metadata": { 32 | "heading_collapsed": true 33 | }, 34 | "source": [ 35 | "## `lstrip()` Parameters\n", 36 | "\n", 37 | "The **`lstrip()`** method takes one parameter:\n", 38 | "\n", 39 | "* **`chars`** (optional) - a string specifying the set of characters to be removed.\n", 40 | "\n", 41 | "If **`chars`** argument is not provided, all leading whitespaces are removed from the string." 42 | ] 43 | }, 44 | { 45 | "cell_type": "markdown", 46 | "metadata": {}, 47 | "source": [ 48 | "## Return Value from `lstrip()`\n", 49 | "\n", 50 | "The **`lstrip()`** method returns a copy of the string with leading characters stripped.\n", 51 | "\n", 52 | "All combinations of characters in the **`chars`** argument are removed from the left of the string until the first mismatch." 53 | ] 54 | }, 55 | { 56 | "cell_type": "code", 57 | "execution_count": 1, 58 | "metadata": { 59 | "ExecuteTime": { 60 | "end_time": "2021-06-23T09:44:18.124262Z", 61 | "start_time": "2021-06-23T09:44:18.105710Z" 62 | }, 63 | "scrolled": true 64 | }, 65 | "outputs": [ 66 | { 67 | "name": "stdout", 68 | "output_type": "stream", 69 | "text": [ 70 | "this is good \n", 71 | " this is good \n", 72 | "his is good \n", 73 | "www.github.com/\n" 74 | ] 75 | } 76 | ], 77 | "source": [ 78 | "# Example 1: Working of lstrip()\n", 79 | "\n", 80 | "random_string = ' this is good '\n", 81 | "\n", 82 | "# Leading whitepsace are removed\n", 83 | "print(random_string.lstrip())\n", 84 | "\n", 85 | "# Argument doesn't contain space\n", 86 | "# No characters are removed.\n", 87 | "print(random_string.lstrip('sti'))\n", 88 | "\n", 89 | "print(random_string.lstrip('s ti'))\n", 90 | "\n", 91 | "website = 'https://www.github.com/' \n", 92 | "print(website.lstrip('htps:/.'))" 93 | ] 94 | }, 95 | { 96 | "cell_type": "code", 97 | "execution_count": 2, 98 | "metadata": { 99 | "ExecuteTime": { 100 | "end_time": "2021-06-23T09:44:36.855572Z", 101 | "start_time": "2021-06-23T09:44:36.838485Z" 102 | } 103 | }, 104 | "outputs": [ 105 | { 106 | "name": "stdout", 107 | "output_type": "stream", 108 | "text": [ 109 | "I Love Python Tutorial \n", 110 | "HelloWorld###\n" 111 | ] 112 | } 113 | ], 114 | "source": [ 115 | "# Example 2:\n", 116 | "\n", 117 | "s1=' I Love Python Tutorial '\n", 118 | "print(s1.lstrip())\n", 119 | "\n", 120 | "s2='###HelloWorld###'\n", 121 | "print(s2.lstrip('#'))" 122 | ] 123 | }, 124 | { 125 | "cell_type": "code", 126 | "execution_count": null, 127 | "metadata": {}, 128 | "outputs": [], 129 | "source": [] 130 | } 131 | ], 132 | "metadata": { 133 | "hide_input": false, 134 | "kernelspec": { 135 | "display_name": "Python 3", 136 | "language": "python", 137 | "name": "python3" 138 | }, 139 | "language_info": { 140 | "codemirror_mode": { 141 | "name": "ipython", 142 | "version": 3 143 | }, 144 | "file_extension": ".py", 145 | "mimetype": "text/x-python", 146 | "name": "python", 147 | "nbconvert_exporter": "python", 148 | "pygments_lexer": "ipython3", 149 | "version": "3.8.8" 150 | }, 151 | "toc": { 152 | "base_numbering": 1, 153 | "nav_menu": {}, 154 | "number_sections": true, 155 | "sideBar": true, 156 | "skip_h1_title": false, 157 | "title_cell": "Table of Contents", 158 | "title_sidebar": "Contents", 159 | "toc_cell": false, 160 | "toc_position": {}, 161 | "toc_section_display": true, 162 | "toc_window_display": false 163 | }, 164 | "varInspector": { 165 | "cols": { 166 | "lenName": 16, 167 | "lenType": 16, 168 | "lenVar": 40 169 | }, 170 | "kernels_config": { 171 | "python": { 172 | "delete_cmd_postfix": "", 173 | "delete_cmd_prefix": "del ", 174 | "library": "var_list.py", 175 | "varRefreshCmd": "print(var_dic_list())" 176 | }, 177 | "r": { 178 | "delete_cmd_postfix": ") ", 179 | "delete_cmd_prefix": "rm(", 180 | "library": "var_list.r", 181 | "varRefreshCmd": "cat(var_dic_list()) " 182 | } 183 | }, 184 | "types_to_exclude": [ 185 | "module", 186 | "function", 187 | "builtin_function_or_method", 188 | "instance", 189 | "_Feature" 190 | ], 191 | "window_display": false 192 | } 193 | }, 194 | "nbformat": 4, 195 | "nbformat_minor": 2 196 | } 197 | -------------------------------------------------------------------------------- /002_Python_String_Methods/025_Python_String_lower().ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\n", 8 | "All the IPython Notebooks in this lecture series by Dr. Milan Parmar are available @ **[GitHub](https://github.com/milaan9/02_Python_Datatypes/tree/main/002_Python_String_Methods)**\n", 9 | "" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "# Python String `lower()`\n", 17 | "\n", 18 | "The string **`lower()`** method converts all uppercase characters in a string into lowercase characters and returns it.\n", 19 | "\n", 20 | "**Syntax**:\n", 21 | "\n", 22 | "```python\n", 23 | "string.lower()\n", 24 | "```" 25 | ] 26 | }, 27 | { 28 | "cell_type": "markdown", 29 | "metadata": { 30 | "heading_collapsed": true 31 | }, 32 | "source": [ 33 | "## `lower()` Parameters\n", 34 | "\n", 35 | "The **`lower()`** method doesn't take any parameters." 36 | ] 37 | }, 38 | { 39 | "cell_type": "markdown", 40 | "metadata": {}, 41 | "source": [ 42 | "## Return Value from `lower()`\n", 43 | "\n", 44 | "The **`lower()`** method returns the lowercased string from the given string. It converts all uppercase characters to lowercase.\n", 45 | "\n", 46 | "If no uppercase characters exist, it returns the original string." 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "execution_count": 1, 52 | "metadata": { 53 | "ExecuteTime": { 54 | "end_time": "2021-06-10T18:11:26.177616Z", 55 | "start_time": "2021-06-10T18:11:26.165927Z" 56 | }, 57 | "scrolled": true 58 | }, 59 | "outputs": [ 60 | { 61 | "name": "stdout", 62 | "output_type": "stream", 63 | "text": [ 64 | "this should be lowercase!\n", 65 | "th!s sh0uld b3 l0w3rcas3!\n" 66 | ] 67 | } 68 | ], 69 | "source": [ 70 | "# Example 1: Convert a string to lowercase\n", 71 | "\n", 72 | "# example string\n", 73 | "string = \"THIS SHOULD BE LOWERCASE!\"\n", 74 | "print(string.lower())\n", 75 | "\n", 76 | "# string with numbers\n", 77 | "# all alphabets whould be lowercase\n", 78 | "string = \"Th!s Sh0uLd B3 L0w3rCas3!\"\n", 79 | "print(string.lower())" 80 | ] 81 | }, 82 | { 83 | "cell_type": "code", 84 | "execution_count": 2, 85 | "metadata": { 86 | "ExecuteTime": { 87 | "end_time": "2021-06-10T18:11:26.787226Z", 88 | "start_time": "2021-06-10T18:11:26.770674Z" 89 | } 90 | }, 91 | "outputs": [ 92 | { 93 | "name": "stdout", 94 | "output_type": "stream", 95 | "text": [ 96 | "The strings are same.\n" 97 | ] 98 | } 99 | ], 100 | "source": [ 101 | "# Example 2: How lower() is used in a program?\n", 102 | "\n", 103 | "# first string\n", 104 | "firstString = \"PYTHON IS AWESOME!\"\n", 105 | "\n", 106 | "# second string\n", 107 | "secondString = \"PyThOn Is AwEsOmE!\"\n", 108 | "\n", 109 | "if(firstString.lower() == secondString.lower()):\n", 110 | " print(\"The strings are same.\")\n", 111 | "else:\n", 112 | " print(\"The strings are not same.\")" 113 | ] 114 | }, 115 | { 116 | "cell_type": "markdown", 117 | "metadata": {}, 118 | "source": [ 119 | ">**Note:** Note: If you want to convert to uppercase string, use **[upper()](https://github.com/milaan9/02_Python_Datatypes/blob/main/002_Python_String_Methods/026_Python_String_upper%28%29.ipynb)**. You can also use **[swapcase()](https://github.com/milaan9/02_Python_Datatypes/blob/main/002_Python_String_Methods/027_Python_String_swapcase%28%29.ipynb)** to swap between lowercase to uppercase. " 120 | ] 121 | }, 122 | { 123 | "cell_type": "code", 124 | "execution_count": null, 125 | "metadata": {}, 126 | "outputs": [], 127 | "source": [] 128 | } 129 | ], 130 | "metadata": { 131 | "hide_input": false, 132 | "kernelspec": { 133 | "display_name": "Python 3", 134 | "language": "python", 135 | "name": "python3" 136 | }, 137 | "language_info": { 138 | "codemirror_mode": { 139 | "name": "ipython", 140 | "version": 3 141 | }, 142 | "file_extension": ".py", 143 | "mimetype": "text/x-python", 144 | "name": "python", 145 | "nbconvert_exporter": "python", 146 | "pygments_lexer": "ipython3", 147 | "version": "3.8.8" 148 | }, 149 | "toc": { 150 | "base_numbering": 1, 151 | "nav_menu": {}, 152 | "number_sections": true, 153 | "sideBar": true, 154 | "skip_h1_title": false, 155 | "title_cell": "Table of Contents", 156 | "title_sidebar": "Contents", 157 | "toc_cell": false, 158 | "toc_position": {}, 159 | "toc_section_display": true, 160 | "toc_window_display": false 161 | }, 162 | "varInspector": { 163 | "cols": { 164 | "lenName": 16, 165 | "lenType": 16, 166 | "lenVar": 40 167 | }, 168 | "kernels_config": { 169 | "python": { 170 | "delete_cmd_postfix": "", 171 | "delete_cmd_prefix": "del ", 172 | "library": "var_list.py", 173 | "varRefreshCmd": "print(var_dic_list())" 174 | }, 175 | "r": { 176 | "delete_cmd_postfix": ") ", 177 | "delete_cmd_prefix": "rm(", 178 | "library": "var_list.r", 179 | "varRefreshCmd": "cat(var_dic_list()) " 180 | } 181 | }, 182 | "types_to_exclude": [ 183 | "module", 184 | "function", 185 | "builtin_function_or_method", 186 | "instance", 187 | "_Feature" 188 | ], 189 | "window_display": false 190 | } 191 | }, 192 | "nbformat": 4, 193 | "nbformat_minor": 2 194 | } 195 | -------------------------------------------------------------------------------- /002_Python_String_Methods/026_Python_String_upper().ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\n", 8 | "All the IPython Notebooks in this lecture series by Dr. Milan Parmar are available @ **[GitHub](https://github.com/milaan9/02_Python_Datatypes/tree/main/002_Python_String_Methods)**\n", 9 | "" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "# Python String `upper()`\n", 17 | "\n", 18 | "The string **`upper()`** method converts all lowercase characters in a string into uppercase characters and returns it.\n", 19 | "\n", 20 | "**Syntax**:\n", 21 | "\n", 22 | "```python\n", 23 | "string.upper()\n", 24 | "```" 25 | ] 26 | }, 27 | { 28 | "cell_type": "markdown", 29 | "metadata": { 30 | "heading_collapsed": true 31 | }, 32 | "source": [ 33 | "## `upper()` Parameters\n", 34 | "\n", 35 | "The **`upper()`** method doesn't take any parameters." 36 | ] 37 | }, 38 | { 39 | "cell_type": "markdown", 40 | "metadata": {}, 41 | "source": [ 42 | "## Return Value from `upper()`\n", 43 | "\n", 44 | "The **`upper()`** method returns the uppercased string from the given string. It converts all lowercase characters to uppercase.\n", 45 | "\n", 46 | "If no lowercase characters exist, it returns the original string." 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "execution_count": 1, 52 | "metadata": { 53 | "ExecuteTime": { 54 | "end_time": "2021-06-10T18:12:35.049388Z", 55 | "start_time": "2021-06-10T18:12:35.030884Z" 56 | }, 57 | "scrolled": true 58 | }, 59 | "outputs": [ 60 | { 61 | "name": "stdout", 62 | "output_type": "stream", 63 | "text": [ 64 | "THIS SHOULD BE UPPERCASE!\n", 65 | "TH!S SH0ULD B3 UPP3RCAS3!\n" 66 | ] 67 | } 68 | ], 69 | "source": [ 70 | "# Example 1: Convert a string to uppercase\n", 71 | "\n", 72 | "# example string\n", 73 | "string = \"this should be uppercase!\"\n", 74 | "print(string.upper())\n", 75 | "\n", 76 | "# string with numbers\n", 77 | "# all alphabets whould be lowercase\n", 78 | "string = \"Th!s Sh0uLd B3 uPp3rCas3!\"\n", 79 | "print(string.upper())" 80 | ] 81 | }, 82 | { 83 | "cell_type": "code", 84 | "execution_count": 2, 85 | "metadata": { 86 | "ExecuteTime": { 87 | "end_time": "2021-06-10T18:12:36.049015Z", 88 | "start_time": "2021-06-10T18:12:36.036356Z" 89 | } 90 | }, 91 | "outputs": [ 92 | { 93 | "name": "stdout", 94 | "output_type": "stream", 95 | "text": [ 96 | "The strings are same.\n" 97 | ] 98 | } 99 | ], 100 | "source": [ 101 | "# Example 2: How upper() is used in a program?\n", 102 | "\n", 103 | "# first string\n", 104 | "firstString = \"python is awesome!\"\n", 105 | "\n", 106 | "# second string\n", 107 | "secondString = \"PyThOn Is AwEsOmE!\"\n", 108 | "\n", 109 | "if(firstString.upper() == secondString.upper()):\n", 110 | " print(\"The strings are same.\")\n", 111 | "else:\n", 112 | " print(\"The strings are not same.\")" 113 | ] 114 | }, 115 | { 116 | "cell_type": "markdown", 117 | "metadata": {}, 118 | "source": [ 119 | ">**Note:** Note: If you want to convert to lowercase string, use **[lower()](https://github.com/milaan9/02_Python_Datatypes/blob/main/002_Python_String_Methods/025_Python_String_lower%28%29.ipynb)**. You can also use **[swapcase()](https://github.com/milaan9/02_Python_Datatypes/blob/main/002_Python_String_Methods/027_Python_String_swapcase%28%29.ipynb)** to swap between uppercase to lowercase. " 120 | ] 121 | }, 122 | { 123 | "cell_type": "code", 124 | "execution_count": null, 125 | "metadata": {}, 126 | "outputs": [], 127 | "source": [] 128 | } 129 | ], 130 | "metadata": { 131 | "hide_input": false, 132 | "kernelspec": { 133 | "display_name": "Python 3", 134 | "language": "python", 135 | "name": "python3" 136 | }, 137 | "language_info": { 138 | "codemirror_mode": { 139 | "name": "ipython", 140 | "version": 3 141 | }, 142 | "file_extension": ".py", 143 | "mimetype": "text/x-python", 144 | "name": "python", 145 | "nbconvert_exporter": "python", 146 | "pygments_lexer": "ipython3", 147 | "version": "3.8.8" 148 | }, 149 | "toc": { 150 | "base_numbering": 1, 151 | "nav_menu": {}, 152 | "number_sections": true, 153 | "sideBar": true, 154 | "skip_h1_title": false, 155 | "title_cell": "Table of Contents", 156 | "title_sidebar": "Contents", 157 | "toc_cell": false, 158 | "toc_position": {}, 159 | "toc_section_display": true, 160 | "toc_window_display": false 161 | }, 162 | "varInspector": { 163 | "cols": { 164 | "lenName": 16, 165 | "lenType": 16, 166 | "lenVar": 40 167 | }, 168 | "kernels_config": { 169 | "python": { 170 | "delete_cmd_postfix": "", 171 | "delete_cmd_prefix": "del ", 172 | "library": "var_list.py", 173 | "varRefreshCmd": "print(var_dic_list())" 174 | }, 175 | "r": { 176 | "delete_cmd_postfix": ") ", 177 | "delete_cmd_prefix": "rm(", 178 | "library": "var_list.r", 179 | "varRefreshCmd": "cat(var_dic_list()) " 180 | } 181 | }, 182 | "types_to_exclude": [ 183 | "module", 184 | "function", 185 | "builtin_function_or_method", 186 | "instance", 187 | "_Feature" 188 | ], 189 | "window_display": false 190 | } 191 | }, 192 | "nbformat": 4, 193 | "nbformat_minor": 2 194 | } 195 | -------------------------------------------------------------------------------- /002_Python_String_Methods/043_Python_String_zfill().ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\n", 8 | "All the IPython Notebooks in this lecture series by Dr. Milan Parmar are available @ **[GitHub](https://github.com/milaan9/02_Python_Datatypes/tree/main/002_Python_String_Methods)**\n", 9 | "" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "# Python String `zfill()`\n", 17 | "\n", 18 | "The string **`zfill()`** method returns a copy of the string with '0' characters padded to the left.\n", 19 | "\n", 20 | "**Syntax**:\n", 21 | "\n", 22 | "```python\n", 23 | "str.zfill(width)\n", 24 | "```" 25 | ] 26 | }, 27 | { 28 | "cell_type": "markdown", 29 | "metadata": { 30 | "heading_collapsed": true 31 | }, 32 | "source": [ 33 | "## `zfill()` Parameters\n", 34 | "\n", 35 | "The **`zfill()`** method takes a single character width.\n", 36 | "\n", 37 | "The **`width`** specifies the length of the returned string from **`zfill()`** with **`0`** digits filled to the left." 38 | ] 39 | }, 40 | { 41 | "cell_type": "markdown", 42 | "metadata": {}, 43 | "source": [ 44 | "## Return Value from `zfill()`\n", 45 | "\n", 46 | "The **`zfill()`** method returns a copy of the string with **`0`** filled to the left. The length of the returned string depends on the **`width`** provided.\n", 47 | "\n", 48 | "* Suppose, the initial length of the string is 10. And, the **`width`** is specified 15. In this case, **`zfill()`** returns a copy of the string with five '0' digits filled to the left.\n", 49 | "* Suppose, the initial length of the string is 10. And, the **`width`** is specified 8. In this case, **`zfill()`** doesn't fill '0' digits to the left and returns a copy of the original string. The length of the returned string in this case will be 10." 50 | ] 51 | }, 52 | { 53 | "cell_type": "code", 54 | "execution_count": 1, 55 | "metadata": { 56 | "ExecuteTime": { 57 | "end_time": "2021-06-10T18:16:54.223013Z", 58 | "start_time": "2021-06-10T18:16:54.207430Z" 59 | }, 60 | "scrolled": false 61 | }, 62 | "outputs": [ 63 | { 64 | "name": "stdout", 65 | "output_type": "stream", 66 | "text": [ 67 | "0program is fun\n", 68 | "000000program is fun\n", 69 | "program is fun\n" 70 | ] 71 | } 72 | ], 73 | "source": [ 74 | "# Example 1: How zfill() works in Python?\n", 75 | "\n", 76 | "text = \"program is fun\"\n", 77 | "print(text.zfill(15))\n", 78 | "print(text.zfill(20))\n", 79 | "print(text.zfill(10))" 80 | ] 81 | }, 82 | { 83 | "cell_type": "markdown", 84 | "metadata": {}, 85 | "source": [ 86 | ">**Note:** If a string starts with the sign prefix **`('+', '-')`**, **`0`** digits are filled after the first sign prefix character." 87 | ] 88 | }, 89 | { 90 | "cell_type": "code", 91 | "execution_count": 2, 92 | "metadata": { 93 | "ExecuteTime": { 94 | "end_time": "2021-06-10T18:16:55.830310Z", 95 | "start_time": "2021-06-10T18:16:55.818624Z" 96 | } 97 | }, 98 | "outputs": [ 99 | { 100 | "name": "stdout", 101 | "output_type": "stream", 102 | "text": [ 103 | "-0000690\n", 104 | "+0000690\n", 105 | "-0000000-random+text\n" 106 | ] 107 | } 108 | ], 109 | "source": [ 110 | "# Example 2: How zfill() works with Sign Prefix?\n", 111 | "\n", 112 | "number = \"-690\"\n", 113 | "print(number.zfill(8))\n", 114 | "\n", 115 | "number = \"+690\"\n", 116 | "print(number.zfill(8))\n", 117 | "\n", 118 | "text = \"--random+text\"\n", 119 | "print(text.zfill(20))" 120 | ] 121 | }, 122 | { 123 | "cell_type": "code", 124 | "execution_count": null, 125 | "metadata": {}, 126 | "outputs": [], 127 | "source": [] 128 | } 129 | ], 130 | "metadata": { 131 | "hide_input": false, 132 | "kernelspec": { 133 | "display_name": "Python 3", 134 | "language": "python", 135 | "name": "python3" 136 | }, 137 | "language_info": { 138 | "codemirror_mode": { 139 | "name": "ipython", 140 | "version": 3 141 | }, 142 | "file_extension": ".py", 143 | "mimetype": "text/x-python", 144 | "name": "python", 145 | "nbconvert_exporter": "python", 146 | "pygments_lexer": "ipython3", 147 | "version": "3.8.8" 148 | }, 149 | "toc": { 150 | "base_numbering": 1, 151 | "nav_menu": {}, 152 | "number_sections": true, 153 | "sideBar": true, 154 | "skip_h1_title": false, 155 | "title_cell": "Table of Contents", 156 | "title_sidebar": "Contents", 157 | "toc_cell": false, 158 | "toc_position": {}, 159 | "toc_section_display": true, 160 | "toc_window_display": false 161 | }, 162 | "varInspector": { 163 | "cols": { 164 | "lenName": 16, 165 | "lenType": 16, 166 | "lenVar": 40 167 | }, 168 | "kernels_config": { 169 | "python": { 170 | "delete_cmd_postfix": "", 171 | "delete_cmd_prefix": "del ", 172 | "library": "var_list.py", 173 | "varRefreshCmd": "print(var_dic_list())" 174 | }, 175 | "r": { 176 | "delete_cmd_postfix": ") ", 177 | "delete_cmd_prefix": "rm(", 178 | "library": "var_list.r", 179 | "varRefreshCmd": "cat(var_dic_list()) " 180 | } 181 | }, 182 | "types_to_exclude": [ 183 | "module", 184 | "function", 185 | "builtin_function_or_method", 186 | "instance", 187 | "_Feature" 188 | ], 189 | "window_display": false 190 | } 191 | }, 192 | "nbformat": 4, 193 | "nbformat_minor": 2 194 | } 195 | -------------------------------------------------------------------------------- /002_Python_String_Methods/018_Python_String_isprintable().ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\n", 8 | "All the IPython Notebooks in this lecture series by Dr. Milan Parmar are available @ **[GitHub](https://github.com/milaan9/02_Python_Datatypes/tree/main/002_Python_String_Methods)**\n", 9 | "" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "# Python String `isprintable()`\n", 17 | "\n", 18 | "The string **`isprintable()`** method returns **`True`** if all characters in a string are printable or the string is empty. If not, it returns **`False`**.\n", 19 | "\n", 20 | "Characters that occupy printing space on the screen are known as printable characters. For example:\n", 21 | "\n", 22 | "1. letters and symbols\n", 23 | "2. digits\n", 24 | "3. punctuation\n", 25 | "4. whitespace\n", 26 | "\n", 27 | "**Syntax**:\n", 28 | "\n", 29 | "```python\n", 30 | "string.isprintable()\n", 31 | "```" 32 | ] 33 | }, 34 | { 35 | "cell_type": "markdown", 36 | "metadata": { 37 | "heading_collapsed": true 38 | }, 39 | "source": [ 40 | "## `isprintable()` Parameters\n", 41 | "\n", 42 | "The **`isprintable()`** method doesn't take any parameters." 43 | ] 44 | }, 45 | { 46 | "cell_type": "markdown", 47 | "metadata": {}, 48 | "source": [ 49 | "## Return Value from `isprintable()`\n", 50 | "\n", 51 | "The **`isprintable()`** returns:\n", 52 | "\n", 53 | "* **`True`** if all characters in the string are printable.\n", 54 | "* **`False`** if the string contains at least one non-printable character." 55 | ] 56 | }, 57 | { 58 | "cell_type": "code", 59 | "execution_count": 1, 60 | "metadata": { 61 | "ExecuteTime": { 62 | "end_time": "2021-06-10T18:09:37.350836Z", 63 | "start_time": "2021-06-10T18:09:37.334280Z" 64 | }, 65 | "scrolled": true 66 | }, 67 | "outputs": [ 68 | { 69 | "name": "stdout", 70 | "output_type": "stream", 71 | "text": [ 72 | "Space is a printable\n", 73 | "True\n", 74 | "\n", 75 | "New Line is printable\n", 76 | "False\n", 77 | "\n", 78 | "Empty string printable? True\n" 79 | ] 80 | } 81 | ], 82 | "source": [ 83 | "# Example 1: Working of isprintable()\n", 84 | "\n", 85 | "s = 'Space is a printable'\n", 86 | "print(s)\n", 87 | "print(s.isprintable())\n", 88 | "\n", 89 | "s = '\\nNew Line is printable'\n", 90 | "print(s)\n", 91 | "print(s.isprintable())\n", 92 | "\n", 93 | "s = ''\n", 94 | "print('\\nEmpty string printable?', s.isprintable())" 95 | ] 96 | }, 97 | { 98 | "cell_type": "code", 99 | "execution_count": 2, 100 | "metadata": { 101 | "ExecuteTime": { 102 | "end_time": "2021-06-10T18:09:38.793069Z", 103 | "start_time": "2021-06-10T18:09:38.758982Z" 104 | } 105 | }, 106 | "outputs": [ 107 | { 108 | "name": "stdout", 109 | "output_type": "stream", 110 | "text": [ 111 | "Not Printable\n", 112 | "Printable\n" 113 | ] 114 | } 115 | ], 116 | "source": [ 117 | "# Example 2: How to use isprintable()?\n", 118 | "\n", 119 | "# written using ASCII\n", 120 | "# chr(27) is escape character\n", 121 | "# char(97) is letter 'a'\n", 122 | "s = chr(27) + chr(97)\n", 123 | "\n", 124 | "if s.isprintable() == True:\n", 125 | " print('Printable')\n", 126 | "else:\n", 127 | " print('Not Printable')\n", 128 | " \n", 129 | "s = '2+2 = 4'\n", 130 | "\n", 131 | "if s.isprintable() == True:\n", 132 | " print('Printable')\n", 133 | "else:\n", 134 | " print('Not Printable')" 135 | ] 136 | }, 137 | { 138 | "cell_type": "code", 139 | "execution_count": null, 140 | "metadata": {}, 141 | "outputs": [], 142 | "source": [] 143 | } 144 | ], 145 | "metadata": { 146 | "hide_input": false, 147 | "kernelspec": { 148 | "display_name": "Python 3", 149 | "language": "python", 150 | "name": "python3" 151 | }, 152 | "language_info": { 153 | "codemirror_mode": { 154 | "name": "ipython", 155 | "version": 3 156 | }, 157 | "file_extension": ".py", 158 | "mimetype": "text/x-python", 159 | "name": "python", 160 | "nbconvert_exporter": "python", 161 | "pygments_lexer": "ipython3", 162 | "version": "3.8.8" 163 | }, 164 | "toc": { 165 | "base_numbering": 1, 166 | "nav_menu": {}, 167 | "number_sections": true, 168 | "sideBar": true, 169 | "skip_h1_title": false, 170 | "title_cell": "Table of Contents", 171 | "title_sidebar": "Contents", 172 | "toc_cell": false, 173 | "toc_position": {}, 174 | "toc_section_display": true, 175 | "toc_window_display": false 176 | }, 177 | "varInspector": { 178 | "cols": { 179 | "lenName": 16, 180 | "lenType": 16, 181 | "lenVar": 40 182 | }, 183 | "kernels_config": { 184 | "python": { 185 | "delete_cmd_postfix": "", 186 | "delete_cmd_prefix": "del ", 187 | "library": "var_list.py", 188 | "varRefreshCmd": "print(var_dic_list())" 189 | }, 190 | "r": { 191 | "delete_cmd_postfix": ") ", 192 | "delete_cmd_prefix": "rm(", 193 | "library": "var_list.r", 194 | "varRefreshCmd": "cat(var_dic_list()) " 195 | } 196 | }, 197 | "types_to_exclude": [ 198 | "module", 199 | "function", 200 | "builtin_function_or_method", 201 | "instance", 202 | "_Feature" 203 | ], 204 | "window_display": false 205 | } 206 | }, 207 | "nbformat": 4, 208 | "nbformat_minor": 2 209 | } 210 | -------------------------------------------------------------------------------- /005_Python_Dictionary_Methods/009_Python_Dictionary_setdefault().ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\n", 8 | "All the IPython Notebooks in this lecture series by Dr. Milan Parmar are available @ **[GitHub](https://github.com/milaan9/02_Python_Datatypes/tree/main/005_Python_Dictionary_Methods)**\n", 9 | "" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "# Python Dictionary `setdefault()`\n", 17 | "\n", 18 | "The **`setdefault()`** method returns the value of a key (if the key is in dictionary). If not, it inserts key with a value to the dictionary.\n", 19 | "\n", 20 | "**Syntax**:\n", 21 | "\n", 22 | "```python\n", 23 | "dict.setdefault(key[, default_value])\n", 24 | "```" 25 | ] 26 | }, 27 | { 28 | "cell_type": "markdown", 29 | "metadata": {}, 30 | "source": [ 31 | "## `setdefault()` Parameters\n", 32 | "\n", 33 | "The **`setdefault()`** method takes a maximum of two parameters:\n", 34 | "\n", 35 | "* **key** - the key to be searched in the dictionary\n", 36 | "* **default_value** (optional) - **`key`** with a value **`default_value`** is inserted to the dictionary if the key is not in the dictionary.\n", 37 | "\n", 38 | "If not provided, the **`default_value`** will be **`None`**." 39 | ] 40 | }, 41 | { 42 | "cell_type": "markdown", 43 | "metadata": {}, 44 | "source": [ 45 | "## Return Value from `setdefault()`\n", 46 | "\n", 47 | "The **`setdefault()`** method returns:\n", 48 | "\n", 49 | "* value of the **`key`** if it is in the dictionary\n", 50 | "* None if the key is not in the dictionary and **`default_value`** is not specified\n", 51 | "* **`default_value`** if **`key`** is not in the dictionary and **`default_value`** is specified" 52 | ] 53 | }, 54 | { 55 | "cell_type": "code", 56 | "execution_count": 1, 57 | "metadata": { 58 | "ExecuteTime": { 59 | "end_time": "2021-06-09T18:12:40.123321Z", 60 | "start_time": "2021-06-09T18:12:40.112608Z" 61 | } 62 | }, 63 | "outputs": [ 64 | { 65 | "name": "stdout", 66 | "output_type": "stream", 67 | "text": [ 68 | "person = {'name': 'Phill', 'age': 22}\n", 69 | "Age = 22\n" 70 | ] 71 | } 72 | ], 73 | "source": [ 74 | "# Example 1: How setdefault() works when key is in the dictionary?\n", 75 | "\n", 76 | "person = {'name': 'Phill', 'age': 22}\n", 77 | "\n", 78 | "age = person.setdefault('age')\n", 79 | "print('person = ',person)\n", 80 | "print('Age = ',age)" 81 | ] 82 | }, 83 | { 84 | "cell_type": "code", 85 | "execution_count": 2, 86 | "metadata": { 87 | "ExecuteTime": { 88 | "end_time": "2021-06-09T18:12:41.230074Z", 89 | "start_time": "2021-06-09T18:12:41.220335Z" 90 | } 91 | }, 92 | "outputs": [ 93 | { 94 | "name": "stdout", 95 | "output_type": "stream", 96 | "text": [ 97 | "person = {'name': 'Phill', 'salary': None}\n", 98 | "salary = None\n", 99 | "person = {'name': 'Phill', 'salary': None, 'age': 22}\n", 100 | "age = 22\n" 101 | ] 102 | } 103 | ], 104 | "source": [ 105 | "# Example 2: How setdefault() works when key is not in the dictionary?\n", 106 | "\n", 107 | "person = {'name': 'Phill'}\n", 108 | "\n", 109 | "# key is not in the dictionary\n", 110 | "salary = person.setdefault('salary')\n", 111 | "print('person = ',person)\n", 112 | "print('salary = ',salary)\n", 113 | "\n", 114 | "# key is not in the dictionary\n", 115 | "# default_value is provided\n", 116 | "age = person.setdefault('age', 22)\n", 117 | "print('person = ',person)\n", 118 | "print('age = ',age)" 119 | ] 120 | }, 121 | { 122 | "cell_type": "code", 123 | "execution_count": null, 124 | "metadata": {}, 125 | "outputs": [], 126 | "source": [] 127 | } 128 | ], 129 | "metadata": { 130 | "hide_input": false, 131 | "kernelspec": { 132 | "display_name": "Python 3", 133 | "language": "python", 134 | "name": "python3" 135 | }, 136 | "language_info": { 137 | "codemirror_mode": { 138 | "name": "ipython", 139 | "version": 3 140 | }, 141 | "file_extension": ".py", 142 | "mimetype": "text/x-python", 143 | "name": "python", 144 | "nbconvert_exporter": "python", 145 | "pygments_lexer": "ipython3", 146 | "version": "3.8.8" 147 | }, 148 | "toc": { 149 | "base_numbering": 1, 150 | "nav_menu": {}, 151 | "number_sections": true, 152 | "sideBar": true, 153 | "skip_h1_title": false, 154 | "title_cell": "Table of Contents", 155 | "title_sidebar": "Contents", 156 | "toc_cell": false, 157 | "toc_position": {}, 158 | "toc_section_display": true, 159 | "toc_window_display": false 160 | }, 161 | "varInspector": { 162 | "cols": { 163 | "lenName": 16, 164 | "lenType": 16, 165 | "lenVar": 40 166 | }, 167 | "kernels_config": { 168 | "python": { 169 | "delete_cmd_postfix": "", 170 | "delete_cmd_prefix": "del ", 171 | "library": "var_list.py", 172 | "varRefreshCmd": "print(var_dic_list())" 173 | }, 174 | "r": { 175 | "delete_cmd_postfix": ") ", 176 | "delete_cmd_prefix": "rm(", 177 | "library": "var_list.r", 178 | "varRefreshCmd": "cat(var_dic_list()) " 179 | } 180 | }, 181 | "types_to_exclude": [ 182 | "module", 183 | "function", 184 | "builtin_function_or_method", 185 | "instance", 186 | "_Feature" 187 | ], 188 | "window_display": false 189 | } 190 | }, 191 | "nbformat": 4, 192 | "nbformat_minor": 2 193 | } 194 | -------------------------------------------------------------------------------- /002_Python_String_Methods/015_Python_String_isidentifier().ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\n", 8 | "All the IPython Notebooks in this lecture series by Dr. Milan Parmar are available @ **[GitHub](https://github.com/milaan9/02_Python_Datatypes/tree/main/002_Python_String_Methods)**\n", 9 | "" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "# Python String `isidentifier()`\n", 17 | "\n", 18 | "The string **`isidentifier()`** method returns **`True`** if the string is a valid identifier in Python. If not, it returns **`False`**.\n", 19 | "\n", 20 | "**Syntax**:\n", 21 | "\n", 22 | "```python\n", 23 | "string.isidentifier()\n", 24 | "```" 25 | ] 26 | }, 27 | { 28 | "cell_type": "markdown", 29 | "metadata": { 30 | "heading_collapsed": true 31 | }, 32 | "source": [ 33 | "## `isidentifier()` Parameters\n", 34 | "\n", 35 | "The **`isidentifier()`** method doesn't take any parameters." 36 | ] 37 | }, 38 | { 39 | "cell_type": "markdown", 40 | "metadata": {}, 41 | "source": [ 42 | "## Return Value from `isidentifier()`\n", 43 | "\n", 44 | "The **`isidentifier()`** returns:\n", 45 | "\n", 46 | "* **`True`** is a valid identifier.\n", 47 | "* **`False`** if the string is not a invalid identifier." 48 | ] 49 | }, 50 | { 51 | "cell_type": "code", 52 | "execution_count": 1, 53 | "metadata": { 54 | "ExecuteTime": { 55 | "end_time": "2021-06-10T18:08:29.394939Z", 56 | "start_time": "2021-06-10T18:08:29.382281Z" 57 | }, 58 | "scrolled": true 59 | }, 60 | "outputs": [ 61 | { 62 | "name": "stdout", 63 | "output_type": "stream", 64 | "text": [ 65 | "True\n", 66 | "False\n", 67 | "False\n", 68 | "False\n" 69 | ] 70 | } 71 | ], 72 | "source": [ 73 | "# Example 1: How isidentifier() works?\n", 74 | "\n", 75 | "str = 'Python'\n", 76 | "print(str.isidentifier())\n", 77 | "\n", 78 | "str = 'Py thon'\n", 79 | "print(str.isidentifier())\n", 80 | "\n", 81 | "str = '22Python'\n", 82 | "print(str.isidentifier())\n", 83 | "\n", 84 | "str = ''\n", 85 | "print(str.isidentifier())" 86 | ] 87 | }, 88 | { 89 | "cell_type": "markdown", 90 | "metadata": {}, 91 | "source": [ 92 | "Visit this page to learn what is **[valid identifier in Python?](https://docs.python.org/3.1/reference/lexical_analysis.html#identifiers)**" 93 | ] 94 | }, 95 | { 96 | "cell_type": "code", 97 | "execution_count": 2, 98 | "metadata": { 99 | "ExecuteTime": { 100 | "end_time": "2021-06-10T18:08:31.098156Z", 101 | "start_time": "2021-06-10T18:08:31.072841Z" 102 | } 103 | }, 104 | "outputs": [ 105 | { 106 | "name": "stdout", 107 | "output_type": "stream", 108 | "text": [ 109 | "root33 is a valid identifier.\n", 110 | "33root is not a valid identifier.\n", 111 | "root 33 is not a valid identifier.\n" 112 | ] 113 | } 114 | ], 115 | "source": [ 116 | "# Example 2: More Example of isidentifier()\n", 117 | "\n", 118 | "str = 'root33'\n", 119 | "if str.isidentifier() == True:\n", 120 | " print(str, 'is a valid identifier.')\n", 121 | "else:\n", 122 | " print(str, 'is not a valid identifier.')\n", 123 | " \n", 124 | "str = '33root'\n", 125 | "if str.isidentifier() == True:\n", 126 | " print(str, 'is a valid identifier.')\n", 127 | "else:\n", 128 | " print(str, 'is not a valid identifier.')\n", 129 | " \n", 130 | "str = 'root 33'\n", 131 | "if str.isidentifier() == True:\n", 132 | " print(str, 'is a valid identifier.')\n", 133 | "else:\n", 134 | " print(str, 'is not a valid identifier.')" 135 | ] 136 | }, 137 | { 138 | "cell_type": "code", 139 | "execution_count": null, 140 | "metadata": {}, 141 | "outputs": [], 142 | "source": [] 143 | } 144 | ], 145 | "metadata": { 146 | "hide_input": false, 147 | "kernelspec": { 148 | "display_name": "Python 3", 149 | "language": "python", 150 | "name": "python3" 151 | }, 152 | "language_info": { 153 | "codemirror_mode": { 154 | "name": "ipython", 155 | "version": 3 156 | }, 157 | "file_extension": ".py", 158 | "mimetype": "text/x-python", 159 | "name": "python", 160 | "nbconvert_exporter": "python", 161 | "pygments_lexer": "ipython3", 162 | "version": "3.8.8" 163 | }, 164 | "toc": { 165 | "base_numbering": 1, 166 | "nav_menu": {}, 167 | "number_sections": true, 168 | "sideBar": true, 169 | "skip_h1_title": false, 170 | "title_cell": "Table of Contents", 171 | "title_sidebar": "Contents", 172 | "toc_cell": false, 173 | "toc_position": {}, 174 | "toc_section_display": true, 175 | "toc_window_display": false 176 | }, 177 | "varInspector": { 178 | "cols": { 179 | "lenName": 16, 180 | "lenType": 16, 181 | "lenVar": 40 182 | }, 183 | "kernels_config": { 184 | "python": { 185 | "delete_cmd_postfix": "", 186 | "delete_cmd_prefix": "del ", 187 | "library": "var_list.py", 188 | "varRefreshCmd": "print(var_dic_list())" 189 | }, 190 | "r": { 191 | "delete_cmd_postfix": ") ", 192 | "delete_cmd_prefix": "rm(", 193 | "library": "var_list.r", 194 | "varRefreshCmd": "cat(var_dic_list()) " 195 | } 196 | }, 197 | "types_to_exclude": [ 198 | "module", 199 | "function", 200 | "builtin_function_or_method", 201 | "instance", 202 | "_Feature" 203 | ], 204 | "window_display": false 205 | } 206 | }, 207 | "nbformat": 4, 208 | "nbformat_minor": 2 209 | } 210 | -------------------------------------------------------------------------------- /002_Python_String_Methods/042_Python_String_title().ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\n", 8 | "All the IPython Notebooks in this lecture series by Dr. Milan Parmar are available @ **[GitHub](https://github.com/milaan9/02_Python_Datatypes/tree/main/002_Python_String_Methods)**\n", 9 | "" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "# Python String `title()`\n", 17 | "\n", 18 | "The string **`title()`** method returns a string with first letter of each word capitalized; a title cased string.\n", 19 | "\n", 20 | "**Syntax**:\n", 21 | "\n", 22 | "```python\n", 23 | "str.title()\n", 24 | "```" 25 | ] 26 | }, 27 | { 28 | "cell_type": "markdown", 29 | "metadata": { 30 | "heading_collapsed": true 31 | }, 32 | "source": [ 33 | "## `title()` Parameters\n", 34 | "\n", 35 | "The **`title()`** method doesn't take any parameters." 36 | ] 37 | }, 38 | { 39 | "cell_type": "markdown", 40 | "metadata": {}, 41 | "source": [ 42 | "## Return Value from `title()`\n", 43 | "\n", 44 | "The **`title()`** method returns a title cased version of the string. Meaning, the first character of each word is capitalized (if the first character is a letter)." 45 | ] 46 | }, 47 | { 48 | "cell_type": "code", 49 | "execution_count": 1, 50 | "metadata": { 51 | "ExecuteTime": { 52 | "end_time": "2021-06-10T18:16:39.103900Z", 53 | "start_time": "2021-06-10T18:16:39.089292Z" 54 | }, 55 | "scrolled": true 56 | }, 57 | "outputs": [ 58 | { 59 | "name": "stdout", 60 | "output_type": "stream", 61 | "text": [ 62 | "My Favorite Number Is 99.\n", 63 | "963 K3L2 *63 Fun\n" 64 | ] 65 | } 66 | ], 67 | "source": [ 68 | "# Example 1: How Python title() works?\n", 69 | "\n", 70 | "text = 'My favorite number is 99.'\n", 71 | "print(text.title())\n", 72 | "\n", 73 | "text = '963 k3l2 *63 fun'\n", 74 | "print(text.title())" 75 | ] 76 | }, 77 | { 78 | "cell_type": "code", 79 | "execution_count": 2, 80 | "metadata": { 81 | "ExecuteTime": { 82 | "end_time": "2021-06-10T18:16:39.744677Z", 83 | "start_time": "2021-06-10T18:16:39.734937Z" 84 | } 85 | }, 86 | "outputs": [ 87 | { 88 | "name": "stdout", 89 | "output_type": "stream", 90 | "text": [ 91 | "He'S An Engineer, Isn'T He?\n" 92 | ] 93 | } 94 | ], 95 | "source": [ 96 | "# Example 2: title() with apostrophes\n", 97 | "\n", 98 | "text = \"He's an engineer, isn't he?\"\n", 99 | "print(text.title())" 100 | ] 101 | }, 102 | { 103 | "cell_type": "markdown", 104 | "metadata": {}, 105 | "source": [ 106 | ">**Note:** **`title()`** capitalizes the first letter after apostrophes as well.\n", 107 | "\n", 108 | "To solve this issue, you can use regex as follows:" 109 | ] 110 | }, 111 | { 112 | "cell_type": "code", 113 | "execution_count": 3, 114 | "metadata": { 115 | "ExecuteTime": { 116 | "end_time": "2021-06-10T18:16:41.072488Z", 117 | "start_time": "2021-06-10T18:16:41.059828Z" 118 | } 119 | }, 120 | "outputs": [ 121 | { 122 | "name": "stdout", 123 | "output_type": "stream", 124 | "text": [ 125 | "He's An Engineer, Isn't He?\n" 126 | ] 127 | } 128 | ], 129 | "source": [ 130 | "# Example 3: Using Regex to Title Case String\n", 131 | "\n", 132 | "import re\n", 133 | "\n", 134 | "def titlecase(s):\n", 135 | " return re.sub(r\"[A-Za-z]+('[A-Za-z]+)?\",\n", 136 | " lambda mo: mo.group(0)[0].upper() +\n", 137 | " mo.group(0)[1:].lower(),\n", 138 | " s)\n", 139 | "\n", 140 | "text = \"He's an engineer, isn't he?\"\n", 141 | "print(titlecase(text))" 142 | ] 143 | }, 144 | { 145 | "cell_type": "code", 146 | "execution_count": null, 147 | "metadata": {}, 148 | "outputs": [], 149 | "source": [] 150 | } 151 | ], 152 | "metadata": { 153 | "hide_input": false, 154 | "kernelspec": { 155 | "display_name": "Python 3", 156 | "language": "python", 157 | "name": "python3" 158 | }, 159 | "language_info": { 160 | "codemirror_mode": { 161 | "name": "ipython", 162 | "version": 3 163 | }, 164 | "file_extension": ".py", 165 | "mimetype": "text/x-python", 166 | "name": "python", 167 | "nbconvert_exporter": "python", 168 | "pygments_lexer": "ipython3", 169 | "version": "3.8.8" 170 | }, 171 | "toc": { 172 | "base_numbering": 1, 173 | "nav_menu": {}, 174 | "number_sections": true, 175 | "sideBar": true, 176 | "skip_h1_title": false, 177 | "title_cell": "Table of Contents", 178 | "title_sidebar": "Contents", 179 | "toc_cell": false, 180 | "toc_position": {}, 181 | "toc_section_display": true, 182 | "toc_window_display": false 183 | }, 184 | "varInspector": { 185 | "cols": { 186 | "lenName": 16, 187 | "lenType": 16, 188 | "lenVar": 40 189 | }, 190 | "kernels_config": { 191 | "python": { 192 | "delete_cmd_postfix": "", 193 | "delete_cmd_prefix": "del ", 194 | "library": "var_list.py", 195 | "varRefreshCmd": "print(var_dic_list())" 196 | }, 197 | "r": { 198 | "delete_cmd_postfix": ") ", 199 | "delete_cmd_prefix": "rm(", 200 | "library": "var_list.r", 201 | "varRefreshCmd": "cat(var_dic_list()) " 202 | } 203 | }, 204 | "types_to_exclude": [ 205 | "module", 206 | "function", 207 | "builtin_function_or_method", 208 | "instance", 209 | "_Feature" 210 | ], 211 | "window_display": false 212 | } 213 | }, 214 | "nbformat": 4, 215 | "nbformat_minor": 2 216 | } 217 | -------------------------------------------------------------------------------- /005_Python_Dictionary_Methods/010_Python_Dictionary_update().ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\n", 8 | "All the IPython Notebooks in this lecture series by Dr. Milan Parmar are available @ **[GitHub](https://github.com/milaan9/02_Python_Datatypes/tree/main/005_Python_Dictionary_Methods)**\n", 9 | "" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "# Python Dictionary `update()`\n", 17 | "\n", 18 | "The **`update()`** method updates the dictionary with the elements from the another dictionary object or from an iterable of key/value pairs.\n", 19 | "\n", 20 | "The **`update()`** method adds element(s) to the dictionary if the key is not in the dictionary. If the key is in the dictionary, it updates the key with the new value.\n", 21 | "\n", 22 | "**Syntax**:\n", 23 | "\n", 24 | "```python\n", 25 | "dict.update([other])\n", 26 | "```" 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "metadata": {}, 32 | "source": [ 33 | "## `update()` Parameters\n", 34 | "\n", 35 | "The **`update()`** method takes either a **[dictionary](https://github.com/milaan9/02_Python_Datatypes/blob/main/005_Python_Dictionary.ipynb)** or an iterable object of key/value pairs (generally **[tuples](https://github.com/milaan9/02_Python_Datatypes/blob/main/004_Python_Tuple.ipynb)**).\n", 36 | "\n", 37 | "If **`update()`** is called without passing parameters, the dictionary remains unchanged." 38 | ] 39 | }, 40 | { 41 | "cell_type": "markdown", 42 | "metadata": {}, 43 | "source": [ 44 | "## Return Value from `update()`\n", 45 | "\n", 46 | "The **`update()`** method updates the dictionary with elements from a dictionary object or an iterable object of key/value pairs.\n", 47 | "\n", 48 | "It doesn't return any value (returns **`None`**)." 49 | ] 50 | }, 51 | { 52 | "cell_type": "code", 53 | "execution_count": 1, 54 | "metadata": { 55 | "ExecuteTime": { 56 | "end_time": "2021-06-09T18:12:52.127660Z", 57 | "start_time": "2021-06-09T18:12:52.118894Z" 58 | } 59 | }, 60 | "outputs": [ 61 | { 62 | "name": "stdout", 63 | "output_type": "stream", 64 | "text": [ 65 | "{1: 'one', 2: 'two'}\n", 66 | "{1: 'one', 2: 'two', 3: 'three'}\n" 67 | ] 68 | } 69 | ], 70 | "source": [ 71 | "# Example 1: Working of update()\n", 72 | "\n", 73 | "d = {1: \"one\", 2: \"three\"}\n", 74 | "d1 = {2: \"two\"}\n", 75 | "\n", 76 | "# updates the value of key 2\n", 77 | "d.update(d1)\n", 78 | "print(d)\n", 79 | "\n", 80 | "d1 = {3: \"three\"}\n", 81 | "\n", 82 | "# adds element with key 3\n", 83 | "d.update(d1)\n", 84 | "print(d)" 85 | ] 86 | }, 87 | { 88 | "cell_type": "code", 89 | "execution_count": 2, 90 | "metadata": { 91 | "ExecuteTime": { 92 | "end_time": "2021-06-09T18:12:52.766488Z", 93 | "start_time": "2021-06-09T18:12:52.747986Z" 94 | } 95 | }, 96 | "outputs": [ 97 | { 98 | "name": "stdout", 99 | "output_type": "stream", 100 | "text": [ 101 | "{'x': 2, 'y': 3, 'z': 0}\n" 102 | ] 103 | } 104 | ], 105 | "source": [ 106 | "# Example 2: update() When Tuple is Passed\n", 107 | "\n", 108 | "d = {'x': 2}\n", 109 | "\n", 110 | "d.update(y = 3, z = 0)\n", 111 | "print(d)" 112 | ] 113 | }, 114 | { 115 | "cell_type": "markdown", 116 | "metadata": {}, 117 | "source": [ 118 | "**Explanation:** \n", 119 | "\n", 120 | "The view object **`values`** doesn't itself return a list of **`sales`** item values but it returns a view of all values of the dictionary.\n", 121 | "\n", 122 | "If the list is updated at any time, the changes are reflected on the view object itself, as shown in the above program." 123 | ] 124 | }, 125 | { 126 | "cell_type": "code", 127 | "execution_count": null, 128 | "metadata": {}, 129 | "outputs": [], 130 | "source": [] 131 | } 132 | ], 133 | "metadata": { 134 | "hide_input": false, 135 | "kernelspec": { 136 | "display_name": "Python 3", 137 | "language": "python", 138 | "name": "python3" 139 | }, 140 | "language_info": { 141 | "codemirror_mode": { 142 | "name": "ipython", 143 | "version": 3 144 | }, 145 | "file_extension": ".py", 146 | "mimetype": "text/x-python", 147 | "name": "python", 148 | "nbconvert_exporter": "python", 149 | "pygments_lexer": "ipython3", 150 | "version": "3.8.8" 151 | }, 152 | "toc": { 153 | "base_numbering": 1, 154 | "nav_menu": {}, 155 | "number_sections": true, 156 | "sideBar": true, 157 | "skip_h1_title": false, 158 | "title_cell": "Table of Contents", 159 | "title_sidebar": "Contents", 160 | "toc_cell": false, 161 | "toc_position": {}, 162 | "toc_section_display": true, 163 | "toc_window_display": false 164 | }, 165 | "varInspector": { 166 | "cols": { 167 | "lenName": 16, 168 | "lenType": 16, 169 | "lenVar": 40 170 | }, 171 | "kernels_config": { 172 | "python": { 173 | "delete_cmd_postfix": "", 174 | "delete_cmd_prefix": "del ", 175 | "library": "var_list.py", 176 | "varRefreshCmd": "print(var_dic_list())" 177 | }, 178 | "r": { 179 | "delete_cmd_postfix": ") ", 180 | "delete_cmd_prefix": "rm(", 181 | "library": "var_list.r", 182 | "varRefreshCmd": "cat(var_dic_list()) " 183 | } 184 | }, 185 | "types_to_exclude": [ 186 | "module", 187 | "function", 188 | "builtin_function_or_method", 189 | "instance", 190 | "_Feature" 191 | ], 192 | "window_display": false 193 | } 194 | }, 195 | "nbformat": 4, 196 | "nbformat_minor": 2 197 | } 198 | -------------------------------------------------------------------------------- /006_Python_Sets_Methods/016_Python_Set_union().ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\n", 8 | "All the IPython Notebooks in this lecture series by Dr. Milan Parmar are available @ **[GitHub](https://github.com/milaan9/02_Python_Datatypes/tree/main/006_Python_Sets_Methods)**\n", 9 | "" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "# Python Set `union()`\n", 17 | "\n", 18 | "The **`union()`** method returns a new set with distinct elements from all the sets.\n", 19 | "\n", 20 | "The union of two or more sets is the set of all distinct elements present in all the sets. For example:\n", 21 | "\n", 22 | "```python\n", 23 | "A = {1, 2}\n", 24 | "B = {2, 3, 4}\n", 25 | "C = {5}\n", 26 | "\n", 27 | "Then,\n", 28 | "A∪B = B∪A = {1, 2, 3, 4}\n", 29 | "A∪C = C∪A = {1, 2, 5}\n", 30 | "B∪C = C∪B = {2, 3, 4, 5}\n", 31 | "\n", 32 | "A∪B∪C = {1, 2, 3, 4, 5}\n", 33 | "```\n", 34 | "\n", 35 | "
\n", 36 | "\n", 37 | "
" 38 | ] 39 | }, 40 | { 41 | "cell_type": "markdown", 42 | "metadata": {}, 43 | "source": [ 44 | "**Syntax**:\n", 45 | "\n", 46 | "```python\n", 47 | "A.union(*other_sets)\n", 48 | "```\n", 49 | "\n", 50 | ">**Note:** **`*`** is not part of the syntax. It is used to indicate that the method can take 0 or more arguments." 51 | ] 52 | }, 53 | { 54 | "cell_type": "markdown", 55 | "metadata": {}, 56 | "source": [ 57 | "## Return Value from `union()`\n", 58 | "\n", 59 | "* The **`union()`** method returns a new set with elements from the set and all other sets (passed as an argument).\n", 60 | "* If the argument is not passed to **`union()`**, it returns a shallow copy of the set." 61 | ] 62 | }, 63 | { 64 | "cell_type": "code", 65 | "execution_count": 1, 66 | "metadata": { 67 | "ExecuteTime": { 68 | "end_time": "2021-06-10T17:46:05.414841Z", 69 | "start_time": "2021-06-10T17:46:05.404128Z" 70 | }, 71 | "scrolled": true 72 | }, 73 | "outputs": [ 74 | { 75 | "name": "stdout", 76 | "output_type": "stream", 77 | "text": [ 78 | "A U B = {'a', 2, 'd', 'c'}\n", 79 | "B U C = {1, 2, 3, 'd', 'c'}\n", 80 | "A U B U C = {1, 'a', 2, 3, 'd', 'c'}\n", 81 | "A.union() = {'a', 'd', 'c'}\n" 82 | ] 83 | } 84 | ], 85 | "source": [ 86 | "# Example 1: Working of union()\n", 87 | "\n", 88 | "A = {'a', 'c', 'd'}\n", 89 | "B = {'c', 'd', 2 }\n", 90 | "C = {1, 2, 3}\n", 91 | "\n", 92 | "print('A U B =', A.union(B))\n", 93 | "print('B U C =', B.union(C))\n", 94 | "print('A U B U C =', A.union(B, C))\n", 95 | "print('A.union() =', A.union())" 96 | ] 97 | }, 98 | { 99 | "cell_type": "markdown", 100 | "metadata": {}, 101 | "source": [ 102 | "You can also find the union of sets using the **`|`** operator." 103 | ] 104 | }, 105 | { 106 | "cell_type": "code", 107 | "execution_count": 2, 108 | "metadata": { 109 | "ExecuteTime": { 110 | "end_time": "2021-06-10T17:46:08.102103Z", 111 | "start_time": "2021-06-10T17:46:08.083601Z" 112 | } 113 | }, 114 | "outputs": [ 115 | { 116 | "name": "stdout", 117 | "output_type": "stream", 118 | "text": [ 119 | "A U B = {'a', 2, 'd', 'c'}\n", 120 | "B U C = {1, 2, 3, 'd', 'c'}\n", 121 | "A U B U C = {1, 'a', 2, 3, 'd', 'c'}\n" 122 | ] 123 | } 124 | ], 125 | "source": [ 126 | "# Example 2: Set Union Using the | Operator\n", 127 | "\n", 128 | "A = {'a', 'c', 'd'}\n", 129 | "B = {'c', 'd', 2 }\n", 130 | "C = {1, 2, 3}\n", 131 | "\n", 132 | "print('A U B =', A| B)\n", 133 | "print('B U C =', B | C)\n", 134 | "print('A U B U C =', A | B | C)" 135 | ] 136 | }, 137 | { 138 | "cell_type": "code", 139 | "execution_count": null, 140 | "metadata": {}, 141 | "outputs": [], 142 | "source": [] 143 | } 144 | ], 145 | "metadata": { 146 | "hide_input": false, 147 | "kernelspec": { 148 | "display_name": "Python 3", 149 | "language": "python", 150 | "name": "python3" 151 | }, 152 | "language_info": { 153 | "codemirror_mode": { 154 | "name": "ipython", 155 | "version": 3 156 | }, 157 | "file_extension": ".py", 158 | "mimetype": "text/x-python", 159 | "name": "python", 160 | "nbconvert_exporter": "python", 161 | "pygments_lexer": "ipython3", 162 | "version": "3.8.8" 163 | }, 164 | "toc": { 165 | "base_numbering": 1, 166 | "nav_menu": {}, 167 | "number_sections": true, 168 | "sideBar": true, 169 | "skip_h1_title": false, 170 | "title_cell": "Table of Contents", 171 | "title_sidebar": "Contents", 172 | "toc_cell": false, 173 | "toc_position": {}, 174 | "toc_section_display": true, 175 | "toc_window_display": false 176 | }, 177 | "varInspector": { 178 | "cols": { 179 | "lenName": 16, 180 | "lenType": 16, 181 | "lenVar": 40 182 | }, 183 | "kernels_config": { 184 | "python": { 185 | "delete_cmd_postfix": "", 186 | "delete_cmd_prefix": "del ", 187 | "library": "var_list.py", 188 | "varRefreshCmd": "print(var_dic_list())" 189 | }, 190 | "r": { 191 | "delete_cmd_postfix": ") ", 192 | "delete_cmd_prefix": "rm(", 193 | "library": "var_list.r", 194 | "varRefreshCmd": "cat(var_dic_list()) " 195 | } 196 | }, 197 | "types_to_exclude": [ 198 | "module", 199 | "function", 200 | "builtin_function_or_method", 201 | "instance", 202 | "_Feature" 203 | ], 204 | "window_display": false 205 | } 206 | }, 207 | "nbformat": 4, 208 | "nbformat_minor": 2 209 | } 210 | -------------------------------------------------------------------------------- /002_Python_String_Methods/016_Python_String_islower().ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\n", 8 | "All the IPython Notebooks in this lecture series by Dr. Milan Parmar are available @ **[GitHub](https://github.com/milaan9/02_Python_Datatypes/tree/main/002_Python_String_Methods)**\n", 9 | "" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "# Python String `islower()`\n", 17 | "\n", 18 | "The string **`islower()`** method returns **`True`** if all alphabets in a string are lowercase alphabets. If the string contains at least one uppercase alphabet, it returns **`False`**.\n", 19 | "\n", 20 | "**Syntax**:\n", 21 | "\n", 22 | "```python\n", 23 | "string.islower()\n", 24 | "```" 25 | ] 26 | }, 27 | { 28 | "cell_type": "markdown", 29 | "metadata": { 30 | "heading_collapsed": true 31 | }, 32 | "source": [ 33 | "## `islower()` Parameters\n", 34 | "\n", 35 | "The **`islower()`** method doesn't take any parameters." 36 | ] 37 | }, 38 | { 39 | "cell_type": "markdown", 40 | "metadata": {}, 41 | "source": [ 42 | "## Return Value from `islower()`\n", 43 | "\n", 44 | "The **`islower()`** returns:\n", 45 | "\n", 46 | "* **`True`** if all alphabets that exist in the string are lowercase alphabets.\n", 47 | "* **`False`** if the string contains at least one uppercase alphabet." 48 | ] 49 | }, 50 | { 51 | "cell_type": "code", 52 | "execution_count": 1, 53 | "metadata": { 54 | "ExecuteTime": { 55 | "end_time": "2021-06-23T09:23:31.669668Z", 56 | "start_time": "2021-06-23T09:23:31.659900Z" 57 | }, 58 | "scrolled": true 59 | }, 60 | "outputs": [ 61 | { 62 | "name": "stdout", 63 | "output_type": "stream", 64 | "text": [ 65 | "True\n", 66 | "True\n", 67 | "False\n" 68 | ] 69 | } 70 | ], 71 | "source": [ 72 | "# Example 1: Return Value from islower()\n", 73 | "\n", 74 | "s = 'this is good'\n", 75 | "print(s.islower())\n", 76 | "\n", 77 | "s = 'th!s is a1so g00d'\n", 78 | "print(s.islower())\n", 79 | "\n", 80 | "s = 'this is Not good'\n", 81 | "print(s.islower())" 82 | ] 83 | }, 84 | { 85 | "cell_type": "code", 86 | "execution_count": 2, 87 | "metadata": { 88 | "ExecuteTime": { 89 | "end_time": "2021-06-23T09:23:32.194564Z", 90 | "start_time": "2021-06-23T09:23:32.179426Z" 91 | } 92 | }, 93 | "outputs": [ 94 | { 95 | "name": "stdout", 96 | "output_type": "stream", 97 | "text": [ 98 | "Does not contain uppercase letter.\n", 99 | "Contains uppercase letter.\n" 100 | ] 101 | } 102 | ], 103 | "source": [ 104 | "# Example 2: How to use islower() in a program?\n", 105 | "\n", 106 | "s = 'this is good'\n", 107 | "if s.islower() == True:\n", 108 | " print('Does not contain uppercase letter.')\n", 109 | "else:\n", 110 | " print('Contains uppercase letter.')\n", 111 | " \n", 112 | "s = 'this is Good'\n", 113 | "if s.islower() == True:\n", 114 | " print('Does not contain uppercase letter.')\n", 115 | "else:\n", 116 | " print('Contains uppercase letter.')" 117 | ] 118 | }, 119 | { 120 | "cell_type": "code", 121 | "execution_count": 3, 122 | "metadata": { 123 | "ExecuteTime": { 124 | "end_time": "2021-06-23T09:23:35.210648Z", 125 | "start_time": "2021-06-23T09:23:35.195028Z" 126 | } 127 | }, 128 | "outputs": [ 129 | { 130 | "name": "stdout", 131 | "output_type": "stream", 132 | "text": [ 133 | "False\n", 134 | "True\n" 135 | ] 136 | } 137 | ], 138 | "source": [ 139 | "# Example:\n", 140 | "\n", 141 | "s=\"I Love Python 3 Tutorial\"\n", 142 | "\n", 143 | "print(s.islower())\n", 144 | "p=\"python\"\n", 145 | "print(p.islower())" 146 | ] 147 | }, 148 | { 149 | "cell_type": "code", 150 | "execution_count": null, 151 | "metadata": {}, 152 | "outputs": [], 153 | "source": [] 154 | } 155 | ], 156 | "metadata": { 157 | "hide_input": false, 158 | "kernelspec": { 159 | "display_name": "Python 3", 160 | "language": "python", 161 | "name": "python3" 162 | }, 163 | "language_info": { 164 | "codemirror_mode": { 165 | "name": "ipython", 166 | "version": 3 167 | }, 168 | "file_extension": ".py", 169 | "mimetype": "text/x-python", 170 | "name": "python", 171 | "nbconvert_exporter": "python", 172 | "pygments_lexer": "ipython3", 173 | "version": "3.8.8" 174 | }, 175 | "toc": { 176 | "base_numbering": 1, 177 | "nav_menu": {}, 178 | "number_sections": true, 179 | "sideBar": true, 180 | "skip_h1_title": false, 181 | "title_cell": "Table of Contents", 182 | "title_sidebar": "Contents", 183 | "toc_cell": false, 184 | "toc_position": {}, 185 | "toc_section_display": true, 186 | "toc_window_display": false 187 | }, 188 | "varInspector": { 189 | "cols": { 190 | "lenName": 16, 191 | "lenType": 16, 192 | "lenVar": 40 193 | }, 194 | "kernels_config": { 195 | "python": { 196 | "delete_cmd_postfix": "", 197 | "delete_cmd_prefix": "del ", 198 | "library": "var_list.py", 199 | "varRefreshCmd": "print(var_dic_list())" 200 | }, 201 | "r": { 202 | "delete_cmd_postfix": ") ", 203 | "delete_cmd_prefix": "rm(", 204 | "library": "var_list.r", 205 | "varRefreshCmd": "cat(var_dic_list()) " 206 | } 207 | }, 208 | "types_to_exclude": [ 209 | "module", 210 | "function", 211 | "builtin_function_or_method", 212 | "instance", 213 | "_Feature" 214 | ], 215 | "window_display": false 216 | } 217 | }, 218 | "nbformat": 4, 219 | "nbformat_minor": 2 220 | } 221 | --------------------------------------------------------------------------------