0 00:00:00,0 --> 00:00:05,0 Downloaded from git.ir 1 00:00:00,979 --> 00:00:03,260 in this course you're going to learn 2 00:00:03,260 --> 00:00:03,270 in this course you're going to learn 3 00:00:03,270 --> 00:00:04,999 in this course you're going to learn everything you need to get started with 4 00:00:04,999 --> 00:00:05,009 everything you need to get started with 5 00:00:05,009 --> 00:00:07,430 everything you need to get started with Python just be aware that I've designed 6 00:00:07,430 --> 00:00:07,440 Python just be aware that I've designed 7 00:00:07,440 --> 00:00:09,320 Python just be aware that I've designed this course for beginners so if you have 8 00:00:09,320 --> 00:00:09,330 this course for beginners so if you have 9 00:00:09,330 --> 00:00:11,240 this course for beginners so if you have some programming experience check out my 10 00:00:11,240 --> 00:00:11,250 some programming experience check out my 11 00:00:11,250 --> 00:00:13,669 some programming experience check out my other Python course for developers you 12 00:00:13,669 --> 00:00:13,679 other Python course for developers you 13 00:00:13,679 --> 00:00:15,169 other Python course for developers you can see the link on the top right corner 14 00:00:15,169 --> 00:00:15,179 can see the link on the top right corner 15 00:00:15,179 --> 00:00:19,189 can see the link on the top right corner of this video so python is the world's 16 00:00:19,189 --> 00:00:19,199 of this video so python is the world's 17 00:00:19,199 --> 00:00:21,679 of this video so python is the world's fastest-growing and most popular 18 00:00:21,679 --> 00:00:21,689 fastest-growing and most popular 19 00:00:21,689 --> 00:00:23,870 fastest-growing and most popular programming language not just amongst 20 00:00:23,870 --> 00:00:23,880 programming language not just amongst 21 00:00:23,880 --> 00:00:26,769 programming language not just amongst software developers but also amongst 22 00:00:26,769 --> 00:00:26,779 software developers but also amongst 23 00:00:26,779 --> 00:00:30,400 software developers but also amongst mathematicians data analysts scientists 24 00:00:30,400 --> 00:00:30,410 mathematicians data analysts scientists 25 00:00:30,410 --> 00:00:33,319 mathematicians data analysts scientists accountants network engineers and even 26 00:00:33,319 --> 00:00:33,329 accountants network engineers and even 27 00:00:33,329 --> 00:00:36,290 accountants network engineers and even kids in fact it's the ideal programming 28 00:00:36,290 --> 00:00:36,300 kids in fact it's the ideal programming 29 00:00:36,300 --> 00:00:38,660 kids in fact it's the ideal programming language to learn first but what makes 30 00:00:38,660 --> 00:00:38,670 language to learn first but what makes 31 00:00:38,670 --> 00:00:41,360 language to learn first but what makes Python so special here are six reasons 32 00:00:41,360 --> 00:00:41,370 Python so special here are six reasons 33 00:00:41,370 --> 00:00:44,000 Python so special here are six reasons with Python you can solve complex 34 00:00:44,000 --> 00:00:44,010 with Python you can solve complex 35 00:00:44,010 --> 00:00:46,819 with Python you can solve complex problems in less time with fewer lines 36 00:00:46,819 --> 00:00:46,829 problems in less time with fewer lines 37 00:00:46,829 --> 00:00:49,160 problems in less time with fewer lines of code than many other languages 38 00:00:49,160 --> 00:00:49,170 of code than many other languages 39 00:00:49,170 --> 00:00:51,970 of code than many other languages that's why huge companies like Google 40 00:00:51,970 --> 00:00:51,980 that's why huge companies like Google 41 00:00:51,980 --> 00:00:55,279 that's why huge companies like Google Spotify Dropbox and Facebook have 42 00:00:55,279 --> 00:00:55,289 Spotify Dropbox and Facebook have 43 00:00:55,289 --> 00:00:57,529 Spotify Dropbox and Facebook have embraced this beautiful and powerful 44 00:00:57,529 --> 00:00:57,539 embraced this beautiful and powerful 45 00:00:57,539 --> 00:01:00,740 embraced this beautiful and powerful language here is an example let's say we 46 00:01:00,740 --> 00:01:00,750 language here is an example let's say we 47 00:01:00,750 --> 00:01:02,810 language here is an example let's say we want to extract the first three 48 00:01:02,810 --> 00:01:02,820 want to extract the first three 49 00:01:02,820 --> 00:01:05,870 want to extract the first three characters of the text hello world this 50 00:01:05,870 --> 00:01:05,880 characters of the text hello world this 51 00:01:05,880 --> 00:01:07,429 characters of the text hello world this is the code we would have to write in 52 00:01:07,429 --> 00:01:07,439 is the code we would have to write in 53 00:01:07,439 --> 00:01:10,070 is the code we would have to write in c-sharp this is how we would do this in 54 00:01:10,070 --> 00:01:10,080 c-sharp this is how we would do this in 55 00:01:10,080 --> 00:01:12,679 c-sharp this is how we would do this in JavaScript and here's how we would do it 56 00:01:12,679 --> 00:01:12,689 JavaScript and here's how we would do it 57 00:01:12,689 --> 00:01:15,770 JavaScript and here's how we would do it in Python see how clean and simple the 58 00:01:15,770 --> 00:01:15,780 in Python see how clean and simple the 59 00:01:15,780 --> 00:01:17,510 in Python see how clean and simple the language is and that's just the 60 00:01:17,510 --> 00:01:17,520 language is and that's just the 61 00:01:17,520 --> 00:01:18,200 language is and that's just the beginning 62 00:01:18,200 --> 00:01:18,210 beginning 63 00:01:18,210 --> 00:01:20,780 beginning Python is a multi-purpose language and 64 00:01:20,780 --> 00:01:20,790 Python is a multi-purpose language and 65 00:01:20,790 --> 00:01:22,609 Python is a multi-purpose language and you can use it for a wide range of jobs 66 00:01:22,609 --> 00:01:22,619 you can use it for a wide range of jobs 67 00:01:22,619 --> 00:01:25,460 you can use it for a wide range of jobs such as data analysis AI and machine 68 00:01:25,460 --> 00:01:25,470 such as data analysis AI and machine 69 00:01:25,470 --> 00:01:28,240 such as data analysis AI and machine learning writing automation scripts 70 00:01:28,240 --> 00:01:28,250 learning writing automation scripts 71 00:01:28,250 --> 00:01:30,830 learning writing automation scripts building web mobile and desktop 72 00:01:30,830 --> 00:01:30,840 building web mobile and desktop 73 00:01:30,840 --> 00:01:33,499 building web mobile and desktop applications as well as software testing 74 00:01:33,499 --> 00:01:33,509 applications as well as software testing 75 00:01:33,509 --> 00:01:35,840 applications as well as software testing or even hacking so if you want a 76 00:01:35,840 --> 00:01:35,850 or even hacking so if you want a 77 00:01:35,850 --> 00:01:38,840 or even hacking so if you want a high-paying long lasting career in any 78 00:01:38,840 --> 00:01:38,850 high-paying long lasting career in any 79 00:01:38,850 --> 00:01:41,270 high-paying long lasting career in any of these areas especially AI and machine 80 00:01:41,270 --> 00:01:41,280 of these areas especially AI and machine 81 00:01:41,280 --> 00:01:44,899 of these areas especially AI and machine learning Python is the language to put 82 00:01:44,899 --> 00:01:44,909 learning Python is the language to put 83 00:01:44,909 --> 00:01:46,999 learning Python is the language to put those opportunities at your fingertips 84 00:01:46,999 --> 00:01:47,009 those opportunities at your fingertips 85 00:01:47,009 --> 00:01:49,819 those opportunities at your fingertips in fact according to indeed.com 86 00:01:49,819 --> 00:01:49,829 in fact according to indeed.com 87 00:01:49,829 --> 00:01:52,249 in fact according to indeed.com the average salary of a Python developer 88 00:01:52,249 --> 00:01:52,259 the average salary of a Python developer 89 00:01:52,259 --> 00:01:55,130 the average salary of a Python developer in the US was over one hundred and 90 00:01:55,130 --> 00:01:55,140 in the US was over one hundred and 91 00:01:55,140 --> 00:01:58,030 in the US was over one hundred and fifteen thousand dollars in March 2018 92 00:01:58,030 --> 00:01:58,040 fifteen thousand dollars in March 2018 93 00:01:58,040 --> 00:02:01,010 fifteen thousand dollars in March 2018 and here are four more reasons that make 94 00:02:01,010 --> 00:02:01,020 and here are four more reasons that make 95 00:02:01,020 --> 00:02:03,260 and here are four more reasons that make Python the most desirable language 96 00:02:03,260 --> 00:02:03,270 Python the most desirable language 97 00:02:03,270 --> 00:02:05,870 Python the most desirable language Python is a high-level language so you 98 00:02:05,870 --> 00:02:05,880 Python is a high-level language so you 99 00:02:05,880 --> 00:02:08,389 Python is a high-level language so you don't have to worry about complex tasks 100 00:02:08,389 --> 00:02:08,399 don't have to worry about complex tasks 101 00:02:08,399 --> 00:02:10,609 don't have to worry about complex tasks such as memory management as you do in 102 00:02:10,609 --> 00:02:10,619 such as memory management as you do in 103 00:02:10,619 --> 00:02:12,089 such as memory management as you do in C++ 104 00:02:12,089 --> 00:02:12,099 C++ 105 00:02:12,099 --> 00:02:14,489 C++ it's cross platform which means we can 106 00:02:14,489 --> 00:02:14,499 it's cross platform which means we can 107 00:02:14,499 --> 00:02:17,520 it's cross platform which means we can build and run Python apps on Windows Mac 108 00:02:17,520 --> 00:02:17,530 build and run Python apps on Windows Mac 109 00:02:17,530 --> 00:02:20,849 build and run Python apps on Windows Mac and Linux it has a huge community so 110 00:02:20,849 --> 00:02:20,859 and Linux it has a huge community so 111 00:02:20,859 --> 00:02:22,679 and Linux it has a huge community so whenever you get stuck there is someone 112 00:02:22,679 --> 00:02:22,689 whenever you get stuck there is someone 113 00:02:22,689 --> 00:02:25,349 whenever you get stuck there is someone out there to help and it has a large 114 00:02:25,349 --> 00:02:25,359 out there to help and it has a large 115 00:02:25,359 --> 00:02:28,349 out there to help and it has a large ecosystem of libraries frameworks and 116 00:02:28,349 --> 00:02:28,359 ecosystem of libraries frameworks and 117 00:02:28,359 --> 00:02:30,839 ecosystem of libraries frameworks and tools whatever you want to do it is 118 00:02:30,839 --> 00:02:30,849 tools whatever you want to do it is 119 00:02:30,849 --> 00:02:32,520 tools whatever you want to do it is likely that someone else has done it 120 00:02:32,520 --> 00:02:32,530 likely that someone else has done it 121 00:02:32,530 --> 00:02:34,649 likely that someone else has done it before because python has been around 122 00:02:34,649 --> 00:02:34,659 before because python has been around 123 00:02:34,659 --> 00:02:37,979 before because python has been around for over 20 years there are two versions 124 00:02:37,979 --> 00:02:37,989 for over 20 years there are two versions 125 00:02:37,989 --> 00:02:40,709 for over 20 years there are two versions of Python out there Python 2 which is 126 00:02:40,709 --> 00:02:40,719 of Python out there Python 2 which is 127 00:02:40,719 --> 00:02:42,869 of Python out there Python 2 which is the legacy version of Python and is 128 00:02:42,869 --> 00:02:42,879 the legacy version of Python and is 129 00:02:42,879 --> 00:02:45,209 the legacy version of Python and is going to be supported until year 2020 130 00:02:45,209 --> 00:02:45,219 going to be supported until year 2020 131 00:02:45,219 --> 00:02:48,240 going to be supported until year 2020 and Python 3 which is Python for the 132 00:02:48,240 --> 00:02:48,250 and Python 3 which is Python for the 133 00:02:48,250 --> 00:02:50,459 and Python 3 which is Python for the future in this course you're gonna learn 134 00:02:50,459 --> 00:02:50,469 future in this course you're gonna learn 135 00:02:50,469 --> 00:02:53,879 future in this course you're gonna learn Python 3 hi my name is Muhammed Ani and 136 00:02:53,879 --> 00:02:53,889 Python 3 hi my name is Muhammed Ani and 137 00:02:53,889 --> 00:02:55,439 Python 3 hi my name is Muhammed Ani and I'm going to be your instructor in this 138 00:02:55,439 --> 00:02:55,449 I'm going to be your instructor in this 139 00:02:55,449 --> 00:02:58,199 I'm going to be your instructor in this course I'm a software engineer with 18 140 00:02:58,199 --> 00:02:58,209 course I'm a software engineer with 18 141 00:02:58,209 --> 00:03:00,659 course I'm a software engineer with 18 years of experience and I've taught way 142 00:03:00,659 --> 00:03:00,669 years of experience and I've taught way 143 00:03:00,669 --> 00:03:03,330 years of experience and I've taught way over a million people how to code or how 144 00:03:03,330 --> 00:03:03,340 over a million people how to code or how 145 00:03:03,340 --> 00:03:06,119 over a million people how to code or how to become top professional software 146 00:03:06,119 --> 00:03:06,129 to become top professional software 147 00:03:06,129 --> 00:03:08,339 to become top professional software engineers to learn more about me and my 148 00:03:08,339 --> 00:03:08,349 engineers to learn more about me and my 149 00:03:08,349 --> 00:03:10,979 engineers to learn more about me and my courses head over to code with mass comm 150 00:03:10,979 --> 00:03:10,989 courses head over to code with mass comm 151 00:03:10,989 --> 00:03:13,870 courses head over to code with mass comm alright now let's get started 152 00:03:13,870 --> 00:03:13,880 alright now let's get started 153 00:03:13,880 --> 00:03:23,100 alright now let's get started [Music] 154 00:03:23,100 --> 00:03:23,110 [Music] 155 00:03:23,110 --> 00:03:24,720 [Music] all right now we were ready to download 156 00:03:24,720 --> 00:03:24,730 all right now we were ready to download 157 00:03:24,730 --> 00:03:27,120 all right now we were ready to download and install Python the first thing I 158 00:03:27,120 --> 00:03:27,130 and install Python the first thing I 159 00:03:27,130 --> 00:03:28,710 and install Python the first thing I want you to do is to open up your 160 00:03:28,710 --> 00:03:28,720 want you to do is to open up your 161 00:03:28,720 --> 00:03:32,510 want you to do is to open up your browser and head over to python org on 162 00:03:32,510 --> 00:03:32,520 browser and head over to python org on 163 00:03:32,520 --> 00:03:35,490 browser and head over to python org on this page under the downloads you can 164 00:03:35,490 --> 00:03:35,500 this page under the downloads you can 165 00:03:35,500 --> 00:03:37,080 this page under the downloads you can see the latest version of python 166 00:03:37,080 --> 00:03:37,090 see the latest version of python 167 00:03:37,090 --> 00:03:40,160 see the latest version of python currently the latest version is 3.7 168 00:03:40,160 --> 00:03:40,170 currently the latest version is 3.7 169 00:03:40,170 --> 00:03:42,120 currently the latest version is 3.7 chances are in the future when you're 170 00:03:42,120 --> 00:03:42,130 chances are in the future when you're 171 00:03:42,130 --> 00:03:43,680 chances are in the future when you're watching this video there is a newer 172 00:03:43,680 --> 00:03:43,690 watching this video there is a newer 173 00:03:43,690 --> 00:03:45,750 watching this video there is a newer version available don't worry all the 174 00:03:45,750 --> 00:03:45,760 version available don't worry all the 175 00:03:45,760 --> 00:03:47,850 version available don't worry all the materials in this course will continue 176 00:03:47,850 --> 00:03:47,860 materials in this course will continue 177 00:03:47,860 --> 00:03:49,770 materials in this course will continue to apply with the future versions of 178 00:03:49,770 --> 00:03:49,780 to apply with the future versions of 179 00:03:49,780 --> 00:03:55,500 to apply with the future versions of Python so go ahead and download Python 180 00:03:55,500 --> 00:03:55,510 181 00:03:55,510 --> 00:03:58,229 then run it if you're on Windows we're 182 00:03:58,229 --> 00:03:58,239 then run it if you're on Windows we're 183 00:03:58,239 --> 00:03:59,869 then run it if you're on Windows we're going to see this checkbox here add 184 00:03:59,869 --> 00:03:59,879 going to see this checkbox here add 185 00:03:59,879 --> 00:04:03,149 going to see this checkbox here add Python to path this is very important 186 00:04:03,149 --> 00:04:03,159 Python to path this is very important 187 00:04:03,159 --> 00:04:04,920 Python to path this is very important make sure to take it otherwise you're 188 00:04:04,920 --> 00:04:04,930 make sure to take it otherwise you're 189 00:04:04,930 --> 00:04:06,330 make sure to take it otherwise you're not going to be able to follow the 190 00:04:06,330 --> 00:04:06,340 not going to be able to follow the 191 00:04:06,340 --> 00:04:12,130 not going to be able to follow the course so now go ahead and install it 192 00:04:12,130 --> 00:04:12,140 193 00:04:12,140 --> 00:04:14,470 now let's verify that we have installed 194 00:04:14,470 --> 00:04:14,480 now let's verify that we have installed 195 00:04:14,480 --> 00:04:17,020 now let's verify that we have installed Python properly if you're on Windows 196 00:04:17,020 --> 00:04:17,030 Python properly if you're on Windows 197 00:04:17,030 --> 00:04:20,800 Python properly if you're on Windows here in this search bar type CMD which 198 00:04:20,800 --> 00:04:20,810 here in this search bar type CMD which 199 00:04:20,810 --> 00:04:24,640 here in this search bar type CMD which is short for command prompt dr. in 200 00:04:24,640 --> 00:04:24,650 is short for command prompt dr. in 201 00:04:24,650 --> 00:04:28,810 is short for command prompt dr. in command prompt type Python you can see 202 00:04:28,810 --> 00:04:28,820 command prompt type Python you can see 203 00:04:28,820 --> 00:04:30,700 command prompt type Python you can see we have successfully installed Python 204 00:04:30,700 --> 00:04:30,710 we have successfully installed Python 205 00:04:30,710 --> 00:04:35,710 we have successfully installed Python version 3.7 now to exit press ctrl-z 206 00:04:35,710 --> 00:04:35,720 version 3.7 now to exit press ctrl-z 207 00:04:35,720 --> 00:04:39,440 version 3.7 now to exit press ctrl-z and then enter 208 00:04:39,440 --> 00:04:39,450 209 00:04:39,450 --> 00:04:43,250 if you're on Mac press command and space 210 00:04:43,250 --> 00:04:43,260 if you're on Mac press command and space 211 00:04:43,260 --> 00:04:46,370 if you're on Mac press command and space this opens up the spotlight search so 212 00:04:46,370 --> 00:04:46,380 this opens up the spotlight search so 213 00:04:46,380 --> 00:04:49,510 this opens up the spotlight search so here type terminal 214 00:04:49,510 --> 00:04:49,520 here type terminal 215 00:04:49,520 --> 00:04:52,100 here type terminal terminal and Mac is like command prompt 216 00:04:52,100 --> 00:04:52,110 terminal and Mac is like command prompt 217 00:04:52,110 --> 00:04:55,040 terminal and Mac is like command prompt on Windows now Mac and Linux by default 218 00:04:55,040 --> 00:04:55,050 on Windows now Mac and Linux by default 219 00:04:55,050 --> 00:04:56,930 on Windows now Mac and Linux by default come with an older version of Python 220 00:04:56,930 --> 00:04:56,940 come with an older version of Python 221 00:04:56,940 --> 00:04:59,510 come with an older version of Python that is version 2 so if you type Python 222 00:04:59,510 --> 00:04:59,520 that is version 2 so if you type Python 223 00:04:59,520 --> 00:05:01,820 that is version 2 so if you type Python you can see Python 2 here let's start 224 00:05:01,820 --> 00:05:01,830 you can see Python 2 here let's start 225 00:05:01,830 --> 00:05:04,850 you can see Python 2 here let's start what we want so press control D to exit 226 00:05:04,850 --> 00:05:04,860 what we want so press control D to exit 227 00:05:04,860 --> 00:05:08,900 what we want so press control D to exit and then run Python 3 and this verifies 228 00:05:08,900 --> 00:05:08,910 and then run Python 3 and this verifies 229 00:05:08,910 --> 00:05:10,400 and then run Python 3 and this verifies that we have successfully installed 230 00:05:10,400 --> 00:05:10,410 that we have successfully installed 231 00:05:10,410 --> 00:05:19,740 that we have successfully installed Python 3.7 232 00:05:19,740 --> 00:05:19,750 233 00:05:19,750 --> 00:05:22,629 so this environment you see here is what 234 00:05:22,629 --> 00:05:22,639 so this environment you see here is what 235 00:05:22,639 --> 00:05:25,510 so this environment you see here is what we call Python interpreter which is 236 00:05:25,510 --> 00:05:25,520 we call Python interpreter which is 237 00:05:25,520 --> 00:05:28,180 we call Python interpreter which is basically a program that executes Python 238 00:05:28,180 --> 00:05:28,190 basically a program that executes Python 239 00:05:28,190 --> 00:05:30,340 basically a program that executes Python code we can type our Python code in a 240 00:05:30,340 --> 00:05:30,350 code we can type our Python code in a 241 00:05:30,350 --> 00:05:32,620 code we can type our Python code in a file and give it to this interpreter or 242 00:05:32,620 --> 00:05:32,630 file and give it to this interpreter or 243 00:05:32,630 --> 00:05:34,600 file and give it to this interpreter or we can type our code directly here in 244 00:05:34,600 --> 00:05:34,610 we can type our code directly here in 245 00:05:34,610 --> 00:05:37,480 we can type our code directly here in this interactive shell so here we can 246 00:05:37,480 --> 00:05:37,490 this interactive shell so here we can 247 00:05:37,490 --> 00:05:40,080 this interactive shell so here we can write an expression like 2+2 in 248 00:05:40,080 --> 00:05:40,090 write an expression like 2+2 in 249 00:05:40,090 --> 00:05:42,700 write an expression like 2+2 in programming an expression is a piece of 250 00:05:42,700 --> 00:05:42,710 programming an expression is a piece of 251 00:05:42,710 --> 00:05:45,730 programming an expression is a piece of code that produces a value so here when 252 00:05:45,730 --> 00:05:45,740 code that produces a value so here when 253 00:05:45,740 --> 00:05:48,879 code that produces a value so here when we add two plus two we get a value that 254 00:05:48,879 --> 00:05:48,889 we add two plus two we get a value that 255 00:05:48,889 --> 00:05:50,890 we add two plus two we get a value that is why we refer to this piece of code as 256 00:05:50,890 --> 00:05:50,900 is why we refer to this piece of code as 257 00:05:50,900 --> 00:05:54,790 is why we refer to this piece of code as an expression so enter we get four let's 258 00:05:54,790 --> 00:05:54,800 an expression so enter we get four let's 259 00:05:54,800 --> 00:05:57,129 an expression so enter we get four let's try a different kind of expression let's 260 00:05:57,129 --> 00:05:57,139 try a different kind of expression let's 261 00:05:57,139 --> 00:06:01,120 try a different kind of expression let's see if two is greater than one we get 262 00:06:01,120 --> 00:06:01,130 see if two is greater than one we get 263 00:06:01,130 --> 00:06:03,070 see if two is greater than one we get true which is an example of a boolean 264 00:06:03,070 --> 00:06:03,080 true which is an example of a boolean 265 00:06:03,080 --> 00:06:04,840 true which is an example of a boolean value you're gonna learn about these 266 00:06:04,840 --> 00:06:04,850 value you're gonna learn about these 267 00:06:04,850 --> 00:06:07,360 value you're gonna learn about these boolean values in the next section now 268 00:06:07,360 --> 00:06:07,370 boolean values in the next section now 269 00:06:07,370 --> 00:06:11,070 boolean values in the next section now what if we type 2 is greater than 5 270 00:06:11,070 --> 00:06:11,080 what if we type 2 is greater than 5 271 00:06:11,080 --> 00:06:14,560 what if we type 2 is greater than 5 enter we get false so in programming we 272 00:06:14,560 --> 00:06:14,570 enter we get false so in programming we 273 00:06:14,570 --> 00:06:17,439 enter we get false so in programming we have true and false which are similar to 274 00:06:17,439 --> 00:06:17,449 have true and false which are similar to 275 00:06:17,449 --> 00:06:20,409 have true and false which are similar to yes and no in English now what if we 276 00:06:20,409 --> 00:06:20,419 yes and no in English now what if we 277 00:06:20,419 --> 00:06:23,350 yes and no in English now what if we type 2 is greater than but we don't add 278 00:06:23,350 --> 00:06:23,360 type 2 is greater than but we don't add 279 00:06:23,360 --> 00:06:25,920 type 2 is greater than but we don't add a second value here just press Enter 280 00:06:25,920 --> 00:06:25,930 a second value here just press Enter 281 00:06:25,930 --> 00:06:30,070 a second value here just press Enter we get a syntax error in programming 282 00:06:30,070 --> 00:06:30,080 we get a syntax error in programming 283 00:06:30,080 --> 00:06:32,649 we get a syntax error in programming syntax means grammar so just like we 284 00:06:32,649 --> 00:06:32,659 syntax means grammar so just like we 285 00:06:32,659 --> 00:06:34,570 syntax means grammar so just like we have the concept of grammar in the 286 00:06:34,570 --> 00:06:34,580 have the concept of grammar in the 287 00:06:34,580 --> 00:06:36,339 have the concept of grammar in the languages that we speak we have the 288 00:06:36,339 --> 00:06:36,349 languages that we speak we have the 289 00:06:36,349 --> 00:06:38,920 languages that we speak we have the exact same concept in programming if we 290 00:06:38,920 --> 00:06:38,930 exact same concept in programming if we 291 00:06:38,930 --> 00:06:40,540 exact same concept in programming if we write a sentence that is not 292 00:06:40,540 --> 00:06:40,550 write a sentence that is not 293 00:06:40,550 --> 00:06:42,760 write a sentence that is not grammatically correct chances are some 294 00:06:42,760 --> 00:06:42,770 grammatically correct chances are some 295 00:06:42,770 --> 00:06:44,740 grammatically correct chances are some people may not understand that sentence 296 00:06:44,740 --> 00:06:44,750 people may not understand that sentence 297 00:06:44,750 --> 00:06:46,930 people may not understand that sentence so in this example we have this 298 00:06:46,930 --> 00:06:46,940 so in this example we have this 299 00:06:46,940 --> 00:06:49,300 so in this example we have this expression which is incomplete it 300 00:06:49,300 --> 00:06:49,310 expression which is incomplete it 301 00:06:49,310 --> 00:06:51,219 expression which is incomplete it doesn't have the right grammar or syntax 302 00:06:51,219 --> 00:06:51,229 doesn't have the right grammar or syntax 303 00:06:51,229 --> 00:06:54,040 doesn't have the right grammar or syntax that is why Python interpreter is 304 00:06:54,040 --> 00:06:54,050 that is why Python interpreter is 305 00:06:54,050 --> 00:06:57,070 that is why Python interpreter is complaining by returning an error so 306 00:06:57,070 --> 00:06:57,080 complaining by returning an error so 307 00:06:57,080 --> 00:06:58,990 complaining by returning an error so this interactive shell is a great way to 308 00:06:58,990 --> 00:06:59,000 this interactive shell is a great way to 309 00:06:59,000 --> 00:07:01,300 this interactive shell is a great way to quickly experiment with a bit of Python 310 00:07:01,300 --> 00:07:01,310 quickly experiment with a bit of Python 311 00:07:01,310 --> 00:07:03,610 quickly experiment with a bit of Python code but that's not how we build real 312 00:07:03,610 --> 00:07:03,620 code but that's not how we build real 313 00:07:03,620 --> 00:07:05,860 code but that's not how we build real world applications to do that we need a 314 00:07:05,860 --> 00:07:05,870 world applications to do that we need a 315 00:07:05,870 --> 00:07:07,779 world applications to do that we need a code editor and that's what I'm gonna 316 00:07:07,779 --> 00:07:07,789 code editor and that's what I'm gonna 317 00:07:07,789 --> 00:07:12,760 code editor and that's what I'm gonna show you in the next lecture 318 00:07:12,760 --> 00:07:12,770 319 00:07:12,770 --> 00:07:16,680 [Music] 320 00:07:16,680 --> 00:07:16,690 321 00:07:16,690 --> 00:07:19,750 when it comes to typing Python code you 322 00:07:19,750 --> 00:07:19,760 when it comes to typing Python code you 323 00:07:19,760 --> 00:07:22,150 when it comes to typing Python code you have two options you can use a code 324 00:07:22,150 --> 00:07:22,160 have two options you can use a code 325 00:07:22,160 --> 00:07:25,360 have two options you can use a code editor or an IDE which is short for 326 00:07:25,360 --> 00:07:25,370 editor or an IDE which is short for 327 00:07:25,370 --> 00:07:28,240 editor or an IDE which is short for integrated development environment an 328 00:07:28,240 --> 00:07:28,250 integrated development environment an 329 00:07:28,250 --> 00:07:31,300 integrated development environment an IDE is basically a code editor with some 330 00:07:31,300 --> 00:07:31,310 IDE is basically a code editor with some 331 00:07:31,310 --> 00:07:33,400 IDE is basically a code editor with some fancy features like auto completion 332 00:07:33,400 --> 00:07:33,410 fancy features like auto completion 333 00:07:33,410 --> 00:07:35,920 fancy features like auto completion which means as you type code this 334 00:07:35,920 --> 00:07:35,930 which means as you type code this 335 00:07:35,930 --> 00:07:38,290 which means as you type code this feature helps you complete your code so 336 00:07:38,290 --> 00:07:38,300 feature helps you complete your code so 337 00:07:38,300 --> 00:07:39,940 feature helps you complete your code so you don't have to type every character 338 00:07:39,940 --> 00:07:39,950 you don't have to type every character 339 00:07:39,950 --> 00:07:40,570 you don't have to type every character by hand 340 00:07:40,570 --> 00:07:40,580 by hand 341 00:07:40,580 --> 00:07:43,360 by hand it's a productivity boosting feature it 342 00:07:43,360 --> 00:07:43,370 it's a productivity boosting feature it 343 00:07:43,370 --> 00:07:45,190 it's a productivity boosting feature it also gives you additional features like 344 00:07:45,190 --> 00:07:45,200 also gives you additional features like 345 00:07:45,200 --> 00:07:47,860 also gives you additional features like debugging which means finding and fixing 346 00:07:47,860 --> 00:07:47,870 debugging which means finding and fixing 347 00:07:47,870 --> 00:07:50,470 debugging which means finding and fixing bugs in your programs testing and so on 348 00:07:50,470 --> 00:07:50,480 bugs in your programs testing and so on 349 00:07:50,480 --> 00:07:53,500 bugs in your programs testing and so on for both code editors and IDs are so 350 00:07:53,500 --> 00:07:53,510 for both code editors and IDs are so 351 00:07:53,510 --> 00:07:55,960 for both code editors and IDs are so many options out there the most popular 352 00:07:55,960 --> 00:07:55,970 many options out there the most popular 353 00:07:55,970 --> 00:07:58,990 many options out there the most popular code editors are vs code atom and 354 00:07:58,990 --> 00:07:59,000 code editors are vs code atom and 355 00:07:59,000 --> 00:08:01,750 code editors are vs code atom and sublime you can use the code editor that 356 00:08:01,750 --> 00:08:01,760 sublime you can use the code editor that 357 00:08:01,760 --> 00:08:04,510 sublime you can use the code editor that you prefer in terms of the idea is again 358 00:08:04,510 --> 00:08:04,520 you prefer in terms of the idea is again 359 00:08:04,520 --> 00:08:06,430 you prefer in terms of the idea is again there are so many options out there the 360 00:08:06,430 --> 00:08:06,440 there are so many options out there the 361 00:08:06,440 --> 00:08:09,280 there are so many options out there the most popular one is pie chart in this 362 00:08:09,280 --> 00:08:09,290 most popular one is pie chart in this 363 00:08:09,290 --> 00:08:11,860 most popular one is pie chart in this course I'm gonna use vs code or Visual 364 00:08:11,860 --> 00:08:11,870 course I'm gonna use vs code or Visual 365 00:08:11,870 --> 00:08:13,690 course I'm gonna use vs code or Visual Studio code because that's my favorite 366 00:08:13,690 --> 00:08:13,700 Studio code because that's my favorite 367 00:08:13,700 --> 00:08:16,120 Studio code because that's my favorite code editor later in the course I will 368 00:08:16,120 --> 00:08:16,130 code editor later in the course I will 369 00:08:16,130 --> 00:08:18,460 code editor later in the course I will show you how to install a plugin or an 370 00:08:18,460 --> 00:08:18,470 show you how to install a plugin or an 371 00:08:18,470 --> 00:08:20,860 show you how to install a plugin or an extension that will convert vs code to a 372 00:08:20,860 --> 00:08:20,870 extension that will convert vs code to a 373 00:08:20,870 --> 00:08:23,620 extension that will convert vs code to a powerful ID so before going any further 374 00:08:23,620 --> 00:08:23,630 powerful ID so before going any further 375 00:08:23,630 --> 00:08:26,500 powerful ID so before going any further head over to code that visual studio 376 00:08:26,500 --> 00:08:26,510 head over to code that visual studio 377 00:08:26,510 --> 00:08:29,230 head over to code that visual studio comm and download the latest version of 378 00:08:29,230 --> 00:08:29,240 comm and download the latest version of 379 00:08:29,240 --> 00:08:37,980 comm and download the latest version of vs code 380 00:08:37,980 --> 00:08:37,990 381 00:08:37,990 --> 00:08:42,250 now it vs code open on the top from the 382 00:08:42,250 --> 00:08:42,260 now it vs code open on the top from the 383 00:08:42,260 --> 00:08:44,860 now it vs code open on the top from the file menu go to open 384 00:08:44,860 --> 00:08:44,870 file menu go to open 385 00:08:44,870 --> 00:08:47,050 file menu go to open and somewhere on your desk create a new 386 00:08:47,050 --> 00:08:47,060 and somewhere on your desk create a new 387 00:08:47,060 --> 00:08:50,230 and somewhere on your desk create a new folder let's call this folder hello 388 00:08:50,230 --> 00:08:50,240 folder let's call this folder hello 389 00:08:50,240 --> 00:08:55,990 folder let's call this folder hello world and then open it beautiful now 390 00:08:55,990 --> 00:08:56,000 world and then open it beautiful now 391 00:08:56,000 --> 00:08:59,140 world and then open it beautiful now click this icon on the top this opens up 392 00:08:59,140 --> 00:08:59,150 click this icon on the top this opens up 393 00:08:59,150 --> 00:09:01,690 click this icon on the top this opens up the Explorer panel in this panel you can 394 00:09:01,690 --> 00:09:01,700 the Explorer panel in this panel you can 395 00:09:01,700 --> 00:09:03,910 the Explorer panel in this panel you can see all the files and folders in your 396 00:09:03,910 --> 00:09:03,920 see all the files and folders in your 397 00:09:03,920 --> 00:09:08,200 see all the files and folders in your project so let's add a new file and call 398 00:09:08,200 --> 00:09:08,210 project so let's add a new file and call 399 00:09:08,210 --> 00:09:11,980 project so let's add a new file and call that app that PI so all our Python files 400 00:09:11,980 --> 00:09:11,990 that app that PI so all our Python files 401 00:09:11,990 --> 00:09:15,810 that app that PI so all our Python files should have the PI extension press Enter 402 00:09:15,810 --> 00:09:15,820 should have the PI extension press Enter 403 00:09:15,820 --> 00:09:19,840 should have the PI extension press Enter now let's close this and type a bit of 404 00:09:19,840 --> 00:09:19,850 now let's close this and type a bit of 405 00:09:19,850 --> 00:09:21,910 now let's close this and type a bit of Python code in this lecture we're gonna 406 00:09:21,910 --> 00:09:21,920 Python code in this lecture we're gonna 407 00:09:21,920 --> 00:09:24,010 Python code in this lecture we're gonna use one of the built-in functions in 408 00:09:24,010 --> 00:09:24,020 use one of the built-in functions in 409 00:09:24,020 --> 00:09:27,160 use one of the built-in functions in Python called print so in Python we have 410 00:09:27,160 --> 00:09:27,170 Python called print so in Python we have 411 00:09:27,170 --> 00:09:28,990 Python called print so in Python we have a lot of built-in functions for 412 00:09:28,990 --> 00:09:29,000 a lot of built-in functions for 413 00:09:29,000 --> 00:09:31,240 a lot of built-in functions for performing various kinds of tasks for 414 00:09:31,240 --> 00:09:31,250 performing various kinds of tasks for 415 00:09:31,250 --> 00:09:33,040 performing various kinds of tasks for example as a metaphor think of the 416 00:09:33,040 --> 00:09:33,050 example as a metaphor think of the 417 00:09:33,050 --> 00:09:35,620 example as a metaphor think of the remote control of your TV on this remote 418 00:09:35,620 --> 00:09:35,630 remote control of your TV on this remote 419 00:09:35,630 --> 00:09:37,360 remote control of your TV on this remote control you have a bunch of functions 420 00:09:37,360 --> 00:09:37,370 control you have a bunch of functions 421 00:09:37,370 --> 00:09:40,269 control you have a bunch of functions like turn on turn off change the channel 422 00:09:40,269 --> 00:09:40,279 like turn on turn off change the channel 423 00:09:40,279 --> 00:09:42,220 like turn on turn off change the channel change the volume and so on these are 424 00:09:42,220 --> 00:09:42,230 change the volume and so on these are 425 00:09:42,230 --> 00:09:45,460 change the volume and so on these are the built-in functions and your TV we 426 00:09:45,460 --> 00:09:45,470 the built-in functions and your TV we 427 00:09:45,470 --> 00:09:47,800 the built-in functions and your TV we have the same concept in Python and many 428 00:09:47,800 --> 00:09:47,810 have the same concept in Python and many 429 00:09:47,810 --> 00:09:50,079 have the same concept in Python and many other programming languages so one of 430 00:09:50,079 --> 00:09:50,089 other programming languages so one of 431 00:09:50,089 --> 00:09:52,000 other programming languages so one of these built-in functions that comes with 432 00:09:52,000 --> 00:09:52,010 these built-in functions that comes with 433 00:09:52,010 --> 00:09:56,380 these built-in functions that comes with Python is print and we can use this to 434 00:09:56,380 --> 00:09:56,390 Python is print and we can use this to 435 00:09:56,390 --> 00:09:58,870 Python is print and we can use this to print something on the screen now 436 00:09:58,870 --> 00:09:58,880 print something on the screen now 437 00:09:58,880 --> 00:10:00,760 print something on the screen now whenever you want to use a function you 438 00:10:00,760 --> 00:10:00,770 whenever you want to use a function you 439 00:10:00,770 --> 00:10:03,540 whenever you want to use a function you should open and close parenthesis in 440 00:10:03,540 --> 00:10:03,550 should open and close parenthesis in 441 00:10:03,550 --> 00:10:06,160 should open and close parenthesis in programming we say we're calling the 442 00:10:06,160 --> 00:10:06,170 programming we say we're calling the 443 00:10:06,170 --> 00:10:08,710 programming we say we're calling the print function calling a function means 444 00:10:08,710 --> 00:10:08,720 print function calling a function means 445 00:10:08,720 --> 00:10:12,280 print function calling a function means executing it now let's display the hello 446 00:10:12,280 --> 00:10:12,290 executing it now let's display the hello 447 00:10:12,290 --> 00:10:15,010 executing it now let's display the hello world message on the screen whenever you 448 00:10:15,010 --> 00:10:15,020 world message on the screen whenever you 449 00:10:15,020 --> 00:10:16,780 world message on the screen whenever you want to work with text you should put 450 00:10:16,780 --> 00:10:16,790 want to work with text you should put 451 00:10:16,790 --> 00:10:20,140 want to work with text you should put your text in between quotes either 452 00:10:20,140 --> 00:10:20,150 your text in between quotes either 453 00:10:20,150 --> 00:10:23,320 your text in between quotes either double quotes or single quotes now I'm 454 00:10:23,320 --> 00:10:23,330 double quotes or single quotes now I'm 455 00:10:23,330 --> 00:10:25,990 double quotes or single quotes now I'm gonna go with double quotes and add 456 00:10:25,990 --> 00:10:26,000 gonna go with double quotes and add 457 00:10:26,000 --> 00:10:31,180 gonna go with double quotes and add hello world and then put a happy Persian 458 00:10:31,180 --> 00:10:31,190 hello world and then put a happy Persian 459 00:10:31,190 --> 00:10:31,810 hello world and then put a happy Persian cat here 460 00:10:31,810 --> 00:10:31,820 cat here 461 00:10:31,820 --> 00:10:34,900 cat here beautiful save the changes with command 462 00:10:34,900 --> 00:10:34,910 beautiful save the changes with command 463 00:10:34,910 --> 00:10:39,310 beautiful save the changes with command and s on Mac or ctrl + S on Windows now 464 00:10:39,310 --> 00:10:39,320 and s on Mac or ctrl + S on Windows now 465 00:10:39,320 --> 00:10:41,410 and s on Mac or ctrl + S on Windows now to execute this code we need to go back 466 00:10:41,410 --> 00:10:41,420 to execute this code we need to go back 467 00:10:41,420 --> 00:10:43,930 to execute this code we need to go back to command prompt on Windows or terminal 468 00:10:43,930 --> 00:10:43,940 to command prompt on Windows or terminal 469 00:10:43,940 --> 00:10:46,420 to command prompt on Windows or terminal on Mac but the good news is that we 470 00:10:46,420 --> 00:10:46,430 on Mac but the good news is that we 471 00:10:46,430 --> 00:10:48,970 on Mac but the good news is that we don't have to switch programs here in vs 472 00:10:48,970 --> 00:10:48,980 don't have to switch programs here in vs 473 00:10:48,980 --> 00:10:51,880 don't have to switch programs here in vs code we have an integrated terminal so 474 00:10:51,880 --> 00:10:51,890 code we have an integrated terminal so 475 00:10:51,890 --> 00:10:55,660 code we have an integrated terminal so press ctrl + backtick that is the key 476 00:10:55,660 --> 00:10:55,670 press ctrl + backtick that is the key 477 00:10:55,670 --> 00:10:58,900 press ctrl + backtick that is the key before number 1 on your keyboard that is 478 00:10:58,900 --> 00:10:58,910 before number 1 on your keyboard that is 479 00:10:58,910 --> 00:11:02,470 before number 1 on your keyboard that is just below the escape button so this is 480 00:11:02,470 --> 00:11:02,480 just below the escape button so this is 481 00:11:02,480 --> 00:11:04,930 just below the escape button so this is our integrated terminal now you front 482 00:11:04,930 --> 00:11:04,940 our integrated terminal now you front 483 00:11:04,940 --> 00:11:07,750 our integrated terminal now you front windows type Python if you're on Mac or 484 00:11:07,750 --> 00:11:07,760 windows type Python if you're on Mac or 485 00:11:07,760 --> 00:11:10,780 windows type Python if you're on Mac or Linux type Python 3 and next to that at 486 00:11:10,780 --> 00:11:10,790 Linux type Python 3 and next to that at 487 00:11:10,790 --> 00:11:14,440 Linux type Python 3 and next to that at the name of our file that is up at PI 488 00:11:14,440 --> 00:11:14,450 the name of our file that is up at PI 489 00:11:14,450 --> 00:11:17,530 the name of our file that is up at PI and here's our hello world message in 490 00:11:17,530 --> 00:11:17,540 and here's our hello world message in 491 00:11:17,540 --> 00:11:20,380 and here's our hello world message in the terminal beautiful now let's take 492 00:11:20,380 --> 00:11:20,390 the terminal beautiful now let's take 493 00:11:20,390 --> 00:11:21,790 the terminal beautiful now let's take this to the next level and make it a 494 00:11:21,790 --> 00:11:21,800 this to the next level and make it a 495 00:11:21,800 --> 00:11:24,100 this to the next level and make it a little bit more interesting let's close 496 00:11:24,100 --> 00:11:24,110 little bit more interesting let's close 497 00:11:24,110 --> 00:11:26,050 little bit more interesting let's close this terminal window by pressing ctrl 498 00:11:26,050 --> 00:11:26,060 this terminal window by pressing ctrl 499 00:11:26,060 --> 00:11:29,860 this terminal window by pressing ctrl and backtick and add a second line of 500 00:11:29,860 --> 00:11:29,870 and backtick and add a second line of 501 00:11:29,870 --> 00:11:33,910 and backtick and add a second line of code so one more time print this time 502 00:11:33,910 --> 00:11:33,920 code so one more time print this time 503 00:11:33,920 --> 00:11:36,730 code so one more time print this time let's add quotes with a star in between 504 00:11:36,730 --> 00:11:36,740 let's add quotes with a star in between 505 00:11:36,740 --> 00:11:39,430 let's add quotes with a star in between them now let's see if you want to repeat 506 00:11:39,430 --> 00:11:39,440 them now let's see if you want to repeat 507 00:11:39,440 --> 00:11:41,980 them now let's see if you want to repeat this star ten times so here we can 508 00:11:41,980 --> 00:11:41,990 this star ten times so here we can 509 00:11:41,990 --> 00:11:46,350 this star ten times so here we can multiply this by 10 save the changes 510 00:11:46,350 --> 00:11:46,360 multiply this by 10 save the changes 511 00:11:46,360 --> 00:11:49,630 multiply this by 10 save the changes open up the terminal and run our program 512 00:11:49,630 --> 00:11:49,640 open up the terminal and run our program 513 00:11:49,640 --> 00:11:53,620 open up the terminal and run our program and you can see this star is repeated 10 514 00:11:53,620 --> 00:11:53,630 and you can see this star is repeated 10 515 00:11:53,630 --> 00:11:56,920 and you can see this star is repeated 10 times so as you see the instructions on 516 00:11:56,920 --> 00:11:56,930 times so as you see the instructions on 517 00:11:56,930 --> 00:11:59,230 times so as you see the instructions on our program are executed from top to 518 00:11:59,230 --> 00:11:59,240 our program are executed from top to 519 00:11:59,240 --> 00:12:02,200 our program are executed from top to bottom in order in the next lecture I'm 520 00:12:02,200 --> 00:12:02,210 bottom in order in the next lecture I'm 521 00:12:02,210 --> 00:12:04,120 bottom in order in the next lecture I'm going to show you how to convert this vs 522 00:12:04,120 --> 00:12:04,130 going to show you how to convert this vs 523 00:12:04,130 --> 00:12:06,790 going to show you how to convert this vs code to a powerful IDE for building 524 00:12:06,790 --> 00:12:06,800 code to a powerful IDE for building 525 00:12:06,800 --> 00:12:11,990 code to a powerful IDE for building Python applications 526 00:12:11,990 --> 00:12:12,000 527 00:12:12,000 --> 00:12:15,250 [Music] 528 00:12:15,250 --> 00:12:15,260 529 00:12:15,260 --> 00:12:17,600 in this lecture I'm gonna show you how 530 00:12:17,600 --> 00:12:17,610 in this lecture I'm gonna show you how 531 00:12:17,610 --> 00:12:20,870 in this lecture I'm gonna show you how to convert vs code to a powerful IDE by 532 00:12:20,870 --> 00:12:20,880 to convert vs code to a powerful IDE by 533 00:12:20,880 --> 00:12:23,900 to convert vs code to a powerful IDE by using an extension called Python with 534 00:12:23,900 --> 00:12:23,910 using an extension called Python with 535 00:12:23,910 --> 00:12:26,240 using an extension called Python with this extension or plugin we get a number 536 00:12:26,240 --> 00:12:26,250 this extension or plugin we get a number 537 00:12:26,250 --> 00:12:28,699 this extension or plugin we get a number of features such as linting which 538 00:12:28,699 --> 00:12:28,709 of features such as linting which 539 00:12:28,709 --> 00:12:31,190 of features such as linting which basically means analyzing our code for 540 00:12:31,190 --> 00:12:31,200 basically means analyzing our code for 541 00:12:31,200 --> 00:12:32,300 basically means analyzing our code for potential errors 542 00:12:32,300 --> 00:12:32,310 potential errors 543 00:12:32,310 --> 00:12:35,030 potential errors you also get debugging which involves 544 00:12:35,030 --> 00:12:35,040 you also get debugging which involves 545 00:12:35,040 --> 00:12:37,639 you also get debugging which involves finding and fixing errors we'll look at 546 00:12:37,639 --> 00:12:37,649 finding and fixing errors we'll look at 547 00:12:37,649 --> 00:12:39,650 finding and fixing errors we'll look at this later in the course we also get 548 00:12:39,650 --> 00:12:39,660 this later in the course we also get 549 00:12:39,660 --> 00:12:42,470 this later in the course we also get auto completion which basically helps us 550 00:12:42,470 --> 00:12:42,480 auto completion which basically helps us 551 00:12:42,480 --> 00:12:44,420 auto completion which basically helps us write code faster so we don't have to 552 00:12:44,420 --> 00:12:44,430 write code faster so we don't have to 553 00:12:44,430 --> 00:12:46,610 write code faster so we don't have to type every character we get code 554 00:12:46,610 --> 00:12:46,620 type every character we get code 555 00:12:46,620 --> 00:12:48,889 type every character we get code formatting which is all about making our 556 00:12:48,889 --> 00:12:48,899 formatting which is all about making our 557 00:12:48,899 --> 00:12:51,410 formatting which is all about making our code clean and readable just like how we 558 00:12:51,410 --> 00:12:51,420 code clean and readable just like how we 559 00:12:51,420 --> 00:12:54,889 code clean and readable just like how we format our articles newspapers books to 560 00:12:54,889 --> 00:12:54,899 format our articles newspapers books to 561 00:12:54,899 --> 00:12:57,620 format our articles newspapers books to make them clean and readable we get unit 562 00:12:57,620 --> 00:12:57,630 make them clean and readable we get unit 563 00:12:57,630 --> 00:12:59,750 make them clean and readable we get unit testing which involves writing a bunch 564 00:12:59,750 --> 00:12:59,760 testing which involves writing a bunch 565 00:12:59,760 --> 00:13:02,269 testing which involves writing a bunch of tests for our code we can run these 566 00:13:02,269 --> 00:13:02,279 of tests for our code we can run these 567 00:13:02,279 --> 00:13:04,730 of tests for our code we can run these tests in an automated fashion to make 568 00:13:04,730 --> 00:13:04,740 tests in an automated fashion to make 569 00:13:04,740 --> 00:13:07,280 tests in an automated fashion to make sure our code is behaving correctly and 570 00:13:07,280 --> 00:13:07,290 sure our code is behaving correctly and 571 00:13:07,290 --> 00:13:10,180 sure our code is behaving correctly and finally we get code snippets which are 572 00:13:10,180 --> 00:13:10,190 finally we get code snippets which are 573 00:13:10,190 --> 00:13:12,710 finally we get code snippets which are reusable code blocks that we can quickly 574 00:13:12,710 --> 00:13:12,720 reusable code blocks that we can quickly 575 00:13:12,720 --> 00:13:14,630 reusable code blocks that we can quickly generate so we don't have to type them 576 00:13:14,630 --> 00:13:14,640 generate so we don't have to type them 577 00:13:14,640 --> 00:13:16,430 generate so we don't have to type them all by hand now don't worry about 578 00:13:16,430 --> 00:13:16,440 all by hand now don't worry about 579 00:13:16,440 --> 00:13:18,680 all by hand now don't worry about memorizing any of these as we go through 580 00:13:18,680 --> 00:13:18,690 memorizing any of these as we go through 581 00:13:18,690 --> 00:13:19,850 memorizing any of these as we go through the course you're going to learn about 582 00:13:19,850 --> 00:13:19,860 the course you're going to learn about 583 00:13:19,860 --> 00:13:23,120 the course you're going to learn about these features now here in vs code on 584 00:13:23,120 --> 00:13:23,130 these features now here in vs code on 585 00:13:23,130 --> 00:13:26,900 these features now here in vs code on the left side click this icon this opens 586 00:13:26,900 --> 00:13:26,910 the left side click this icon this opens 587 00:13:26,910 --> 00:13:28,880 the left side click this icon this opens the extensions tab so these are the 588 00:13:28,880 --> 00:13:28,890 the extensions tab so these are the 589 00:13:28,890 --> 00:13:31,220 the extensions tab so these are the extensions that we can install in vs 590 00:13:31,220 --> 00:13:31,230 extensions that we can install in vs 591 00:13:31,230 --> 00:13:32,440 extensions that we can install in vs code to bring in additional 592 00:13:32,440 --> 00:13:32,450 code to bring in additional 593 00:13:32,450 --> 00:13:35,329 code to bring in additional functionality here under the recommend 594 00:13:35,329 --> 00:13:35,339 functionality here under the recommend 595 00:13:35,339 --> 00:13:37,639 functionality here under the recommend the tab you can see the python extension 596 00:13:37,639 --> 00:13:37,649 the tab you can see the python extension 597 00:13:37,649 --> 00:13:41,180 the tab you can see the python extension if you don't see this simply type Python 598 00:13:41,180 --> 00:13:41,190 if you don't see this simply type Python 599 00:13:41,190 --> 00:13:42,930 if you don't see this simply type Python here on the top 600 00:13:42,930 --> 00:13:42,940 here on the top 601 00:13:42,940 --> 00:13:45,990 here on the top and here's the extension to go ahead and 602 00:13:45,990 --> 00:13:46,000 and here's the extension to go ahead and 603 00:13:46,000 --> 00:13:48,870 and here's the extension to go ahead and install this and then you'll have to 604 00:13:48,870 --> 00:13:48,880 install this and then you'll have to 605 00:13:48,880 --> 00:13:49,710 install this and then you'll have to reload 606 00:13:49,710 --> 00:13:49,720 reload 607 00:13:49,720 --> 00:13:53,350 reload yes code 608 00:13:53,350 --> 00:13:53,360 609 00:13:53,360 --> 00:13:55,419 now here on the bottom right corner you 610 00:13:55,419 --> 00:13:55,429 now here on the bottom right corner you 611 00:13:55,429 --> 00:13:58,269 now here on the bottom right corner you can see this message linter pilant is 612 00:13:58,269 --> 00:13:58,279 can see this message linter pilant is 613 00:13:58,279 --> 00:14:00,729 can see this message linter pilant is not in stock so as I told you before 614 00:14:00,729 --> 00:14:00,739 not in stock so as I told you before 615 00:14:00,739 --> 00:14:03,100 not in stock so as I told you before linting is about finding potential 616 00:14:03,100 --> 00:14:03,110 linting is about finding potential 617 00:14:03,110 --> 00:14:06,100 linting is about finding potential errors in our code linter is a program 618 00:14:06,100 --> 00:14:06,110 errors in our code linter is a program 619 00:14:06,110 --> 00:14:08,530 errors in our code linter is a program or a tool that analyzes our code and 620 00:14:08,530 --> 00:14:08,540 or a tool that analyzes our code and 621 00:14:08,540 --> 00:14:11,109 or a tool that analyzes our code and finds these potential problems now for 622 00:14:11,109 --> 00:14:11,119 finds these potential problems now for 623 00:14:11,119 --> 00:14:13,329 finds these potential problems now for Python there are several interceptor 624 00:14:13,329 --> 00:14:13,339 Python there are several interceptor 625 00:14:13,339 --> 00:14:16,090 Python there are several interceptor pilant is one of the most popular ones 626 00:14:16,090 --> 00:14:16,100 pilant is one of the most popular ones 627 00:14:16,100 --> 00:14:18,549 pilant is one of the most popular ones that this Python extension uses by 628 00:14:18,549 --> 00:14:18,559 that this Python extension uses by 629 00:14:18,559 --> 00:14:20,499 that this Python extension uses by default so we need to go ahead and 630 00:14:20,499 --> 00:14:20,509 default so we need to go ahead and 631 00:14:20,509 --> 00:14:23,530 default so we need to go ahead and install pylons as well now to do this 632 00:14:23,530 --> 00:14:23,540 install pylons as well now to do this 633 00:14:23,540 --> 00:14:26,049 install pylons as well now to do this first we need to change our Python 634 00:14:26,049 --> 00:14:26,059 first we need to change our Python 635 00:14:26,059 --> 00:14:27,879 first we need to change our Python environment so if you look here on the 636 00:14:27,879 --> 00:14:27,889 environment so if you look here on the 637 00:14:27,889 --> 00:14:29,859 environment so if you look here on the bottom left corner you can see the 638 00:14:29,859 --> 00:14:29,869 bottom left corner you can see the 639 00:14:29,869 --> 00:14:31,989 bottom left corner you can see the current python that is used in vs code 640 00:14:31,989 --> 00:14:31,999 current python that is used in vs code 641 00:14:31,999 --> 00:14:35,439 current python that is used in vs code that is python 2 point 6 point 9 on my 642 00:14:35,439 --> 00:14:35,449 that is python 2 point 6 point 9 on my 643 00:14:35,449 --> 00:14:35,979 that is python 2 point 6 point 9 on my machine 644 00:14:35,979 --> 00:14:35,989 machine 645 00:14:35,989 --> 00:14:37,539 machine chances are you see a different version 646 00:14:37,539 --> 00:14:37,549 chances are you see a different version 647 00:14:37,549 --> 00:14:41,590 chances are you see a different version here so click here and in this list make 648 00:14:41,590 --> 00:14:41,600 here so click here and in this list make 649 00:14:41,600 --> 00:14:46,660 here so click here and in this list make sure to select python 3 point 7 so this 650 00:14:46,660 --> 00:14:46,670 sure to select python 3 point 7 so this 651 00:14:46,670 --> 00:14:48,609 sure to select python 3 point 7 so this changes our Python environment to Python 652 00:14:48,609 --> 00:14:48,619 changes our Python environment to Python 653 00:14:48,619 --> 00:14:52,479 changes our Python environment to Python 3 point 7 and then we can install pilant 654 00:14:52,479 --> 00:14:52,489 3 point 7 and then we can install pilant 655 00:14:52,489 --> 00:14:57,429 3 point 7 and then we can install pilant by clicking this button ok pilant is 656 00:14:57,429 --> 00:14:57,439 by clicking this button ok pilant is 657 00:14:57,439 --> 00:14:59,530 by clicking this button ok pilant is installed beautiful in the next lecture 658 00:14:59,530 --> 00:14:59,540 installed beautiful in the next lecture 659 00:14:59,540 --> 00:15:09,790 installed beautiful in the next lecture I will show you how linting works 660 00:15:09,790 --> 00:15:09,800 661 00:15:09,800 --> 00:15:11,870 in this lecture I'm gonna show you 662 00:15:11,870 --> 00:15:11,880 in this lecture I'm gonna show you 663 00:15:11,880 --> 00:15:14,570 in this lecture I'm gonna show you linting and action so let's start by 664 00:15:14,570 --> 00:15:14,580 linting and action so let's start by 665 00:15:14,580 --> 00:15:16,880 linting and action so let's start by writing some invalid code like this 666 00:15:16,880 --> 00:15:16,890 writing some invalid code like this 667 00:15:16,890 --> 00:15:20,810 writing some invalid code like this print space with no parentheses and then 668 00:15:20,810 --> 00:15:20,820 print space with no parentheses and then 669 00:15:20,820 --> 00:15:24,350 print space with no parentheses and then hello work earlier I told you that print 670 00:15:24,350 --> 00:15:24,360 hello work earlier I told you that print 671 00:15:24,360 --> 00:15:26,570 hello work earlier I told you that print is a built-in function and whenever you 672 00:15:26,570 --> 00:15:26,580 is a built-in function and whenever you 673 00:15:26,580 --> 00:15:28,490 is a built-in function and whenever you want to use or call a function you 674 00:15:28,490 --> 00:15:28,500 want to use or call a function you 675 00:15:28,500 --> 00:15:31,280 want to use or call a function you should always use parentheses now to be 676 00:15:31,280 --> 00:15:31,290 should always use parentheses now to be 677 00:15:31,290 --> 00:15:33,230 should always use parentheses now to be more precise this is actually valid 678 00:15:33,230 --> 00:15:33,240 more precise this is actually valid 679 00:15:33,240 --> 00:15:35,390 more precise this is actually valid Python 2 code but because we're using 680 00:15:35,390 --> 00:15:35,400 Python 2 code but because we're using 681 00:15:35,400 --> 00:15:38,690 Python 2 code but because we're using Python 3 here this is invalid code from 682 00:15:38,690 --> 00:15:38,700 Python 3 here this is invalid code from 683 00:15:38,700 --> 00:15:41,570 Python 3 here this is invalid code from Python 3 point of view so now when I 684 00:15:41,570 --> 00:15:41,580 Python 3 point of view so now when I 685 00:15:41,580 --> 00:15:44,780 Python 3 point of view so now when I save the changes you can see this red 686 00:15:44,780 --> 00:15:44,790 save the changes you can see this red 687 00:15:44,790 --> 00:15:47,050 save the changes you can see this red underline here let's hover our mouse 688 00:15:47,050 --> 00:15:47,060 underline here let's hover our mouse 689 00:15:47,060 --> 00:15:50,060 underline here let's hover our mouse over this underline you can see this 690 00:15:50,060 --> 00:15:50,070 over this underline you can see this 691 00:15:50,070 --> 00:15:52,400 over this underline you can see this tooltip it's coming from Pyland and 692 00:15:52,400 --> 00:15:52,410 tooltip it's coming from Pyland and 693 00:15:52,410 --> 00:15:54,290 tooltip it's coming from Pyland and here's the error message missing 694 00:15:54,290 --> 00:15:54,300 here's the error message missing 695 00:15:54,300 --> 00:15:57,260 here's the error message missing parentheses in call to print did you 696 00:15:57,260 --> 00:15:57,270 parentheses in call to print did you 697 00:15:57,270 --> 00:15:59,690 parentheses in call to print did you mean print with parentheses so this is 698 00:15:59,690 --> 00:15:59,700 mean print with parentheses so this is 699 00:15:59,700 --> 00:16:02,180 mean print with parentheses so this is the benefit of linting as you're writing 700 00:16:02,180 --> 00:16:02,190 the benefit of linting as you're writing 701 00:16:02,190 --> 00:16:04,250 the benefit of linting as you're writing code you can see potential problems in 702 00:16:04,250 --> 00:16:04,260 code you can see potential problems in 703 00:16:04,260 --> 00:16:06,500 code you can see potential problems in your code you don't have to wait to run 704 00:16:06,500 --> 00:16:06,510 your code you don't have to wait to run 705 00:16:06,510 --> 00:16:09,590 your code you don't have to wait to run your program to see these errors so now 706 00:16:09,590 --> 00:16:09,600 your program to see these errors so now 707 00:16:09,600 --> 00:16:14,000 your program to see these errors so now if we put parentheses here and save the 708 00:16:14,000 --> 00:16:14,010 if we put parentheses here and save the 709 00:16:14,010 --> 00:16:16,370 if we put parentheses here and save the changes you can see that red underline 710 00:16:16,370 --> 00:16:16,380 changes you can see that red underline 711 00:16:16,380 --> 00:16:20,230 changes you can see that red underline is gone let's look at another error 712 00:16:20,230 --> 00:16:20,240 is gone let's look at another error 713 00:16:20,240 --> 00:16:22,780 is gone let's look at another error let's type two plus and then save the 714 00:16:22,780 --> 00:16:22,790 let's type two plus and then save the 715 00:16:22,790 --> 00:16:23,380 let's type two plus and then save the changes 716 00:16:23,380 --> 00:16:23,390 changes 717 00:16:23,390 --> 00:16:26,170 changes earlier we run this code in Python 718 00:16:26,170 --> 00:16:26,180 earlier we run this code in Python 719 00:16:26,180 --> 00:16:29,350 earlier we run this code in Python interpreters interactive shell there 720 00:16:29,350 --> 00:16:29,360 interpreters interactive shell there 721 00:16:29,360 --> 00:16:33,010 interpreters interactive shell there we got a syntax or grammar error so if 722 00:16:33,010 --> 00:16:33,020 we got a syntax or grammar error so if 723 00:16:33,020 --> 00:16:34,930 we got a syntax or grammar error so if you hover your mouse here one more time 724 00:16:34,930 --> 00:16:34,940 you hover your mouse here one more time 725 00:16:34,940 --> 00:16:37,600 you hover your mouse here one more time you can see pylons is telling us that 726 00:16:37,600 --> 00:16:37,610 you can see pylons is telling us that 727 00:16:37,610 --> 00:16:40,060 you can see pylons is telling us that this is invalid syntax or invalid 728 00:16:40,060 --> 00:16:40,070 this is invalid syntax or invalid 729 00:16:40,070 --> 00:16:42,730 this is invalid syntax or invalid grammar it's like an incomplete sentence 730 00:16:42,730 --> 00:16:42,740 grammar it's like an incomplete sentence 731 00:16:42,740 --> 00:16:45,730 grammar it's like an incomplete sentence so this is linting in action now let me 732 00:16:45,730 --> 00:16:45,740 so this is linting in action now let me 733 00:16:45,740 --> 00:16:47,889 so this is linting in action now let me show you a couple useful shortcuts here 734 00:16:47,889 --> 00:16:47,899 show you a couple useful shortcuts here 735 00:16:47,899 --> 00:16:52,060 show you a couple useful shortcuts here on the top look at the View menu here we 736 00:16:52,060 --> 00:16:52,070 on the top look at the View menu here we 737 00:16:52,070 --> 00:16:54,699 on the top look at the View menu here we have this problems menu look at the 738 00:16:54,699 --> 00:16:54,709 have this problems menu look at the 739 00:16:54,709 --> 00:16:57,820 have this problems menu look at the shortcut on Mac is shift command and M 740 00:16:57,820 --> 00:16:57,830 shortcut on Mac is shift command and M 741 00:16:57,830 --> 00:17:01,060 shortcut on Mac is shift command and M on windows is probably shift control M 742 00:17:01,060 --> 00:17:01,070 on windows is probably shift control M 743 00:17:01,070 --> 00:17:03,639 on windows is probably shift control M so as you're working with vs code try to 744 00:17:03,639 --> 00:17:03,649 so as you're working with vs code try to 745 00:17:03,649 --> 00:17:05,710 so as you're working with vs code try to memorize these shortcuts because they 746 00:17:05,710 --> 00:17:05,720 memorize these shortcuts because they 747 00:17:05,720 --> 00:17:08,919 memorize these shortcuts because they really help you write code faster now 748 00:17:08,919 --> 00:17:08,929 really help you write code faster now 749 00:17:08,929 --> 00:17:11,620 really help you write code faster now let's take a look at these problems 750 00:17:11,620 --> 00:17:11,630 let's take a look at these problems 751 00:17:11,630 --> 00:17:15,010 let's take a look at these problems panel so this problems panel lists all 752 00:17:15,010 --> 00:17:15,020 panel so this problems panel lists all 753 00:17:15,020 --> 00:17:17,860 panel so this problems panel lists all the issues in your code in one place so 754 00:17:17,860 --> 00:17:17,870 the issues in your code in one place so 755 00:17:17,870 --> 00:17:19,480 the issues in your code in one place so if you have an application with multiple 756 00:17:19,480 --> 00:17:19,490 if you have an application with multiple 757 00:17:19,490 --> 00:17:21,939 if you have an application with multiple files this is really useful because some 758 00:17:21,939 --> 00:17:21,949 files this is really useful because some 759 00:17:21,949 --> 00:17:24,160 files this is really useful because some of those files may not currently be open 760 00:17:24,160 --> 00:17:24,170 of those files may not currently be open 761 00:17:24,170 --> 00:17:27,309 of those files may not currently be open so this linter Pyland will analyze all 762 00:17:27,309 --> 00:17:27,319 so this linter Pyland will analyze all 763 00:17:27,319 --> 00:17:29,830 so this linter Pyland will analyze all your files and if it finds any issues it 764 00:17:29,830 --> 00:17:29,840 your files and if it finds any issues it 765 00:17:29,840 --> 00:17:31,540 your files and if it finds any issues it will list them here in the problems 766 00:17:31,540 --> 00:17:31,550 will list them here in the problems 767 00:17:31,550 --> 00:17:33,820 will list them here in the problems panel now you can also put this on the 768 00:17:33,820 --> 00:17:33,830 panel now you can also put this on the 769 00:17:33,830 --> 00:17:36,490 panel now you can also put this on the right side of your screen so let's put 770 00:17:36,490 --> 00:17:36,500 right side of your screen so let's put 771 00:17:36,500 --> 00:17:39,790 right side of your screen so let's put it here so as you write code these 772 00:17:39,790 --> 00:17:39,800 it here so as you write code these 773 00:17:39,800 --> 00:17:42,310 it here so as you write code these problems will appear here now let's fix 774 00:17:42,310 --> 00:17:42,320 problems will appear here now let's fix 775 00:17:42,320 --> 00:17:44,740 problems will appear here now let's fix this issue so I'm gonna add three here 776 00:17:44,740 --> 00:17:44,750 this issue so I'm gonna add three here 777 00:17:44,750 --> 00:17:47,470 this issue so I'm gonna add three here save the changes and you can see the 778 00:17:47,470 --> 00:17:47,480 save the changes and you can see the 779 00:17:47,480 --> 00:17:49,870 save the changes and you can see the problem disappear and one last thing 780 00:17:49,870 --> 00:17:49,880 problem disappear and one last thing 781 00:17:49,880 --> 00:17:52,270 problem disappear and one last thing before we finish this lecture once again 782 00:17:52,270 --> 00:17:52,280 before we finish this lecture once again 783 00:17:52,280 --> 00:17:55,060 before we finish this lecture once again on the top let's go to the View menu the 784 00:17:55,060 --> 00:17:55,070 on the top let's go to the View menu the 785 00:17:55,070 --> 00:17:58,210 on the top let's go to the View menu the first item is command palette this is a 786 00:17:58,210 --> 00:17:58,220 first item is command palette this is a 787 00:17:58,220 --> 00:18:00,940 first item is command palette this is a very important feature in vs code once 788 00:18:00,940 --> 00:18:00,950 very important feature in vs code once 789 00:18:00,950 --> 00:18:03,010 very important feature in vs code once again look at the shortcut that is shift 790 00:18:03,010 --> 00:18:03,020 again look at the shortcut that is shift 791 00:18:03,020 --> 00:18:06,100 again look at the shortcut that is shift command and P on Mac or shift control P 792 00:18:06,100 --> 00:18:06,110 command and P on Mac or shift control P 793 00:18:06,110 --> 00:18:08,899 command and P on Mac or shift control P on Windows 794 00:18:08,899 --> 00:18:08,909 795 00:18:08,909 --> 00:18:10,489 this command palette you can execute 796 00:18:10,489 --> 00:18:10,499 this command palette you can execute 797 00:18:10,499 --> 00:18:13,580 this command palette you can execute various commands in vs Co if you type 798 00:18:13,580 --> 00:18:13,590 various commands in vs Co if you type 799 00:18:13,590 --> 00:18:16,339 various commands in vs Co if you type lint here you can see all commands 800 00:18:16,339 --> 00:18:16,349 lint here you can see all commands 801 00:18:16,349 --> 00:18:19,159 lint here you can see all commands related to linting as you can see all 802 00:18:19,159 --> 00:18:19,169 related to linting as you can see all 803 00:18:19,169 --> 00:18:21,830 related to linting as you can see all these commands are prefixed with Python 804 00:18:21,830 --> 00:18:21,840 these commands are prefixed with Python 805 00:18:21,840 --> 00:18:24,499 these commands are prefixed with Python because these commands come with a 806 00:18:24,499 --> 00:18:24,509 because these commands come with a 807 00:18:24,509 --> 00:18:26,180 because these commands come with a Python extension that we installed 808 00:18:26,180 --> 00:18:26,190 Python extension that we installed 809 00:18:26,190 --> 00:18:28,369 Python extension that we installed earlier so these are additional features 810 00:18:28,369 --> 00:18:28,379 earlier so these are additional features 811 00:18:28,379 --> 00:18:31,369 earlier so these are additional features available to us in vs code the first 812 00:18:31,369 --> 00:18:31,379 available to us in vs code the first 813 00:18:31,379 --> 00:18:35,149 available to us in vs code the first command here is select linter in this 814 00:18:35,149 --> 00:18:35,159 command here is select linter in this 815 00:18:35,159 --> 00:18:36,649 command here is select linter in this list you can see various linters 816 00:18:36,649 --> 00:18:36,659 list you can see various linters 817 00:18:36,659 --> 00:18:39,349 list you can see various linters available for pilot so as you're reading 818 00:18:39,349 --> 00:18:39,359 available for pilot so as you're reading 819 00:18:39,359 --> 00:18:41,599 available for pilot so as you're reading tutorials or talking to other people you 820 00:18:41,599 --> 00:18:41,609 tutorials or talking to other people you 821 00:18:41,609 --> 00:18:43,759 tutorials or talking to other people you will hear about linters such as flake 822 00:18:43,759 --> 00:18:43,769 will hear about linters such as flake 823 00:18:43,769 --> 00:18:47,629 will hear about linters such as flake ate my pie pep 8 and so on different 824 00:18:47,629 --> 00:18:47,639 ate my pie pep 8 and so on different 825 00:18:47,639 --> 00:18:49,789 ate my pie pep 8 and so on different developers prefer different linters I 826 00:18:49,789 --> 00:18:49,799 developers prefer different linters I 827 00:18:49,799 --> 00:18:52,849 developers prefer different linters I personally prefer pilant that is the 828 00:18:52,849 --> 00:18:52,859 personally prefer pilant that is the 829 00:18:52,859 --> 00:18:54,739 personally prefer pilant that is the most popular one and that's the default 830 00:18:54,739 --> 00:18:54,749 most popular one and that's the default 831 00:18:54,749 --> 00:18:57,680 most popular one and that's the default linter set and the Python extension of 832 00:18:57,680 --> 00:18:57,690 linter set and the Python extension of 833 00:18:57,690 --> 00:19:00,499 linter set and the Python extension of vs code if you're adventurous you can 834 00:19:00,499 --> 00:19:00,509 vs code if you're adventurous you can 835 00:19:00,509 --> 00:19:03,169 vs code if you're adventurous you can try using other linters on your own the 836 00:19:03,169 --> 00:19:03,179 try using other linters on your own the 837 00:19:03,179 --> 00:19:05,149 try using other linters on your own the difference between these linters is in 838 00:19:05,149 --> 00:19:05,159 difference between these linters is in 839 00:19:05,159 --> 00:19:08,419 difference between these linters is in how they find and report errors some 840 00:19:08,419 --> 00:19:08,429 how they find and report errors some 841 00:19:08,429 --> 00:19:10,279 how they find and report errors some error messages are more meaningful or 842 00:19:10,279 --> 00:19:10,289 error messages are more meaningful or 843 00:19:10,289 --> 00:19:12,109 error messages are more meaningful or more friendly the others are more 844 00:19:12,109 --> 00:19:12,119 more friendly the others are more 845 00:19:12,119 --> 00:19:15,499 more friendly the others are more ambiguous so that's all about linting in 846 00:19:15,499 --> 00:19:15,509 ambiguous so that's all about linting in 847 00:19:15,509 --> 00:19:16,940 ambiguous so that's all about linting in the next lecture we'll talk about 848 00:19:16,940 --> 00:19:16,950 the next lecture we'll talk about 849 00:19:16,950 --> 00:19:25,770 the next lecture we'll talk about formatting code 850 00:19:25,770 --> 00:19:25,780 851 00:19:25,780 --> 00:19:28,600 in Python community we have a bunch of 852 00:19:28,600 --> 00:19:28,610 in Python community we have a bunch of 853 00:19:28,610 --> 00:19:31,570 in Python community we have a bunch of documents called Python enhancement 854 00:19:31,570 --> 00:19:31,580 documents called Python enhancement 855 00:19:31,580 --> 00:19:34,990 documents called Python enhancement proposals or peps here on Google if you 856 00:19:34,990 --> 00:19:35,000 proposals or peps here on Google if you 857 00:19:35,000 --> 00:19:38,680 proposals or peps here on Google if you search for Python peps you can see the 858 00:19:38,680 --> 00:19:38,690 search for Python peps you can see the 859 00:19:38,690 --> 00:19:41,710 search for Python peps you can see the list of all these paps under python.org 860 00:19:41,710 --> 00:19:41,720 list of all these paps under python.org 861 00:19:41,720 --> 00:19:45,400 list of all these paps under python.org slash dev slash paps let's have a quick 862 00:19:45,400 --> 00:19:45,410 slash dev slash paps let's have a quick 863 00:19:45,410 --> 00:19:47,980 slash dev slash paps let's have a quick look here 864 00:19:47,980 --> 00:19:47,990 look here 865 00:19:47,990 --> 00:19:50,380 look here so here are the paps you can see each 866 00:19:50,380 --> 00:19:50,390 so here are the paps you can see each 867 00:19:50,390 --> 00:19:53,710 so here are the paps you can see each PAP has a number and a title the one 868 00:19:53,710 --> 00:19:53,720 PAP has a number and a title the one 869 00:19:53,720 --> 00:19:55,990 PAP has a number and a title the one that is very popular amongst Python 870 00:19:55,990 --> 00:19:56,000 that is very popular amongst Python 871 00:19:56,000 --> 00:19:58,690 that is very popular amongst Python developers is pep 8 which is a style 872 00:19:58,690 --> 00:19:58,700 developers is pep 8 which is a style 873 00:19:58,700 --> 00:20:01,570 developers is pep 8 which is a style guide for Python code a style guide is 874 00:20:01,570 --> 00:20:01,580 guide for Python code a style guide is 875 00:20:01,580 --> 00:20:03,640 guide for Python code a style guide is basically a document that defines a 876 00:20:03,640 --> 00:20:03,650 basically a document that defines a 877 00:20:03,650 --> 00:20:05,830 basically a document that defines a bunch of rules for formatting and 878 00:20:05,830 --> 00:20:05,840 bunch of rules for formatting and 879 00:20:05,840 --> 00:20:08,350 bunch of rules for formatting and styling our code if you follow these 880 00:20:08,350 --> 00:20:08,360 styling our code if you follow these 881 00:20:08,360 --> 00:20:10,330 styling our code if you follow these conventions the code that you write will 882 00:20:10,330 --> 00:20:10,340 conventions the code that you write will 883 00:20:10,340 --> 00:20:12,400 conventions the code that you write will end up being consistent with other 884 00:20:12,400 --> 00:20:12,410 end up being consistent with other 885 00:20:12,410 --> 00:20:14,830 end up being consistent with other people's code now if you have time you 886 00:20:14,830 --> 00:20:14,840 people's code now if you have time you 887 00:20:14,840 --> 00:20:17,110 people's code now if you have time you can go ahead and read this PAP 8 888 00:20:17,110 --> 00:20:17,120 can go ahead and read this PAP 8 889 00:20:17,120 --> 00:20:19,210 can go ahead and read this PAP 8 documentation but if not don't worry 890 00:20:19,210 --> 00:20:19,220 documentation but if not don't worry 891 00:20:19,220 --> 00:20:21,220 documentation but if not don't worry because throughout this course I'm gonna 892 00:20:21,220 --> 00:20:21,230 because throughout this course I'm gonna 893 00:20:21,230 --> 00:20:24,340 because throughout this course I'm gonna explain the key things in pep 8 in this 894 00:20:24,340 --> 00:20:24,350 explain the key things in pep 8 in this 895 00:20:24,350 --> 00:20:26,170 explain the key things in pep 8 in this lecture I'm gonna show you a tool that 896 00:20:26,170 --> 00:20:26,180 lecture I'm gonna show you a tool that 897 00:20:26,180 --> 00:20:28,360 lecture I'm gonna show you a tool that helps you automatically format your code 898 00:20:28,360 --> 00:20:28,370 helps you automatically format your code 899 00:20:28,370 --> 00:20:31,100 helps you automatically format your code according to pap 8 900 00:20:31,100 --> 00:20:31,110 according to pap 8 901 00:20:31,110 --> 00:20:33,350 according to pap 8 so back in vs code let's write some 902 00:20:33,350 --> 00:20:33,360 so back in vs code let's write some 903 00:20:33,360 --> 00:20:37,370 so back in vs code let's write some Python code x equals one here I'm 904 00:20:37,370 --> 00:20:37,380 Python code x equals one here I'm 905 00:20:37,380 --> 00:20:39,169 Python code x equals one here I'm declaring a variable and setting it to 906 00:20:39,169 --> 00:20:39,179 declaring a variable and setting it to 907 00:20:39,179 --> 00:20:40,580 declaring a variable and setting it to one if you're not familiar with 908 00:20:40,580 --> 00:20:40,590 one if you're not familiar with 909 00:20:40,590 --> 00:20:42,049 one if you're not familiar with variables don't worry 910 00:20:42,049 --> 00:20:42,059 variables don't worry 911 00:20:42,059 --> 00:20:43,490 variables don't worry in the next section you're gonna learn 912 00:20:43,490 --> 00:20:43,500 in the next section you're gonna learn 913 00:20:43,500 --> 00:20:46,519 in the next section you're gonna learn about them so according to pep 8 this 914 00:20:46,519 --> 00:20:46,529 about them so according to pep 8 this 915 00:20:46,529 --> 00:20:49,070 about them so according to pep 8 this code is considered ugly because by 916 00:20:49,070 --> 00:20:49,080 code is considered ugly because by 917 00:20:49,080 --> 00:20:51,680 code is considered ugly because by convention we should add a space around 918 00:20:51,680 --> 00:20:51,690 convention we should add a space around 919 00:20:51,690 --> 00:20:54,529 convention we should add a space around this equal sign or the assignment 920 00:20:54,529 --> 00:20:54,539 this equal sign or the assignment 921 00:20:54,539 --> 00:20:56,899 this equal sign or the assignment operator now since you're starting out 922 00:20:56,899 --> 00:20:56,909 operator now since you're starting out 923 00:20:56,909 --> 00:20:58,580 operator now since you're starting out with Python you probably don't know 924 00:20:58,580 --> 00:20:58,590 with Python you probably don't know 925 00:20:58,590 --> 00:21:00,320 with Python you probably don't know these rules so let me show you a tool 926 00:21:00,320 --> 00:21:00,330 these rules so let me show you a tool 927 00:21:00,330 --> 00:21:02,389 these rules so let me show you a tool that helps you automatically format your 928 00:21:02,389 --> 00:21:02,399 that helps you automatically format your 929 00:21:02,399 --> 00:21:04,730 that helps you automatically format your code let's revert this back to its 930 00:21:04,730 --> 00:21:04,740 code let's revert this back to its 931 00:21:04,740 --> 00:21:07,669 code let's revert this back to its original state now we need to go back to 932 00:21:07,669 --> 00:21:07,679 original state now we need to go back to 933 00:21:07,679 --> 00:21:10,250 original state now we need to go back to the command palette remember so it's 934 00:21:10,250 --> 00:21:10,260 the command palette remember so it's 935 00:21:10,260 --> 00:21:12,740 the command palette remember so it's right here under view and the shortcut 936 00:21:12,740 --> 00:21:12,750 right here under view and the shortcut 937 00:21:12,750 --> 00:21:16,730 right here under view and the shortcut is shift command and P here if you 938 00:21:16,730 --> 00:21:16,740 is shift command and P here if you 939 00:21:16,740 --> 00:21:18,860 is shift command and P here if you search for format you can see this 940 00:21:18,860 --> 00:21:18,870 search for format you can see this 941 00:21:18,870 --> 00:21:21,860 search for format you can see this command format document the first time 942 00:21:21,860 --> 00:21:21,870 command format document the first time 943 00:21:21,870 --> 00:21:24,289 command format document the first time you execute this command you're going to 944 00:21:24,289 --> 00:21:24,299 you execute this command you're going to 945 00:21:24,299 --> 00:21:27,169 you execute this command you're going to see this message here formatter Auto 946 00:21:27,169 --> 00:21:27,179 see this message here formatter Auto 947 00:21:27,179 --> 00:21:30,049 see this message here formatter Auto kept 8 is not installed so there are a 948 00:21:30,049 --> 00:21:30,059 kept 8 is not installed so there are a 949 00:21:30,059 --> 00:21:31,970 kept 8 is not installed so there are a bunch of tools for formatting Python 950 00:21:31,970 --> 00:21:31,980 bunch of tools for formatting Python 951 00:21:31,980 --> 00:21:34,970 bunch of tools for formatting Python code the most popular one is auto kept 8 952 00:21:34,970 --> 00:21:34,980 code the most popular one is auto kept 8 953 00:21:34,980 --> 00:21:37,430 code the most popular one is auto kept 8 and this is the tool that this Python 954 00:21:37,430 --> 00:21:37,440 and this is the tool that this Python 955 00:21:37,440 --> 00:21:39,769 and this is the tool that this Python extension we installed uses to format 956 00:21:39,769 --> 00:21:39,779 extension we installed uses to format 957 00:21:39,779 --> 00:21:42,019 extension we installed uses to format our code so let's go ahead and install 958 00:21:42,019 --> 00:21:42,029 our code so let's go ahead and install 959 00:21:42,029 --> 00:21:47,570 our code so let's go ahead and install this good now one more time let's open 960 00:21:47,570 --> 00:21:47,580 this good now one more time let's open 961 00:21:47,580 --> 00:21:49,970 this good now one more time let's open up the command palette and execute 962 00:21:49,970 --> 00:21:49,980 up the command palette and execute 963 00:21:49,980 --> 00:21:53,810 up the command palette and execute format document see is tool 964 00:21:53,810 --> 00:21:53,820 format document see is tool 965 00:21:53,820 --> 00:21:55,789 format document see is tool automatically formats our code beautiful 966 00:21:55,789 --> 00:21:55,799 automatically formats our code beautiful 967 00:21:55,799 --> 00:21:58,639 automatically formats our code beautiful let's take a look at another example I'm 968 00:21:58,639 --> 00:21:58,649 let's take a look at another example I'm 969 00:21:58,649 --> 00:22:00,710 let's take a look at another example I'm going to declare another variable Y and 970 00:22:00,710 --> 00:22:00,720 going to declare another variable Y and 971 00:22:00,720 --> 00:22:03,529 going to declare another variable Y and set it to two and a variable with a long 972 00:22:03,529 --> 00:22:03,539 set it to two and a variable with a long 973 00:22:03,539 --> 00:22:06,950 set it to two and a variable with a long name like unit underlined price I'm set 974 00:22:06,950 --> 00:22:06,960 name like unit underlined price I'm set 975 00:22:06,960 --> 00:22:10,100 name like unit underlined price I'm set this to 3 now some developers have this 976 00:22:10,100 --> 00:22:10,110 this to 3 now some developers have this 977 00:22:10,110 --> 00:22:12,470 this to 3 now some developers have this habit of formatting their variable 978 00:22:12,470 --> 00:22:12,480 habit of formatting their variable 979 00:22:12,480 --> 00:22:15,710 habit of formatting their variable declarations like this so they put all 980 00:22:15,710 --> 00:22:15,720 declarations like this so they put all 981 00:22:15,720 --> 00:22:19,430 declarations like this so they put all these equal signs in the same column 982 00:22:19,430 --> 00:22:19,440 these equal signs in the same column 983 00:22:19,440 --> 00:22:21,860 these equal signs in the same column according to pepp 8 this is considered 984 00:22:21,860 --> 00:22:21,870 according to pepp 8 this is considered 985 00:22:21,870 --> 00:22:25,870 according to pepp 8 this is considered ugly so once again let's format our code 986 00:22:25,870 --> 00:22:25,880 ugly so once again let's format our code 987 00:22:25,880 --> 00:22:29,509 ugly so once again let's format our code that is better beautiful now let me show 988 00:22:29,509 --> 00:22:29,519 that is better beautiful now let me show 989 00:22:29,519 --> 00:22:31,820 that is better beautiful now let me show you a trick opening up this command 990 00:22:31,820 --> 00:22:31,830 you a trick opening up this command 991 00:22:31,830 --> 00:22:33,500 you a trick opening up this command palette and searching for format 992 00:22:33,500 --> 00:22:33,510 palette and searching for format 993 00:22:33,510 --> 00:22:35,720 palette and searching for format document every time is a little bit 994 00:22:35,720 --> 00:22:35,730 document every time is a little bit 995 00:22:35,730 --> 00:22:38,509 document every time is a little bit time-consuming so I want to show you how 996 00:22:38,509 --> 00:22:38,519 time-consuming so I want to show you how 997 00:22:38,519 --> 00:22:40,070 time-consuming so I want to show you how to have your file automatically 998 00:22:40,070 --> 00:22:40,080 to have your file automatically 999 00:22:40,080 --> 00:22:41,750 to have your file automatically formatted as soon as you save the 1000 00:22:41,750 --> 00:22:41,760 formatted as soon as you save the 1001 00:22:41,760 --> 00:22:43,110 formatted as soon as you save the changes 1002 00:22:43,110 --> 00:22:43,120 changes 1003 00:22:43,120 --> 00:22:45,680 changes on the top let's go to the code menu 1004 00:22:45,680 --> 00:22:45,690 on the top let's go to the code menu 1005 00:22:45,690 --> 00:22:51,180 on the top let's go to the code menu preferences and settings here in the 1006 00:22:51,180 --> 00:22:51,190 preferences and settings here in the 1007 00:22:51,190 --> 00:22:55,370 preferences and settings here in the search box search for format on save 1008 00:22:55,370 --> 00:22:55,380 search box search for format on save 1009 00:22:55,380 --> 00:22:58,500 search box search for format on save so we have this option editor format 1010 00:22:58,500 --> 00:22:58,510 so we have this option editor format 1011 00:22:58,510 --> 00:23:02,630 so we have this option editor format unsaved take this now back to app top I 1012 00:23:02,630 --> 00:23:02,640 unsaved take this now back to app top I 1013 00:23:02,640 --> 00:23:05,370 unsaved take this now back to app top I I'm gonna change the formatting of these 1014 00:23:05,370 --> 00:23:05,380 I'm gonna change the formatting of these 1015 00:23:05,380 --> 00:23:09,180 I'm gonna change the formatting of these lines make them really ugly now as soon 1016 00:23:09,180 --> 00:23:09,190 lines make them really ugly now as soon 1017 00:23:09,190 --> 00:23:12,270 lines make them really ugly now as soon as I save the changes you can see my 1018 00:23:12,270 --> 00:23:12,280 as I save the changes you can see my 1019 00:23:12,280 --> 00:23:22,149 as I save the changes you can see my code is reformatted beautiful 1020 00:23:22,149 --> 00:23:22,159 1021 00:23:22,159 --> 00:23:24,799 so you have learned that in order to run 1022 00:23:24,799 --> 00:23:24,809 so you have learned that in order to run 1023 00:23:24,809 --> 00:23:27,080 so you have learned that in order to run this Python program we'll have to open 1024 00:23:27,080 --> 00:23:27,090 this Python program we'll have to open 1025 00:23:27,090 --> 00:23:29,749 this Python program we'll have to open up the terminal window and run Python on 1026 00:23:29,749 --> 00:23:29,759 up the terminal window and run Python on 1027 00:23:29,759 --> 00:23:32,720 up the terminal window and run Python on windows or Python 3 on Mac and an app 1028 00:23:32,720 --> 00:23:32,730 windows or Python 3 on Mac and an app 1029 00:23:32,730 --> 00:23:36,139 windows or Python 3 on Mac and an app that pi this is a little bit tedious so 1030 00:23:36,139 --> 00:23:36,149 that pi this is a little bit tedious so 1031 00:23:36,149 --> 00:23:38,779 that pi this is a little bit tedious so let me show you a shortcut once again 1032 00:23:38,779 --> 00:23:38,789 let me show you a shortcut once again 1033 00:23:38,789 --> 00:23:41,419 let me show you a shortcut once again let's go to the extensions panel here 1034 00:23:41,419 --> 00:23:41,429 let's go to the extensions panel here 1035 00:23:41,429 --> 00:23:45,629 let's go to the extensions panel here search for code runner 1036 00:23:45,629 --> 00:23:45,639 1037 00:23:45,639 --> 00:23:47,310 there are multiple code runners out 1038 00:23:47,310 --> 00:23:47,320 there are multiple code runners out 1039 00:23:47,320 --> 00:23:49,499 there are multiple code runners out there the one that I'm talking about is 1040 00:23:49,499 --> 00:23:49,509 there the one that I'm talking about is 1041 00:23:49,509 --> 00:23:53,669 there the one that I'm talking about is this one with the yellow icon so go 1042 00:23:53,669 --> 00:23:53,679 this one with the yellow icon so go 1043 00:23:53,679 --> 00:23:56,669 this one with the yellow icon so go ahead and install this and then reload 1044 00:23:56,669 --> 00:23:56,679 ahead and install this and then reload 1045 00:23:56,679 --> 00:24:01,229 ahead and install this and then reload yes code now instead of opening up the 1046 00:24:01,229 --> 00:24:01,239 yes code now instead of opening up the 1047 00:24:01,239 --> 00:24:03,599 yes code now instead of opening up the terminal and manually typing Python 1048 00:24:03,599 --> 00:24:03,609 terminal and manually typing Python 1049 00:24:03,609 --> 00:24:06,659 terminal and manually typing Python after pi all you have to do is to press 1050 00:24:06,659 --> 00:24:06,669 after pi all you have to do is to press 1051 00:24:06,669 --> 00:24:10,169 after pi all you have to do is to press ctrl alt and in 1052 00:24:10,169 --> 00:24:10,179 ctrl alt and in 1053 00:24:10,179 --> 00:24:12,419 ctrl alt and in you can see the output here beautiful 1054 00:24:12,419 --> 00:24:12,429 you can see the output here beautiful 1055 00:24:12,429 --> 00:24:14,519 you can see the output here beautiful just be aware of that if you make any 1056 00:24:14,519 --> 00:24:14,529 just be aware of that if you make any 1057 00:24:14,529 --> 00:24:16,980 just be aware of that if you make any changes you'll have to save the changes 1058 00:24:16,980 --> 00:24:16,990 changes you'll have to save the changes 1059 00:24:16,990 --> 00:24:19,139 changes you'll have to save the changes before using this shortcut otherwise 1060 00:24:19,139 --> 00:24:19,149 before using this shortcut otherwise 1061 00:24:19,149 --> 00:24:21,299 before using this shortcut otherwise you're going to see the old result now 1062 00:24:21,299 --> 00:24:21,309 you're going to see the old result now 1063 00:24:21,309 --> 00:24:24,149 you're going to see the old result now there is a tiny problem here so you can 1064 00:24:24,149 --> 00:24:24,159 there is a tiny problem here so you can 1065 00:24:24,159 --> 00:24:26,639 there is a tiny problem here so you can see this is the command that is executed 1066 00:24:26,639 --> 00:24:26,649 see this is the command that is executed 1067 00:24:26,649 --> 00:24:29,789 see this is the command that is executed to run this Python program so by default 1068 00:24:29,789 --> 00:24:29,799 to run this Python program so by default 1069 00:24:29,799 --> 00:24:32,759 to run this Python program so by default this command is using Python - U and 1070 00:24:32,759 --> 00:24:32,769 this command is using Python - U and 1071 00:24:32,769 --> 00:24:35,369 this command is using Python - U and here is the name of our file if you're 1072 00:24:35,369 --> 00:24:35,379 here is the name of our file if you're 1073 00:24:35,379 --> 00:24:36,029 here is the name of our file if you're on Windows 1074 00:24:36,029 --> 00:24:36,039 on Windows 1075 00:24:36,039 --> 00:24:37,950 on Windows that's perfectly fine but if you're on 1076 00:24:37,950 --> 00:24:37,960 that's perfectly fine but if you're on 1077 00:24:37,960 --> 00:24:40,350 that's perfectly fine but if you're on Mac you know that Python refers to 1078 00:24:40,350 --> 00:24:40,360 Mac you know that Python refers to 1079 00:24:40,360 --> 00:24:42,989 Mac you know that Python refers to Python - here we want to change this to 1080 00:24:42,989 --> 00:24:42,999 Python - here we want to change this to 1081 00:24:42,999 --> 00:24:46,889 Python - here we want to change this to Python 3 this is very easy once again on 1082 00:24:46,889 --> 00:24:46,899 Python 3 this is very easy once again on 1083 00:24:46,899 --> 00:24:49,499 Python 3 this is very easy once again on the top under the code menu let's go to 1084 00:24:49,499 --> 00:24:49,509 the top under the code menu let's go to 1085 00:24:49,509 --> 00:24:54,690 the top under the code menu let's go to preferences settings and then here 1086 00:24:54,690 --> 00:24:54,700 preferences settings and then here 1087 00:24:54,700 --> 00:24:57,840 preferences settings and then here under this dot go to open settings that 1088 00:24:57,840 --> 00:24:57,850 under this dot go to open settings that 1089 00:24:57,850 --> 00:24:59,770 under this dot go to open settings that JSON 1090 00:24:59,770 --> 00:24:59,780 JSON 1091 00:24:59,780 --> 00:25:03,160 JSON now here in the search bar type code 1092 00:25:03,160 --> 00:25:03,170 now here in the search bar type code 1093 00:25:03,170 --> 00:25:08,830 now here in the search bar type code - runner dot executors map so these are 1094 00:25:08,830 --> 00:25:08,840 - runner dot executors map so these are 1095 00:25:08,840 --> 00:25:11,260 - runner dot executors map so these are the default settings used by this code 1096 00:25:11,260 --> 00:25:11,270 the default settings used by this code 1097 00:25:11,270 --> 00:25:13,300 the default settings used by this code runner extension you can see this 1098 00:25:13,300 --> 00:25:13,310 runner extension you can see this 1099 00:25:13,310 --> 00:25:15,850 runner extension you can see this extension support executing code in a 1100 00:25:15,850 --> 00:25:15,860 extension support executing code in a 1101 00:25:15,860 --> 00:25:18,070 extension support executing code in a lot of languages like JavaScript Java 1102 00:25:18,070 --> 00:25:18,080 lot of languages like JavaScript Java 1103 00:25:18,080 --> 00:25:21,820 lot of languages like JavaScript Java and so on now if you scroll down here we 1104 00:25:21,820 --> 00:25:21,830 and so on now if you scroll down here we 1105 00:25:21,830 --> 00:25:24,070 and so on now if you scroll down here we can see Python and in front of that you 1106 00:25:24,070 --> 00:25:24,080 can see Python and in front of that you 1107 00:25:24,080 --> 00:25:25,900 can see Python and in front of that you can see the command that is used to 1108 00:25:25,900 --> 00:25:25,910 can see the command that is used to 1109 00:25:25,910 --> 00:25:28,120 can see the command that is used to execute Python code we need to change 1110 00:25:28,120 --> 00:25:28,130 execute Python code we need to change 1111 00:25:28,130 --> 00:25:30,370 execute Python code we need to change this however we cannot change the 1112 00:25:30,370 --> 00:25:30,380 this however we cannot change the 1113 00:25:30,380 --> 00:25:32,320 this however we cannot change the default settings we should change the 1114 00:25:32,320 --> 00:25:32,330 default settings we should change the 1115 00:25:32,330 --> 00:25:35,470 default settings we should change the user settings so on the right side after 1116 00:25:35,470 --> 00:25:35,480 user settings so on the right side after 1117 00:25:35,480 --> 00:25:37,710 user settings so on the right side after the last setting type a comma and then 1118 00:25:37,710 --> 00:25:37,720 the last setting type a comma and then 1119 00:25:37,720 --> 00:25:42,360 the last setting type a comma and then in quotes type code - runner dot 1120 00:25:42,360 --> 00:25:42,370 in quotes type code - runner dot 1121 00:25:42,370 --> 00:25:46,330 in quotes type code - runner dot executors map and then press enter this 1122 00:25:46,330 --> 00:25:46,340 executors map and then press enter this 1123 00:25:46,340 --> 00:25:48,160 executors map and then press enter this will automatically copy all the settings 1124 00:25:48,160 --> 00:25:48,170 will automatically copy all the settings 1125 00:25:48,170 --> 00:25:51,100 will automatically copy all the settings on the left side to the right side now 1126 00:25:51,100 --> 00:25:51,110 on the left side to the right side now 1127 00:25:51,110 --> 00:25:54,310 on the left side to the right side now we can easily change one of this 1128 00:25:54,310 --> 00:25:54,320 we can easily change one of this 1129 00:25:54,320 --> 00:25:57,460 we can easily change one of this so here's Python let's change the 1130 00:25:57,460 --> 00:25:57,470 so here's Python let's change the 1131 00:25:57,470 --> 00:26:01,930 so here's Python let's change the command to Python 3 you only have to do 1132 00:26:01,930 --> 00:26:01,940 command to Python 3 you only have to do 1133 00:26:01,940 --> 00:26:04,150 command to Python 3 you only have to do this if you're on Mac and by the way 1134 00:26:04,150 --> 00:26:04,160 this if you're on Mac and by the way 1135 00:26:04,160 --> 00:26:06,040 this if you're on Mac and by the way sorry if I have mentioned Windows and 1136 00:26:06,040 --> 00:26:06,050 sorry if I have mentioned Windows and 1137 00:26:06,050 --> 00:26:07,660 sorry if I have mentioned Windows and Mac a few times throughout this course 1138 00:26:07,660 --> 00:26:07,670 Mac a few times throughout this course 1139 00:26:07,670 --> 00:26:09,520 Mac a few times throughout this course that's pretty much it we are not going 1140 00:26:09,520 --> 00:26:09,530 that's pretty much it we are not going 1141 00:26:09,530 --> 00:26:11,320 that's pretty much it we are not going to differentiate between Windows and Mac 1142 00:26:11,320 --> 00:26:11,330 to differentiate between Windows and Mac 1143 00:26:11,330 --> 00:26:13,720 to differentiate between Windows and Mac in the future so save the changes and 1144 00:26:13,720 --> 00:26:13,730 in the future so save the changes and 1145 00:26:13,730 --> 00:26:21,630 in the future so save the changes and we're done 1146 00:26:21,630 --> 00:26:21,640 1147 00:26:21,640 --> 00:26:24,460 so I've got a few questions for you guys 1148 00:26:24,460 --> 00:26:24,470 so I've got a few questions for you guys 1149 00:26:24,470 --> 00:26:25,780 so I've got a few questions for you guys I want to see if you have been really 1150 00:26:25,780 --> 00:26:25,790 I want to see if you have been really 1151 00:26:25,790 --> 00:26:27,340 I want to see if you have been really paying attention to this video or not 1152 00:26:27,340 --> 00:26:27,350 paying attention to this video or not 1153 00:26:27,350 --> 00:26:30,220 paying attention to this video or not you better have so here is the first 1154 00:26:30,220 --> 00:26:30,230 you better have so here is the first 1155 00:26:30,230 --> 00:26:32,620 you better have so here is the first question for each question I want you to 1156 00:26:32,620 --> 00:26:32,630 question for each question I want you to 1157 00:26:32,630 --> 00:26:34,510 question for each question I want you to pause the video think about the answer 1158 00:26:34,510 --> 00:26:34,520 pause the video think about the answer 1159 00:26:34,520 --> 00:26:36,190 pause the video think about the answer for a few seconds when you're ready 1160 00:26:36,190 --> 00:26:36,200 for a few seconds when you're ready 1161 00:26:36,200 --> 00:26:38,590 for a few seconds when you're ready continue watching so here's the first 1162 00:26:38,590 --> 00:26:38,600 continue watching so here's the first 1163 00:26:38,600 --> 00:26:41,850 continue watching so here's the first question what is an expression an 1164 00:26:41,850 --> 00:26:41,860 question what is an expression an 1165 00:26:41,860 --> 00:26:44,409 question what is an expression an expression is a piece of code that 1166 00:26:44,409 --> 00:26:44,419 expression is a piece of code that 1167 00:26:44,419 --> 00:26:47,860 expression is a piece of code that produces a value here's an example of an 1168 00:26:47,860 --> 00:26:47,870 produces a value here's an example of an 1169 00:26:47,870 --> 00:26:49,900 produces a value here's an example of an expression what do you think is the 1170 00:26:49,900 --> 00:26:49,910 expression what do you think is the 1171 00:26:49,910 --> 00:26:53,320 expression what do you think is the value of this expression well here we 1172 00:26:53,320 --> 00:26:53,330 value of this expression well here we 1173 00:26:53,330 --> 00:26:56,260 value of this expression well here we have this string we're multiplying this 1174 00:26:56,260 --> 00:26:56,270 have this string we're multiplying this 1175 00:26:56,270 --> 00:26:59,890 have this string we're multiplying this by 3 so the result will be a string of 1176 00:26:59,890 --> 00:26:59,900 by 3 so the result will be a string of 1177 00:26:59,900 --> 00:27:03,850 by 3 so the result will be a string of three asterisks like this here's another 1178 00:27:03,850 --> 00:27:03,860 three asterisks like this here's another 1179 00:27:03,860 --> 00:27:07,840 three asterisks like this here's another question what is a syntax error a syntax 1180 00:27:07,840 --> 00:27:07,850 question what is a syntax error a syntax 1181 00:27:07,850 --> 00:27:10,030 question what is a syntax error a syntax error is a kind of error that is due to 1182 00:27:10,030 --> 00:27:10,040 error is a kind of error that is due to 1183 00:27:10,040 --> 00:27:12,850 error is a kind of error that is due to bad syntax or bad grammar in the code 1184 00:27:12,850 --> 00:27:12,860 bad syntax or bad grammar in the code 1185 00:27:12,860 --> 00:27:15,970 bad syntax or bad grammar in the code and finally the last question what does 1186 00:27:15,970 --> 00:27:15,980 and finally the last question what does 1187 00:27:15,980 --> 00:27:19,600 and finally the last question what does a linter do a linter is a tool that 1188 00:27:19,600 --> 00:27:19,610 a linter do a linter is a tool that 1189 00:27:19,610 --> 00:27:21,820 a linter do a linter is a tool that checks our code or potential errors 1190 00:27:21,820 --> 00:27:21,830 checks our code or potential errors 1191 00:27:21,830 --> 00:27:24,970 checks our code or potential errors mostly in the category of seen tactical 1192 00:27:24,970 --> 00:27:24,980 mostly in the category of seen tactical 1193 00:27:24,980 --> 00:27:26,740 mostly in the category of seen tactical errors so if you have grand medical 1194 00:27:26,740 --> 00:27:26,750 errors so if you have grand medical 1195 00:27:26,750 --> 00:27:28,810 errors so if you have grand medical issues in our code the linker will tell 1196 00:27:28,810 --> 00:27:28,820 issues in our code the linker will tell 1197 00:27:28,820 --> 00:27:31,390 issues in our code the linker will tell us before running our program okay 1198 00:27:31,390 --> 00:27:31,400 us before running our program okay 1199 00:27:31,400 --> 00:27:33,100 us before running our program okay that's it for now if you like more 1200 00:27:33,100 --> 00:27:33,110 that's it for now if you like more 1201 00:27:33,110 --> 00:27:35,770 that's it for now if you like more quizzes and programming exercises look 1202 00:27:35,770 --> 00:27:35,780 quizzes and programming exercises look 1203 00:27:35,780 --> 00:27:38,350 quizzes and programming exercises look at the link below this video and if you 1204 00:27:38,350 --> 00:27:38,360 at the link below this video and if you 1205 00:27:38,360 --> 00:27:39,820 at the link below this video and if you enjoyed this video I hope you have 1206 00:27:39,820 --> 00:27:39,830 enjoyed this video I hope you have 1207 00:27:39,830 --> 00:27:42,970 enjoyed this video I hope you have please support me by giving a thumbs up 1208 00:27:42,970 --> 00:27:42,980 please support me by giving a thumbs up 1209 00:27:42,980 --> 00:27:44,860 please support me by giving a thumbs up please like this video and share it with 1210 00:27:44,860 --> 00:27:44,870 please like this video and share it with 1211 00:27:44,870 --> 00:27:46,990 please like this video and share it with others in the next section we're going 1212 00:27:46,990 --> 00:27:47,000 others in the next section we're going 1213 00:27:47,000 --> 00:27:49,040 others in the next section we're going to look at the fundamentals of Python 1214 00:27:49,040 --> 00:27:49,050 to look at the fundamentals of Python 1215 00:27:49,050 --> 00:27:51,250 to look at the fundamentals of Python [Music] 1216 00:27:51,250 --> 00:27:51,260 [Music] 1217 00:27:51,260 --> 00:27:51,480 [Music] you 1218 00:27:51,480 --> 00:27:51,490 you 1219 00:27:51,490 --> 00:27:57,810 you [Music] 1220 00:27:57,810 --> 00:27:57,820 [Music] 1221 00:27:57,820 --> 00:28:00,760 [Music] well hello Marsh here thank you for 1222 00:28:00,760 --> 00:28:00,770 well hello Marsh here thank you for 1223 00:28:00,770 --> 00:28:02,980 well hello Marsh here thank you for watching my Python tutorial I wanted to 1224 00:28:02,980 --> 00:28:02,990 watching my Python tutorial I wanted to 1225 00:28:02,990 --> 00:28:04,660 watching my Python tutorial I wanted to let you know that this tutorial is the 1226 00:28:04,660 --> 00:28:04,670 let you know that this tutorial is the 1227 00:28:04,670 --> 00:28:07,360 let you know that this tutorial is the first two hours of my complete Python 1228 00:28:07,360 --> 00:28:07,370 first two hours of my complete Python 1229 00:28:07,370 --> 00:28:09,190 first two hours of my complete Python course where you will learn how to use 1230 00:28:09,190 --> 00:28:09,200 course where you will learn how to use 1231 00:28:09,200 --> 00:28:11,440 course where you will learn how to use Python in real-world scenarios such as 1232 00:28:11,440 --> 00:28:11,450 Python in real-world scenarios such as 1233 00:28:11,450 --> 00:28:13,740 Python in real-world scenarios such as data analysis and visualization 1234 00:28:13,740 --> 00:28:13,750 data analysis and visualization 1235 00:28:13,750 --> 00:28:16,600 data analysis and visualization automating repetitive boring tasks that 1236 00:28:16,600 --> 00:28:16,610 automating repetitive boring tasks that 1237 00:28:16,610 --> 00:28:18,600 automating repetitive boring tasks that involve working with files and folders 1238 00:28:18,600 --> 00:28:18,610 involve working with files and folders 1239 00:28:18,610 --> 00:28:21,450 involve working with files and folders spreadsheets PDFs data compression 1240 00:28:21,450 --> 00:28:21,460 spreadsheets PDFs data compression 1241 00:28:21,460 --> 00:28:25,030 spreadsheets PDFs data compression sending emails web crawling consuming 1242 00:28:25,030 --> 00:28:25,040 sending emails web crawling consuming 1243 00:28:25,040 --> 00:28:26,920 sending emails web crawling consuming API is like Yelp to get information 1244 00:28:26,920 --> 00:28:26,930 API is like Yelp to get information 1245 00:28:26,930 --> 00:28:29,830 API is like Yelp to get information about businesses and much much more this 1246 00:28:29,830 --> 00:28:29,840 about businesses and much much more this 1247 00:28:29,840 --> 00:28:32,350 about businesses and much much more this course comes with a 30 day no questions 1248 00:28:32,350 --> 00:28:32,360 course comes with a 30 day no questions 1249 00:28:32,360 --> 00:28:34,090 course comes with a 30 day no questions asked money back guarantee and a 1250 00:28:34,090 --> 00:28:34,100 asked money back guarantee and a 1251 00:28:34,100 --> 00:28:36,460 asked money back guarantee and a certificate of completion if you're 1252 00:28:36,460 --> 00:28:36,470 certificate of completion if you're 1253 00:28:36,470 --> 00:28:38,320 certificate of completion if you're interested click the link below this 1254 00:28:38,320 --> 00:28:38,330 interested click the link below this 1255 00:28:38,330 --> 00:28:47,029 interested click the link below this video to access the course 1256 00:28:47,029 --> 00:28:47,039 1257 00:28:47,039 --> 00:28:49,500 let's start this section by a discussion 1258 00:28:49,500 --> 00:28:49,510 let's start this section by a discussion 1259 00:28:49,510 --> 00:28:51,480 let's start this section by a discussion of variables which are one of the core 1260 00:28:51,480 --> 00:28:51,490 of variables which are one of the core 1261 00:28:51,490 --> 00:28:54,509 of variables which are one of the core concepts in programming we use variables 1262 00:28:54,509 --> 00:28:54,519 concepts in programming we use variables 1263 00:28:54,519 --> 00:28:57,419 concepts in programming we use variables to store data in computer's memory here 1264 00:28:57,419 --> 00:28:57,429 to store data in computer's memory here 1265 00:28:57,429 --> 00:28:59,310 to store data in computer's memory here are a few examples I'm gonna define a 1266 00:28:59,310 --> 00:28:59,320 are a few examples I'm gonna define a 1267 00:28:59,320 --> 00:29:01,830 are a few examples I'm gonna define a variable called students under line 1268 00:29:01,830 --> 00:29:01,840 variable called students under line 1269 00:29:01,840 --> 00:29:05,730 variable called students under line count and setting it to a thousand when 1270 00:29:05,730 --> 00:29:05,740 count and setting it to a thousand when 1271 00:29:05,740 --> 00:29:07,860 count and setting it to a thousand when we run this program python interpreter 1272 00:29:07,860 --> 00:29:07,870 we run this program python interpreter 1273 00:29:07,870 --> 00:29:10,950 we run this program python interpreter will allocate some memory and store this 1274 00:29:10,950 --> 00:29:10,960 will allocate some memory and store this 1275 00:29:10,960 --> 00:29:13,399 will allocate some memory and store this number thousand in that memory space 1276 00:29:13,399 --> 00:29:13,409 number thousand in that memory space 1277 00:29:13,409 --> 00:29:16,430 number thousand in that memory space then it will have this variable 1278 00:29:16,430 --> 00:29:16,440 then it will have this variable 1279 00:29:16,440 --> 00:29:19,769 then it will have this variable reference that memory location so this 1280 00:29:19,769 --> 00:29:19,779 reference that memory location so this 1281 00:29:19,779 --> 00:29:22,169 reference that memory location so this variable is just like a label for that 1282 00:29:22,169 --> 00:29:22,179 variable is just like a label for that 1283 00:29:22,179 --> 00:29:24,629 variable is just like a label for that memory location we can use this variable 1284 00:29:24,629 --> 00:29:24,639 memory location we can use this variable 1285 00:29:24,639 --> 00:29:27,600 memory location we can use this variable or this label anywhere in our program to 1286 00:29:27,600 --> 00:29:27,610 or this label anywhere in our program to 1287 00:29:27,610 --> 00:29:29,639 or this label anywhere in our program to get access to that memory location and 1288 00:29:29,639 --> 00:29:29,649 get access to that memory location and 1289 00:29:29,649 --> 00:29:32,370 get access to that memory location and the data is stored there so now if we 1290 00:29:32,370 --> 00:29:32,380 the data is stored there so now if we 1291 00:29:32,380 --> 00:29:37,259 the data is stored there so now if we print students count and run our program 1292 00:29:37,259 --> 00:29:37,269 print students count and run our program 1293 00:29:37,269 --> 00:29:40,980 print students count and run our program we will get the number of thousand so 1294 00:29:40,980 --> 00:29:40,990 we will get the number of thousand so 1295 00:29:40,990 --> 00:29:43,799 we will get the number of thousand so this is the basic of variables now what 1296 00:29:43,799 --> 00:29:43,809 this is the basic of variables now what 1297 00:29:43,809 --> 00:29:45,360 this is the basic of variables now what kind of data can be a store in 1298 00:29:45,360 --> 00:29:45,370 kind of data can be a store in 1299 00:29:45,370 --> 00:29:48,269 kind of data can be a store in computer's memory well we have several 1300 00:29:48,269 --> 00:29:48,279 computer's memory well we have several 1301 00:29:48,279 --> 00:29:50,610 computer's memory well we have several different kinds of data in this section 1302 00:29:50,610 --> 00:29:50,620 different kinds of data in this section 1303 00:29:50,620 --> 00:29:52,169 different kinds of data in this section we're going to look at the built-in 1304 00:29:52,169 --> 00:29:52,179 we're going to look at the built-in 1305 00:29:52,179 --> 00:29:55,379 we're going to look at the built-in primitive types in Python primitive 1306 00:29:55,379 --> 00:29:55,389 primitive types in Python primitive 1307 00:29:55,389 --> 00:29:58,830 primitive types in Python primitive types can be numbers boolean and strings 1308 00:29:58,830 --> 00:29:58,840 types can be numbers boolean and strings 1309 00:29:58,840 --> 00:30:01,830 types can be numbers boolean and strings let me show you so here we have a whole 1310 00:30:01,830 --> 00:30:01,840 let me show you so here we have a whole 1311 00:30:01,840 --> 00:30:04,710 let me show you so here we have a whole number we refer to this as an integer in 1312 00:30:04,710 --> 00:30:04,720 number we refer to this as an integer in 1313 00:30:04,720 --> 00:30:07,320 number we refer to this as an integer in programming we can also have numbers 1314 00:30:07,320 --> 00:30:07,330 programming we can also have numbers 1315 00:30:07,330 --> 00:30:09,539 programming we can also have numbers with a decimal point let's take a look 1316 00:30:09,539 --> 00:30:09,549 with a decimal point let's take a look 1317 00:30:09,549 --> 00:30:12,690 with a decimal point let's take a look so rating we set this to four point nine 1318 00:30:12,690 --> 00:30:12,700 so rating we set this to four point nine 1319 00:30:12,700 --> 00:30:15,870 so rating we set this to four point nine nine this is what we call a float or a 1320 00:30:15,870 --> 00:30:15,880 nine this is what we call a float or a 1321 00:30:15,880 --> 00:30:17,909 nine this is what we call a float or a floating-point number and this 1322 00:30:17,909 --> 00:30:17,919 floating-point number and this 1323 00:30:17,919 --> 00:30:20,310 floating-point number and this terminology is not specific to Python in 1324 00:30:20,310 --> 00:30:20,320 terminology is not specific to Python in 1325 00:30:20,320 --> 00:30:22,019 terminology is not specific to Python in the future when you learn a new 1326 00:30:22,019 --> 00:30:22,029 the future when you learn a new 1327 00:30:22,029 --> 00:30:23,909 the future when you learn a new programming language you're going to 1328 00:30:23,909 --> 00:30:23,919 programming language you're going to 1329 00:30:23,919 --> 00:30:26,580 programming language you're going to hear these terms again now let's take a 1330 00:30:26,580 --> 00:30:26,590 hear these terms again now let's take a 1331 00:30:26,590 --> 00:30:29,539 hear these terms again now let's take a look at an example of a boolean is 1332 00:30:29,539 --> 00:30:29,549 look at an example of a boolean is 1333 00:30:29,549 --> 00:30:34,909 look at an example of a boolean is published we set this to true or false 1334 00:30:34,909 --> 00:30:34,919 published we set this to true or false 1335 00:30:34,919 --> 00:30:38,370 published we set this to true or false these are examples of boolean values in 1336 00:30:38,370 --> 00:30:38,380 these are examples of boolean values in 1337 00:30:38,380 --> 00:30:40,649 these are examples of boolean values in programming so boolean values can either 1338 00:30:40,649 --> 00:30:40,659 programming so boolean values can either 1339 00:30:40,659 --> 00:30:43,680 programming so boolean values can either be true or false and these are exactly 1340 00:30:43,680 --> 00:30:43,690 be true or false and these are exactly 1341 00:30:43,690 --> 00:30:46,529 be true or false and these are exactly like yes and no in English later in the 1342 00:30:46,529 --> 00:30:46,539 like yes and no in English later in the 1343 00:30:46,539 --> 00:30:48,210 like yes and no in English later in the course you will learn that will use 1344 00:30:48,210 --> 00:30:48,220 course you will learn that will use 1345 00:30:48,220 --> 00:30:50,639 course you will learn that will use these boolean values to make decisions 1346 00:30:50,639 --> 00:30:50,649 these boolean values to make decisions 1347 00:30:50,649 --> 00:30:51,990 these boolean values to make decisions in our programs 1348 00:30:51,990 --> 00:30:52,000 in our programs 1349 00:30:52,000 --> 00:30:54,659 in our programs for example if the user is an admin user 1350 00:30:54,659 --> 00:30:54,669 for example if the user is an admin user 1351 00:30:54,669 --> 00:30:57,010 for example if the user is an admin user perhaps we want to give them extra 1352 00:30:57,010 --> 00:30:57,020 perhaps we want to give them extra 1353 00:30:57,020 --> 00:30:59,350 perhaps we want to give them extra permissions so these are the boolean 1354 00:30:59,350 --> 00:30:59,360 permissions so these are the boolean 1355 00:30:59,360 --> 00:31:02,350 permissions so these are the boolean values now take into account that Python 1356 00:31:02,350 --> 00:31:02,360 values now take into account that Python 1357 00:31:02,360 --> 00:31:04,930 values now take into account that Python is a case sensitive language which means 1358 00:31:04,930 --> 00:31:04,940 is a case sensitive language which means 1359 00:31:04,940 --> 00:31:06,820 is a case sensitive language which means lower case and upper case characters 1360 00:31:06,820 --> 00:31:06,830 lower case and upper case characters 1361 00:31:06,830 --> 00:31:08,440 lower case and upper case characters have different meanings 1362 00:31:08,440 --> 00:31:08,450 have different meanings 1363 00:31:08,450 --> 00:31:11,230 have different meanings so boolean values should always start 1364 00:31:11,230 --> 00:31:11,240 so boolean values should always start 1365 00:31:11,240 --> 00:31:13,600 so boolean values should always start with a capital letter like what you see 1366 00:31:13,600 --> 00:31:13,610 with a capital letter like what you see 1367 00:31:13,610 --> 00:31:17,500 with a capital letter like what you see here if we type false or false these are 1368 00:31:17,500 --> 00:31:17,510 here if we type false or false these are 1369 00:31:17,510 --> 00:31:19,780 here if we type false or false these are not accepted boolean values in Python 1370 00:31:19,780 --> 00:31:19,790 not accepted boolean values in Python 1371 00:31:19,790 --> 00:31:21,850 not accepted boolean values in Python only what you see here is a valid 1372 00:31:21,850 --> 00:31:21,860 only what you see here is a valid 1373 00:31:21,860 --> 00:31:25,050 only what you see here is a valid boolean value so false or true and 1374 00:31:25,050 --> 00:31:25,060 boolean value so false or true and 1375 00:31:25,060 --> 00:31:27,310 boolean value so false or true and finally let's take a look at an example 1376 00:31:27,310 --> 00:31:27,320 finally let's take a look at an example 1377 00:31:27,320 --> 00:31:31,180 finally let's take a look at an example of a string so course under line name we 1378 00:31:31,180 --> 00:31:31,190 of a string so course under line name we 1379 00:31:31,190 --> 00:31:33,750 of a string so course under line name we set this to your string like Python 1380 00:31:33,750 --> 00:31:33,760 set this to your string like Python 1381 00:31:33,760 --> 00:31:36,640 set this to your string like Python programming so string as I told you 1382 00:31:36,640 --> 00:31:36,650 programming so string as I told you 1383 00:31:36,650 --> 00:31:39,280 programming so string as I told you before is like text whenever you want to 1384 00:31:39,280 --> 00:31:39,290 before is like text whenever you want to 1385 00:31:39,290 --> 00:31:41,380 before is like text whenever you want to work with text in your programs you need 1386 00:31:41,380 --> 00:31:41,390 work with text in your programs you need 1387 00:31:41,390 --> 00:31:44,320 work with text in your programs you need to surround your text with quotes so 1388 00:31:44,320 --> 00:31:44,330 to surround your text with quotes so 1389 00:31:44,330 --> 00:31:53,110 to surround your text with quotes so these are the basics of variables 1390 00:31:53,110 --> 00:31:53,120 1391 00:31:53,120 --> 00:31:55,580 so these are the variables from the last 1392 00:31:55,580 --> 00:31:55,590 so these are the variables from the last 1393 00:31:55,590 --> 00:31:58,070 so these are the variables from the last lecture now I've got a question for you 1394 00:31:58,070 --> 00:31:58,080 lecture now I've got a question for you 1395 00:31:58,080 --> 00:31:59,810 lecture now I've got a question for you there are four things that have 1396 00:31:59,810 --> 00:31:59,820 there are four things that have 1397 00:31:59,820 --> 00:32:02,389 there are four things that have consistently used in this program can 1398 00:32:02,389 --> 00:32:02,399 consistently used in this program can 1399 00:32:02,399 --> 00:32:04,639 consistently used in this program can you spot them if you want you can pause 1400 00:32:04,639 --> 00:32:04,649 you spot them if you want you can pause 1401 00:32:04,649 --> 00:32:06,470 you spot them if you want you can pause the video think about this for a few 1402 00:32:06,470 --> 00:32:06,480 the video think about this for a few 1403 00:32:06,480 --> 00:32:09,540 the video think about this for a few seconds and then continue watching 1404 00:32:09,540 --> 00:32:09,550 seconds and then continue watching 1405 00:32:09,550 --> 00:32:12,120 seconds and then continue watching so here are those four things the first 1406 00:32:12,120 --> 00:32:12,130 so here are those four things the first 1407 00:32:12,130 --> 00:32:14,760 so here are those four things the first thing is that all my variable names are 1408 00:32:14,760 --> 00:32:14,770 thing is that all my variable names are 1409 00:32:14,770 --> 00:32:18,420 thing is that all my variable names are descriptive and meaningful so students 1410 00:32:18,420 --> 00:32:18,430 descriptive and meaningful so students 1411 00:32:18,430 --> 00:32:20,580 descriptive and meaningful so students count represents the number of students 1412 00:32:20,580 --> 00:32:20,590 count represents the number of students 1413 00:32:20,590 --> 00:32:23,520 count represents the number of students for a course or course name clearly 1414 00:32:23,520 --> 00:32:23,530 for a course or course name clearly 1415 00:32:23,530 --> 00:32:25,590 for a course or course name clearly explains that this variable holds the 1416 00:32:25,590 --> 00:32:25,600 explains that this variable holds the 1417 00:32:25,600 --> 00:32:27,900 explains that this variable holds the name of a course one of the issues that 1418 00:32:27,900 --> 00:32:27,910 name of a course one of the issues that 1419 00:32:27,910 --> 00:32:30,480 name of a course one of the issues that I see a lot amongst beginner programmers 1420 00:32:30,480 --> 00:32:30,490 I see a lot amongst beginner programmers 1421 00:32:30,490 --> 00:32:33,180 I see a lot amongst beginner programmers is that they use mystical names for 1422 00:32:33,180 --> 00:32:33,190 is that they use mystical names for 1423 00:32:33,190 --> 00:32:36,300 is that they use mystical names for their variables something like this CN 1424 00:32:36,300 --> 00:32:36,310 their variables something like this CN 1425 00:32:36,310 --> 00:32:39,360 their variables something like this CN has ensured for course name when someone 1426 00:32:39,360 --> 00:32:39,370 has ensured for course name when someone 1427 00:32:39,370 --> 00:32:41,220 has ensured for course name when someone else reads this code they have no idea 1428 00:32:41,220 --> 00:32:41,230 else reads this code they have no idea 1429 00:32:41,230 --> 00:32:44,190 else reads this code they have no idea what CN stands for or they use variable 1430 00:32:44,190 --> 00:32:44,200 what CN stands for or they use variable 1431 00:32:44,200 --> 00:32:47,040 what CN stands for or they use variable names like c1 when I look at that code I 1432 00:32:47,040 --> 00:32:47,050 names like c1 when I look at that code I 1433 00:32:47,050 --> 00:32:49,530 names like c1 when I look at that code I wonder where is c2 and what is the 1434 00:32:49,530 --> 00:32:49,540 wonder where is c2 and what is the 1435 00:32:49,540 --> 00:32:52,050 wonder where is c2 and what is the difference between c1 and c2 so these 1436 00:32:52,050 --> 00:32:52,060 difference between c1 and c2 so these 1437 00:32:52,060 --> 00:32:54,600 difference between c1 and c2 so these variable names are very mystical that's 1438 00:32:54,600 --> 00:32:54,610 variable names are very mystical that's 1439 00:32:54,610 --> 00:32:57,240 variable names are very mystical that's a bad practice make sure your variable 1440 00:32:57,240 --> 00:32:57,250 a bad practice make sure your variable 1441 00:32:57,250 --> 00:32:58,920 a bad practice make sure your variable names are always descriptive and 1442 00:32:58,920 --> 00:32:58,930 names are always descriptive and 1443 00:32:58,930 --> 00:33:01,320 names are always descriptive and meaningful because this makes your code 1444 00:33:01,320 --> 00:33:01,330 meaningful because this makes your code 1445 00:33:01,330 --> 00:33:04,020 meaningful because this makes your code more maintainable now there are times 1446 00:33:04,020 --> 00:33:04,030 more maintainable now there are times 1447 00:33:04,030 --> 00:33:05,970 more maintainable now there are times that you can use short variable names 1448 00:33:05,970 --> 00:33:05,980 that you can use short variable names 1449 00:33:05,980 --> 00:33:09,600 that you can use short variable names like X Y Z if you're dealing with things 1450 00:33:09,600 --> 00:33:09,610 like X Y Z if you're dealing with things 1451 00:33:09,610 --> 00:33:12,060 like X Y Z if you're dealing with things like coordinates so that's an exception 1452 00:33:12,060 --> 00:33:12,070 like coordinates so that's an exception 1453 00:33:12,070 --> 00:33:14,970 like coordinates so that's an exception now the second thing that I have 1454 00:33:14,970 --> 00:33:14,980 now the second thing that I have 1455 00:33:14,980 --> 00:33:17,580 now the second thing that I have consistently used in this code is that I 1456 00:33:17,580 --> 00:33:17,590 consistently used in this code is that I 1457 00:33:17,590 --> 00:33:20,070 consistently used in this code is that I have used lowercase letters to name my 1458 00:33:20,070 --> 00:33:20,080 have used lowercase letters to name my 1459 00:33:20,080 --> 00:33:22,860 have used lowercase letters to name my variables so here we don't have course 1460 00:33:22,860 --> 00:33:22,870 variables so here we don't have course 1461 00:33:22,870 --> 00:33:27,750 variables so here we don't have course name all in capital or in title case all 1462 00:33:27,750 --> 00:33:27,760 name all in capital or in title case all 1463 00:33:27,760 --> 00:33:31,800 name all in capital or in title case all letters are lowercase right let's delete 1464 00:33:31,800 --> 00:33:31,810 letters are lowercase right let's delete 1465 00:33:31,810 --> 00:33:34,230 letters are lowercase right let's delete this the third thing that I've 1466 00:33:34,230 --> 00:33:34,240 this the third thing that I've 1467 00:33:34,240 --> 00:33:36,330 this the third thing that I've consistently used here is that I have 1468 00:33:36,330 --> 00:33:36,340 consistently used here is that I have 1469 00:33:36,340 --> 00:33:38,970 consistently used here is that I have used an underscore to separate multiple 1470 00:33:38,970 --> 00:33:38,980 used an underscore to separate multiple 1471 00:33:38,980 --> 00:33:41,370 used an underscore to separate multiple words and I've done this to make my 1472 00:33:41,370 --> 00:33:41,380 words and I've done this to make my 1473 00:33:41,380 --> 00:33:44,310 words and I've done this to make my variable names more readable because in 1474 00:33:44,310 --> 00:33:44,320 variable names more readable because in 1475 00:33:44,320 --> 00:33:46,470 variable names more readable because in Python we cannot have a space in 1476 00:33:46,470 --> 00:33:46,480 Python we cannot have a space in 1477 00:33:46,480 --> 00:33:48,810 Python we cannot have a space in variable names so we cannot have course 1478 00:33:48,810 --> 00:33:48,820 variable names so we cannot have course 1479 00:33:48,820 --> 00:33:50,940 variable names so we cannot have course name and if you put these two words 1480 00:33:50,940 --> 00:33:50,950 name and if you put these two words 1481 00:33:50,950 --> 00:33:53,190 name and if you put these two words together it's a little bit hard to read 1482 00:33:53,190 --> 00:33:53,200 together it's a little bit hard to read 1483 00:33:53,200 --> 00:33:56,220 together it's a little bit hard to read that's why we use an underscore and the 1484 00:33:56,220 --> 00:33:56,230 that's why we use an underscore and the 1485 00:33:56,230 --> 00:33:57,180 that's why we use an underscore and the fourth thing that I have used 1486 00:33:57,180 --> 00:33:57,190 fourth thing that I have used 1487 00:33:57,190 --> 00:33:59,790 fourth thing that I have used consistently here is that I have put a 1488 00:33:59,790 --> 00:33:59,800 consistently here is that I have put a 1489 00:33:59,800 --> 00:34:03,480 consistently here is that I have put a space around this equal sign again 1490 00:34:03,480 --> 00:34:03,490 space around this equal sign again 1491 00:34:03,490 --> 00:34:05,190 space around this equal sign again that's one of the issues I see a lot 1492 00:34:05,190 --> 00:34:05,200 that's one of the issues I see a lot 1493 00:34:05,200 --> 00:34:08,220 that's one of the issues I see a lot amongst beginners they write code like 1494 00:34:08,220 --> 00:34:08,230 amongst beginners they write code like 1495 00:34:08,230 --> 00:34:12,030 amongst beginners they write code like this this is a little bit ugly this is 1496 00:34:12,030 --> 00:34:12,040 this this is a little bit ugly this is 1497 00:34:12,040 --> 00:34:15,330 this this is a little bit ugly this is what we call dirty code dirty stinky 1498 00:34:15,330 --> 00:34:15,340 what we call dirty code dirty stinky 1499 00:34:15,340 --> 00:34:16,200 what we call dirty code dirty stinky smelly 1500 00:34:16,200 --> 00:34:16,210 smelly 1501 00:34:16,210 --> 00:34:17,760 smelly you should write code that is clean and 1502 00:34:17,760 --> 00:34:17,770 you should write code that is clean and 1503 00:34:17,770 --> 00:34:20,909 you should write code that is clean and beautiful so other people can read it 1504 00:34:20,909 --> 00:34:20,919 beautiful so other people can read it 1505 00:34:20,919 --> 00:34:23,359 beautiful so other people can read it like a story like a newspaper article 1506 00:34:23,359 --> 00:34:23,369 like a story like a newspaper article 1507 00:34:23,369 --> 00:34:25,730 like a story like a newspaper article it should be formatted properly and 1508 00:34:25,730 --> 00:34:25,740 it should be formatted properly and 1509 00:34:25,740 --> 00:34:29,269 it should be formatted properly and that's why we have pep 8 in Python now 1510 00:34:29,269 --> 00:34:29,279 that's why we have pep 8 in Python now 1511 00:34:29,279 --> 00:34:30,919 that's why we have pep 8 in Python now the good thing is if you forget these 1512 00:34:30,919 --> 00:34:30,929 the good thing is if you forget these 1513 00:34:30,929 --> 00:34:33,589 the good thing is if you forget these rules when you save the changes auto-pay 1514 00:34:33,589 --> 00:34:33,599 rules when you save the changes auto-pay 1515 00:34:33,599 --> 00:34:35,659 rules when you save the changes auto-pay 8 kicks in I didn't automatically 1516 00:34:35,659 --> 00:34:35,669 8 kicks in I didn't automatically 1517 00:34:35,669 --> 00:34:37,999 8 kicks in I didn't automatically reformat your code but that aside you 1518 00:34:37,999 --> 00:34:38,009 reformat your code but that aside you 1519 00:34:38,009 --> 00:34:40,069 reformat your code but that aside you should always give yourself the habit of 1520 00:34:40,069 --> 00:34:40,079 should always give yourself the habit of 1521 00:34:40,079 --> 00:34:42,649 should always give yourself the habit of writing clean code without relying too 1522 00:34:42,649 --> 00:34:42,659 writing clean code without relying too 1523 00:34:42,659 --> 00:34:45,230 writing clean code without relying too much on the tooling so these are all the 1524 00:34:45,230 --> 00:34:45,240 much on the tooling so these are all the 1525 00:34:45,240 --> 00:34:47,059 much on the tooling so these are all the best practices about naming your 1526 00:34:47,059 --> 00:34:47,069 best practices about naming your 1527 00:34:47,069 --> 00:34:49,159 best practices about naming your variables next we're going to look at 1528 00:34:49,159 --> 00:34:49,169 variables next we're going to look at 1529 00:34:49,169 --> 00:34:57,930 variables next we're going to look at strings in more detail 1530 00:34:57,930 --> 00:34:57,940 1531 00:34:57,940 --> 00:35:00,609 so here we have this course variable set 1532 00:35:00,609 --> 00:35:00,619 so here we have this course variable set 1533 00:35:00,619 --> 00:35:03,069 so here we have this course variable set to Python programming as I told you 1534 00:35:03,069 --> 00:35:03,079 to Python programming as I told you 1535 00:35:03,079 --> 00:35:05,470 to Python programming as I told you before whenever you work with text you 1536 00:35:05,470 --> 00:35:05,480 before whenever you work with text you 1537 00:35:05,480 --> 00:35:07,240 before whenever you work with text you should surround your text with quotes 1538 00:35:07,240 --> 00:35:07,250 should surround your text with quotes 1539 00:35:07,250 --> 00:35:09,700 should surround your text with quotes you can either use double quotes or 1540 00:35:09,700 --> 00:35:09,710 you can either use double quotes or 1541 00:35:09,710 --> 00:35:11,650 you can either use double quotes or single quotes that's more of a personal 1542 00:35:11,650 --> 00:35:11,660 single quotes that's more of a personal 1543 00:35:11,660 --> 00:35:14,740 single quotes that's more of a personal preference but quite often we use double 1544 00:35:14,740 --> 00:35:14,750 preference but quite often we use double 1545 00:35:14,750 --> 00:35:15,250 preference but quite often we use double quotes 1546 00:35:15,250 --> 00:35:15,260 quotes 1547 00:35:15,260 --> 00:35:18,130 quotes you also have triple quotes and we use 1548 00:35:18,130 --> 00:35:18,140 you also have triple quotes and we use 1549 00:35:18,140 --> 00:35:21,400 you also have triple quotes and we use them to format a long string for example 1550 00:35:21,400 --> 00:35:21,410 them to format a long string for example 1551 00:35:21,410 --> 00:35:24,990 them to format a long string for example if you have let's say a variable message 1552 00:35:24,990 --> 00:35:25,000 if you have let's say a variable message 1553 00:35:25,000 --> 00:35:27,520 if you have let's say a variable message that is the message we want to include 1554 00:35:27,520 --> 00:35:27,530 that is the message we want to include 1555 00:35:27,530 --> 00:35:30,310 that is the message we want to include in the body of an email 1556 00:35:30,310 --> 00:35:30,320 in the body of an email 1557 00:35:30,320 --> 00:35:32,710 in the body of an email you can use triple quotes to format it 1558 00:35:32,710 --> 00:35:32,720 you can use triple quotes to format it 1559 00:35:32,720 --> 00:35:37,600 you can use triple quotes to format it like this hi John this is Marsh from 1560 00:35:37,600 --> 00:35:37,610 like this hi John this is Marsh from 1561 00:35:37,610 --> 00:35:41,710 like this hi John this is Marsh from code with marsh comm blah blah blah so 1562 00:35:41,710 --> 00:35:41,720 code with marsh comm blah blah blah so 1563 00:35:41,720 --> 00:35:44,950 code with marsh comm blah blah blah so that's when we use triple quotes now we 1564 00:35:44,950 --> 00:35:44,960 that's when we use triple quotes now we 1565 00:35:44,960 --> 00:35:47,050 that's when we use triple quotes now we don't need this in this lecture so 1566 00:35:47,050 --> 00:35:47,060 don't need this in this lecture so 1567 00:35:47,060 --> 00:35:49,210 don't need this in this lecture so delete let me show you a few useful 1568 00:35:49,210 --> 00:35:49,220 delete let me show you a few useful 1569 00:35:49,220 --> 00:35:52,120 delete let me show you a few useful things you can do with strings first of 1570 00:35:52,120 --> 00:35:52,130 things you can do with strings first of 1571 00:35:52,130 --> 00:35:54,580 things you can do with strings first of all we have this built-in function in 1572 00:35:54,580 --> 00:35:54,590 all we have this built-in function in 1573 00:35:54,590 --> 00:35:57,130 all we have this built-in function in Python for getting the lengths of 1574 00:35:57,130 --> 00:35:57,140 Python for getting the lengths of 1575 00:35:57,140 --> 00:36:00,340 Python for getting the lengths of strings what is a function a function is 1576 00:36:00,340 --> 00:36:00,350 strings what is a function a function is 1577 00:36:00,350 --> 00:36:02,830 strings what is a function a function is basically a reusable piece of code that 1578 00:36:02,830 --> 00:36:02,840 basically a reusable piece of code that 1579 00:36:02,840 --> 00:36:06,040 basically a reusable piece of code that carries out a task as a metaphor think 1580 00:36:06,040 --> 00:36:06,050 carries out a task as a metaphor think 1581 00:36:06,050 --> 00:36:08,860 carries out a task as a metaphor think of the remote control of your TV on this 1582 00:36:08,860 --> 00:36:08,870 of the remote control of your TV on this 1583 00:36:08,870 --> 00:36:10,690 of the remote control of your TV on this remote control you have buttons for 1584 00:36:10,690 --> 00:36:10,700 remote control you have buttons for 1585 00:36:10,700 --> 00:36:12,940 remote control you have buttons for different functions like turn on turn 1586 00:36:12,940 --> 00:36:12,950 different functions like turn on turn 1587 00:36:12,950 --> 00:36:15,340 different functions like turn on turn off change the channel and so on these 1588 00:36:15,340 --> 00:36:15,350 off change the channel and so on these 1589 00:36:15,350 --> 00:36:18,160 off change the channel and so on these are the built-in functions in your TV in 1590 00:36:18,160 --> 00:36:18,170 are the built-in functions in your TV in 1591 00:36:18,170 --> 00:36:20,590 are the built-in functions in your TV in Python and many other programming 1592 00:36:20,590 --> 00:36:20,600 Python and many other programming 1593 00:36:20,600 --> 00:36:22,780 Python and many other programming languages we have the exact same concept 1594 00:36:22,780 --> 00:36:22,790 languages we have the exact same concept 1595 00:36:22,790 --> 00:36:25,510 languages we have the exact same concept so we have functions that are built into 1596 00:36:25,510 --> 00:36:25,520 so we have functions that are built into 1597 00:36:25,520 --> 00:36:27,430 so we have functions that are built into the language on the platform you can 1598 00:36:27,430 --> 00:36:27,440 the language on the platform you can 1599 00:36:27,440 --> 00:36:29,770 the language on the platform you can reuse these functions to perform various 1600 00:36:29,770 --> 00:36:29,780 reuse these functions to perform various 1601 00:36:29,780 --> 00:36:32,290 reuse these functions to perform various tasks so here we can use the built-in 1602 00:36:32,290 --> 00:36:32,300 tasks so here we can use the built-in 1603 00:36:32,300 --> 00:36:35,050 tasks so here we can use the built-in Len function to get the length of a 1604 00:36:35,050 --> 00:36:35,060 Len function to get the length of a 1605 00:36:35,060 --> 00:36:36,670 Len function to get the length of a string which means the number of 1606 00:36:36,670 --> 00:36:36,680 string which means the number of 1607 00:36:36,680 --> 00:36:39,310 string which means the number of characters in that string now whenever 1608 00:36:39,310 --> 00:36:39,320 characters in that string now whenever 1609 00:36:39,320 --> 00:36:41,290 characters in that string now whenever you want to use a function you should 1610 00:36:41,290 --> 00:36:41,300 you want to use a function you should 1611 00:36:41,300 --> 00:36:45,400 you want to use a function you should use parentheses now we say we're calling 1612 00:36:45,400 --> 00:36:45,410 use parentheses now we say we're calling 1613 00:36:45,410 --> 00:36:47,200 use parentheses now we say we're calling this function which basically means we 1614 00:36:47,200 --> 00:36:47,210 this function which basically means we 1615 00:36:47,210 --> 00:36:49,690 this function which basically means we are using this function now some 1616 00:36:49,690 --> 00:36:49,700 are using this function now some 1617 00:36:49,700 --> 00:36:52,750 are using this function now some functions take additional data which we 1618 00:36:52,750 --> 00:36:52,760 functions take additional data which we 1619 00:36:52,760 --> 00:36:55,360 functions take additional data which we refer to as arguments these arguments 1620 00:36:55,360 --> 00:36:55,370 refer to as arguments these arguments 1621 00:36:55,370 --> 00:36:59,230 refer to as arguments these arguments are inputs to these functions so this 1622 00:36:59,230 --> 00:36:59,240 are inputs to these functions so this 1623 00:36:59,240 --> 00:37:01,540 are inputs to these functions so this Len function takes an input or an 1624 00:37:01,540 --> 00:37:01,550 Len function takes an input or an 1625 00:37:01,550 --> 00:37:04,420 Len function takes an input or an argument here we pass our course 1626 00:37:04,420 --> 00:37:04,430 argument here we pass our course 1627 00:37:04,430 --> 00:37:07,060 argument here we pass our course variable and this will return the number 1628 00:37:07,060 --> 00:37:07,070 variable and this will return the number 1629 00:37:07,070 --> 00:37:09,700 variable and this will return the number of characters in this string so let's 1630 00:37:09,700 --> 00:37:09,710 of characters in this string so let's 1631 00:37:09,710 --> 00:37:13,690 of characters in this string so let's print that and see what we get run the 1632 00:37:13,690 --> 00:37:13,700 print that and see what we get run the 1633 00:37:13,700 --> 00:37:17,560 print that and see what we get run the program we get 18 because we have 18 1634 00:37:17,560 --> 00:37:17,570 program we get 18 because we have 18 1635 00:37:17,570 --> 00:37:20,380 program we get 18 because we have 18 characters here let's look at another 1636 00:37:20,380 --> 00:37:20,390 characters here let's look at another 1637 00:37:20,390 --> 00:37:23,200 characters here let's look at another example if you want to get access to a 1638 00:37:23,200 --> 00:37:23,210 example if you want to get access to a 1639 00:37:23,210 --> 00:37:25,720 example if you want to get access to a specific character in this string you 1640 00:37:25,720 --> 00:37:25,730 specific character in this string you 1641 00:37:25,730 --> 00:37:28,630 specific character in this string you use the square bracket notation so here 1642 00:37:28,630 --> 00:37:28,640 use the square bracket notation so here 1643 00:37:28,640 --> 00:37:32,140 use the square bracket notation so here we add course square brackets to get the 1644 00:37:32,140 --> 00:37:32,150 we add course square brackets to get the 1645 00:37:32,150 --> 00:37:36,280 we add course square brackets to get the first character you use the index 0 so 1646 00:37:36,280 --> 00:37:36,290 first character you use the index 0 so 1647 00:37:36,290 --> 00:37:38,310 first character you use the index 0 so in Python like many other languages 1648 00:37:38,310 --> 00:37:38,320 in Python like many other languages 1649 00:37:38,320 --> 00:37:42,130 in Python like many other languages strings are 0 index which means the 1650 00:37:42,130 --> 00:37:42,140 strings are 0 index which means the 1651 00:37:42,140 --> 00:37:43,579 strings are 0 index which means the index of the first cat 1652 00:37:43,579 --> 00:37:43,589 index of the first cat 1653 00:37:43,589 --> 00:37:47,120 index of the first cat or the first element is zero so now when 1654 00:37:47,120 --> 00:37:47,130 or the first element is zero so now when 1655 00:37:47,130 --> 00:37:54,559 or the first element is zero so now when we print this will get P okay now you 1656 00:37:54,559 --> 00:37:54,569 we print this will get P okay now you 1657 00:37:54,569 --> 00:37:58,519 we print this will get P okay now you can also use a negative index like minus 1658 00:37:58,519 --> 00:37:58,529 can also use a negative index like minus 1659 00:37:58,529 --> 00:38:00,440 can also use a negative index like minus one what does that mean 1660 00:38:00,440 --> 00:38:00,450 one what does that mean 1661 00:38:00,450 --> 00:38:04,759 one what does that mean well if zero represents the first 1662 00:38:04,759 --> 00:38:04,769 well if zero represents the first 1663 00:38:04,769 --> 00:38:06,859 well if zero represents the first character here what do you think 1664 00:38:06,859 --> 00:38:06,869 character here what do you think 1665 00:38:06,869 --> 00:38:09,890 character here what do you think negative one represents that takes us 1666 00:38:09,890 --> 00:38:09,900 negative one represents that takes us 1667 00:38:09,900 --> 00:38:12,410 negative one represents that takes us back to the end of this string so that 1668 00:38:12,410 --> 00:38:12,420 back to the end of this string so that 1669 00:38:12,420 --> 00:38:14,809 back to the end of this string so that returns the first character from the end 1670 00:38:14,809 --> 00:38:14,819 returns the first character from the end 1671 00:38:14,819 --> 00:38:16,819 returns the first character from the end of this string let's run this program 1672 00:38:16,819 --> 00:38:16,829 of this string let's run this program 1673 00:38:16,829 --> 00:38:21,880 of this string let's run this program you will see it will get G there you go 1674 00:38:21,880 --> 00:38:21,890 you will see it will get G there you go 1675 00:38:21,890 --> 00:38:24,979 you will see it will get G there you go using a similar syntax you can slice 1676 00:38:24,979 --> 00:38:24,989 using a similar syntax you can slice 1677 00:38:24,989 --> 00:38:28,160 using a similar syntax you can slice strings let me show you so I'm gonna 1678 00:38:28,160 --> 00:38:28,170 strings let me show you so I'm gonna 1679 00:38:28,170 --> 00:38:31,099 strings let me show you so I'm gonna duplicate this line and remove negative 1680 00:38:31,099 --> 00:38:31,109 duplicate this line and remove negative 1681 00:38:31,109 --> 00:38:34,099 duplicate this line and remove negative one now let's say we want to extract the 1682 00:38:34,099 --> 00:38:34,109 one now let's say we want to extract the 1683 00:38:34,109 --> 00:38:36,589 one now let's say we want to extract the first three characters in this string so 1684 00:38:36,589 --> 00:38:36,599 first three characters in this string so 1685 00:38:36,599 --> 00:38:39,969 first three characters in this string so here we need two indexes the start index 1686 00:38:39,969 --> 00:38:39,979 here we need two indexes the start index 1687 00:38:39,979 --> 00:38:43,759 here we need two indexes the start index colon the end index so this will return 1688 00:38:43,759 --> 00:38:43,769 colon the end index so this will return 1689 00:38:43,769 --> 00:38:46,819 colon the end index so this will return a new string that contains the first 1690 00:38:46,819 --> 00:38:46,829 a new string that contains the first 1691 00:38:46,829 --> 00:38:49,819 a new string that contains the first three characters in this course variable 1692 00:38:49,819 --> 00:38:49,829 three characters in this course variable 1693 00:38:49,829 --> 00:38:53,809 three characters in this course variable that will be P Y and T so the index of 1694 00:38:53,809 --> 00:38:53,819 that will be P Y and T so the index of 1695 00:38:53,819 --> 00:38:57,289 that will be P Y and T so the index of these characters are 0 1 and 2 so that 1696 00:38:57,289 --> 00:38:57,299 these characters are 0 1 and 2 so that 1697 00:38:57,299 --> 00:39:00,079 these characters are 0 1 and 2 so that means the character at the end index is 1698 00:39:00,079 --> 00:39:00,089 means the character at the end index is 1699 00:39:00,089 --> 00:39:03,739 means the character at the end index is not included ok let's run the program 1700 00:39:03,739 --> 00:39:03,749 not included ok let's run the program 1701 00:39:03,749 --> 00:39:05,870 not included ok let's run the program and make sure we get the right result 1702 00:39:05,870 --> 00:39:05,880 and make sure we get the right result 1703 00:39:05,880 --> 00:39:09,739 and make sure we get the right result there you go py T now what if we don't 1704 00:39:09,739 --> 00:39:09,749 there you go py T now what if we don't 1705 00:39:09,749 --> 00:39:10,279 there you go py T now what if we don't include 1706 00:39:10,279 --> 00:39:10,289 include 1707 00:39:10,289 --> 00:39:13,099 include the end index what do you think we're 1708 00:39:13,099 --> 00:39:13,109 the end index what do you think we're 1709 00:39:13,109 --> 00:39:13,640 the end index what do you think we're gonna get 1710 00:39:13,640 --> 00:39:13,650 gonna get 1711 00:39:13,650 --> 00:39:17,509 gonna get it's common sense we start from index 0 1712 00:39:17,509 --> 00:39:17,519 it's common sense we start from index 0 1713 00:39:17,519 --> 00:39:19,759 it's common sense we start from index 0 and go all the way to the end of this 1714 00:39:19,759 --> 00:39:19,769 and go all the way to the end of this 1715 00:39:19,769 --> 00:39:22,099 and go all the way to the end of this string so this will return a new string 1716 00:39:22,099 --> 00:39:22,109 string so this will return a new string 1717 00:39:22,109 --> 00:39:25,099 string so this will return a new string that is exactly the same as the original 1718 00:39:25,099 --> 00:39:25,109 that is exactly the same as the original 1719 00:39:25,109 --> 00:39:29,120 that is exactly the same as the original string let's take a look so we get 1720 00:39:29,120 --> 00:39:29,130 string let's take a look so we get 1721 00:39:29,130 --> 00:39:32,989 string let's take a look so we get Python programming now what if we don't 1722 00:39:32,989 --> 00:39:32,999 Python programming now what if we don't 1723 00:39:32,999 --> 00:39:36,229 Python programming now what if we don't include the start index but include the 1724 00:39:36,229 --> 00:39:36,239 include the start index but include the 1725 00:39:36,239 --> 00:39:38,089 include the start index but include the end index what do you think we're gonna 1726 00:39:38,089 --> 00:39:38,099 end index what do you think we're gonna 1727 00:39:38,099 --> 00:39:41,569 end index what do you think we're gonna get once again it's common sense so by 1728 00:39:41,569 --> 00:39:41,579 get once again it's common sense so by 1729 00:39:41,579 --> 00:39:44,239 get once again it's common sense so by default Python will put 0 here so it 1730 00:39:44,239 --> 00:39:44,249 default Python will put 0 here so it 1731 00:39:44,249 --> 00:39:45,739 default Python will put 0 here so it will start from the beginning of this 1732 00:39:45,739 --> 00:39:45,749 will start from the beginning of this 1733 00:39:45,749 --> 00:39:48,229 will start from the beginning of this string so when I run this program we 1734 00:39:48,229 --> 00:39:48,239 string so when I run this program we 1735 00:39:48,239 --> 00:39:51,259 string so when I run this program we should get py t one more time there you 1736 00:39:51,259 --> 00:39:51,269 should get py t one more time there you 1737 00:39:51,269 --> 00:39:55,579 should get py t one more time there you go and finally as the last example if we 1738 00:39:55,579 --> 00:39:55,589 go and finally as the last example if we 1739 00:39:55,589 --> 00:39:57,530 go and finally as the last example if we don't include the start 1740 00:39:57,530 --> 00:39:57,540 don't include the start 1741 00:39:57,540 --> 00:39:59,810 don't include the start and the end index this will return a 1742 00:39:59,810 --> 00:39:59,820 and the end index this will return a 1743 00:39:59,820 --> 00:40:02,930 and the end index this will return a copy of the original string let's look 1744 00:40:02,930 --> 00:40:02,940 copy of the original string let's look 1745 00:40:02,940 --> 00:40:07,940 copy of the original string let's look at this so we get Python programming now 1746 00:40:07,940 --> 00:40:07,950 at this so we get Python programming now 1747 00:40:07,950 --> 00:40:09,410 at this so we get Python programming now you don't have to memorize any of these 1748 00:40:09,410 --> 00:40:09,420 you don't have to memorize any of these 1749 00:40:09,420 --> 00:40:12,500 you don't have to memorize any of these just remember we use the Len function to 1750 00:40:12,500 --> 00:40:12,510 just remember we use the Len function to 1751 00:40:12,510 --> 00:40:14,570 just remember we use the Len function to get the length of a string we use 1752 00:40:14,570 --> 00:40:14,580 get the length of a string we use 1753 00:40:14,580 --> 00:40:16,910 get the length of a string we use bracket notation to get access to a 1754 00:40:16,910 --> 00:40:16,920 bracket notation to get access to a 1755 00:40:16,920 --> 00:40:19,130 bracket notation to get access to a specific element or a specific character 1756 00:40:19,130 --> 00:40:19,140 specific element or a specific character 1757 00:40:19,140 --> 00:40:22,220 specific element or a specific character and we use this notation to a slice a 1758 00:40:22,220 --> 00:40:22,230 and we use this notation to a slice a 1759 00:40:22,230 --> 00:40:29,980 and we use this notation to a slice a string 1760 00:40:29,980 --> 00:40:29,990 1761 00:40:29,990 --> 00:40:32,600 so we have this string here Python 1762 00:40:32,600 --> 00:40:32,610 so we have this string here Python 1763 00:40:32,610 --> 00:40:35,000 so we have this string here Python programming now let's say we want to put 1764 00:40:35,000 --> 00:40:35,010 programming now let's say we want to put 1765 00:40:35,010 --> 00:40:37,850 programming now let's say we want to put a double quote in the middle of this 1766 00:40:37,850 --> 00:40:37,860 a double quote in the middle of this 1767 00:40:37,860 --> 00:40:40,060 a double quote in the middle of this string there is a problem here 1768 00:40:40,060 --> 00:40:40,070 string there is a problem here 1769 00:40:40,070 --> 00:40:43,520 string there is a problem here Python interpreter sees this second 1770 00:40:43,520 --> 00:40:43,530 Python interpreter sees this second 1771 00:40:43,530 --> 00:40:46,460 Python interpreter sees this second string as the end of the string so the 1772 00:40:46,460 --> 00:40:46,470 string as the end of the string so the 1773 00:40:46,470 --> 00:40:48,350 string as the end of the string so the rest of the code is meaningless and 1774 00:40:48,350 --> 00:40:48,360 rest of the code is meaningless and 1775 00:40:48,360 --> 00:40:51,100 rest of the code is meaningless and invalid how do you solve this problem 1776 00:40:51,100 --> 00:40:51,110 invalid how do you solve this problem 1777 00:40:51,110 --> 00:40:54,410 invalid how do you solve this problem well there are two ways one way is to 1778 00:40:54,410 --> 00:40:54,420 well there are two ways one way is to 1779 00:40:54,420 --> 00:40:58,040 well there are two ways one way is to use single quotes for our string and 1780 00:40:58,040 --> 00:40:58,050 use single quotes for our string and 1781 00:40:58,050 --> 00:41:00,890 use single quotes for our string and then we can use a double code in the 1782 00:41:00,890 --> 00:41:00,900 then we can use a double code in the 1783 00:41:00,900 --> 00:41:01,940 then we can use a double code in the middle of this string 1784 00:41:01,940 --> 00:41:01,950 middle of this string 1785 00:41:01,950 --> 00:41:04,640 middle of this string but what if for whatever reason perhaps 1786 00:41:04,640 --> 00:41:04,650 but what if for whatever reason perhaps 1787 00:41:04,650 --> 00:41:07,400 but what if for whatever reason perhaps for being consistent in our code we 1788 00:41:07,400 --> 00:41:07,410 for being consistent in our code we 1789 00:41:07,410 --> 00:41:10,700 for being consistent in our code we decided to use double quotes how can we 1790 00:41:10,700 --> 00:41:10,710 decided to use double quotes how can we 1791 00:41:10,710 --> 00:41:13,190 decided to use double quotes how can we add another double code in the middle of 1792 00:41:13,190 --> 00:41:13,200 add another double code in the middle of 1793 00:41:13,200 --> 00:41:17,450 add another double code in the middle of this string well we can prefix this with 1794 00:41:17,450 --> 00:41:17,460 this string well we can prefix this with 1795 00:41:17,460 --> 00:41:20,480 this string well we can prefix this with a backslash backslash in Python strings 1796 00:41:20,480 --> 00:41:20,490 a backslash backslash in Python strings 1797 00:41:20,490 --> 00:41:23,300 a backslash backslash in Python strings is a special character we have a jargon 1798 00:41:23,300 --> 00:41:23,310 is a special character we have a jargon 1799 00:41:23,310 --> 00:41:24,410 is a special character we have a jargon for that called 1800 00:41:24,410 --> 00:41:24,420 for that called 1801 00:41:24,420 --> 00:41:28,100 for that called escape character we use it to escape the 1802 00:41:28,100 --> 00:41:28,110 escape character we use it to escape the 1803 00:41:28,110 --> 00:41:30,950 escape character we use it to escape the character after let me show you what I 1804 00:41:30,950 --> 00:41:30,960 character after let me show you what I 1805 00:41:30,960 --> 00:41:35,450 character after let me show you what I mean so let's print this course and run 1806 00:41:35,450 --> 00:41:35,460 mean so let's print this course and run 1807 00:41:35,460 --> 00:41:39,200 mean so let's print this course and run this program what's going on here we 1808 00:41:39,200 --> 00:41:39,210 this program what's going on here we 1809 00:41:39,210 --> 00:41:41,540 this program what's going on here we don't have the backslash because we use 1810 00:41:41,540 --> 00:41:41,550 don't have the backslash because we use 1811 00:41:41,550 --> 00:41:44,030 don't have the backslash because we use that to escape this double code and 1812 00:41:44,030 --> 00:41:44,040 that to escape this double code and 1813 00:41:44,040 --> 00:41:48,260 that to escape this double code and basically displayed here so backslash is 1814 00:41:48,260 --> 00:41:48,270 basically displayed here so backslash is 1815 00:41:48,270 --> 00:41:51,380 basically displayed here so backslash is an escape character and backslash double 1816 00:41:51,380 --> 00:41:51,390 an escape character and backslash double 1817 00:41:51,390 --> 00:41:54,410 an escape character and backslash double quote is an escape sequence in Python 1818 00:41:54,410 --> 00:41:54,420 quote is an escape sequence in Python 1819 00:41:54,420 --> 00:41:56,210 quote is an escape sequence in Python strings we have a few other escape 1820 00:41:56,210 --> 00:41:56,220 strings we have a few other escape 1821 00:41:56,220 --> 00:41:58,030 strings we have a few other escape sequences that you should be aware of 1822 00:41:58,030 --> 00:41:58,040 sequences that you should be aware of 1823 00:41:58,040 --> 00:42:02,180 sequences that you should be aware of let me show you so in Python we use high 1824 00:42:02,180 --> 00:42:02,190 let me show you so in Python we use high 1825 00:42:02,190 --> 00:42:05,450 let me show you so in Python we use high sign to indicate a comment a comment is 1826 00:42:05,450 --> 00:42:05,460 sign to indicate a comment a comment is 1827 00:42:05,460 --> 00:42:07,520 sign to indicate a comment a comment is like additional note that we add to our 1828 00:42:07,520 --> 00:42:07,530 like additional note that we add to our 1829 00:42:07,530 --> 00:42:10,040 like additional note that we add to our program it's not executed by Python 1830 00:42:10,040 --> 00:42:10,050 program it's not executed by Python 1831 00:42:10,050 --> 00:42:13,580 program it's not executed by Python interpreter okay so here are the escape 1832 00:42:13,580 --> 00:42:13,590 interpreter okay so here are the escape 1833 00:42:13,590 --> 00:42:16,160 interpreter okay so here are the escape sequences you have seen backslash double 1834 00:42:16,160 --> 00:42:16,170 sequences you have seen backslash double 1835 00:42:16,170 --> 00:42:19,850 sequences you have seen backslash double quote we also have backslash single 1836 00:42:19,850 --> 00:42:19,860 quote we also have backslash single 1837 00:42:19,860 --> 00:42:23,270 quote we also have backslash single quote so we can use that to add a single 1838 00:42:23,270 --> 00:42:23,280 quote so we can use that to add a single 1839 00:42:23,280 --> 00:42:26,930 quote so we can use that to add a single code here let's run the program here it 1840 00:42:26,930 --> 00:42:26,940 code here let's run the program here it 1841 00:42:26,940 --> 00:42:31,040 code here let's run the program here it is beautiful we also have double 1842 00:42:31,040 --> 00:42:31,050 is beautiful we also have double 1843 00:42:31,050 --> 00:42:33,410 is beautiful we also have double backslash so if you want to include a 1844 00:42:33,410 --> 00:42:33,420 backslash so if you want to include a 1845 00:42:33,420 --> 00:42:35,360 backslash so if you want to include a backslash in your strings 1846 00:42:35,360 --> 00:42:35,370 backslash in your strings 1847 00:42:35,370 --> 00:42:37,310 backslash in your strings you should prefix it with another 1848 00:42:37,310 --> 00:42:37,320 you should prefix it with another 1849 00:42:37,320 --> 00:42:40,340 you should prefix it with another backslash let me show you so when we run 1850 00:42:40,340 --> 00:42:40,350 backslash let me show you so when we run 1851 00:42:40,350 --> 00:42:40,740 backslash let me show you so when we run this 1852 00:42:40,740 --> 00:42:40,750 this 1853 00:42:40,750 --> 00:42:43,590 this we get python one backslash programming 1854 00:42:43,590 --> 00:42:43,600 we get python one backslash programming 1855 00:42:43,600 --> 00:42:48,150 we get python one backslash programming and finally we have backslash n which is 1856 00:42:48,150 --> 00:42:48,160 and finally we have backslash n which is 1857 00:42:48,160 --> 00:42:51,420 and finally we have backslash n which is short for newline so now if I add a 1858 00:42:51,420 --> 00:42:51,430 short for newline so now if I add a 1859 00:42:51,430 --> 00:42:57,000 short for newline so now if I add a backslash n here see what we get we get 1860 00:42:57,000 --> 00:42:57,010 backslash n here see what we get we get 1861 00:42:57,010 --> 00:42:59,760 backslash n here see what we get we get a new line after Python so programming 1862 00:42:59,760 --> 00:42:59,770 a new line after Python so programming 1863 00:42:59,770 --> 00:43:02,910 a new line after Python so programming will end up on the second line so these 1864 00:43:02,910 --> 00:43:02,920 will end up on the second line so these 1865 00:43:02,920 --> 00:43:12,380 will end up on the second line so these are the escape sequences in Python 1866 00:43:12,380 --> 00:43:12,390 1867 00:43:12,390 --> 00:43:15,000 here we have two variables first and 1868 00:43:15,000 --> 00:43:15,010 here we have two variables first and 1869 00:43:15,010 --> 00:43:17,880 here we have two variables first and last let's say we want to print my full 1870 00:43:17,880 --> 00:43:17,890 last let's say we want to print my full 1871 00:43:17,890 --> 00:43:20,760 last let's say we want to print my full name on the console so we can define 1872 00:43:20,760 --> 00:43:20,770 name on the console so we can define 1873 00:43:20,770 --> 00:43:24,590 name on the console so we can define another variable full set it to first 1874 00:43:24,590 --> 00:43:24,600 another variable full set it to first 1875 00:43:24,600 --> 00:43:29,250 another variable full set it to first then concatenate it with a space and one 1876 00:43:29,250 --> 00:43:29,260 then concatenate it with a space and one 1877 00:43:29,260 --> 00:43:33,120 then concatenate it with a space and one more time concatenate it with last now 1878 00:43:33,120 --> 00:43:33,130 more time concatenate it with last now 1879 00:43:33,130 --> 00:43:37,200 more time concatenate it with last now when we print full we get my full name 1880 00:43:37,200 --> 00:43:37,210 when we print full we get my full name 1881 00:43:37,210 --> 00:43:40,050 when we print full we get my full name on the console beautiful now this 1882 00:43:40,050 --> 00:43:40,060 on the console beautiful now this 1883 00:43:40,060 --> 00:43:42,720 on the console beautiful now this approach are using concatenation to 1884 00:43:42,720 --> 00:43:42,730 approach are using concatenation to 1885 00:43:42,730 --> 00:43:45,360 approach are using concatenation to build a string is okay but there is a 1886 00:43:45,360 --> 00:43:45,370 build a string is okay but there is a 1887 00:43:45,370 --> 00:43:48,090 build a string is okay but there is a better and newer approach we can use 1888 00:43:48,090 --> 00:43:48,100 better and newer approach we can use 1889 00:43:48,100 --> 00:43:51,120 better and newer approach we can use formatted strings so here we can set 1890 00:43:51,120 --> 00:43:51,130 formatted strings so here we can set 1891 00:43:51,130 --> 00:43:54,840 formatted strings so here we can set full to this string and prefix it with 1892 00:43:54,840 --> 00:43:54,850 full to this string and prefix it with 1893 00:43:54,850 --> 00:43:57,980 full to this string and prefix it with an F which can be lowercase or uppercase 1894 00:43:57,980 --> 00:43:57,990 an F which can be lowercase or uppercase 1895 00:43:57,990 --> 00:44:00,840 an F which can be lowercase or uppercase this formatted string doesn't have a 1896 00:44:00,840 --> 00:44:00,850 this formatted string doesn't have a 1897 00:44:00,850 --> 00:44:03,630 this formatted string doesn't have a constant value like these two strings 1898 00:44:03,630 --> 00:44:03,640 constant value like these two strings 1899 00:44:03,640 --> 00:44:06,360 constant value like these two strings here it's actually an expression that 1900 00:44:06,360 --> 00:44:06,370 here it's actually an expression that 1901 00:44:06,370 --> 00:44:10,110 here it's actually an expression that will be evaluated at runtime so here we 1902 00:44:10,110 --> 00:44:10,120 will be evaluated at runtime so here we 1903 00:44:10,120 --> 00:44:12,810 will be evaluated at runtime so here we want to add our first name we use curly 1904 00:44:12,810 --> 00:44:12,820 want to add our first name we use curly 1905 00:44:12,820 --> 00:44:16,470 want to add our first name we use curly braces to print the value of the first 1906 00:44:16,470 --> 00:44:16,480 braces to print the value of the first 1907 00:44:16,480 --> 00:44:19,590 braces to print the value of the first variable after that we had in your space 1908 00:44:19,590 --> 00:44:19,600 variable after that we had in your space 1909 00:44:19,600 --> 00:44:22,530 variable after that we had in your space and then we add curly braces one more 1910 00:44:22,530 --> 00:44:22,540 and then we add curly braces one more 1911 00:44:22,540 --> 00:44:26,160 and then we add curly braces one more time to print the last name so at 1912 00:44:26,160 --> 00:44:26,170 time to print the last name so at 1913 00:44:26,170 --> 00:44:27,990 time to print the last name so at runtime this expression will be 1914 00:44:27,990 --> 00:44:28,000 runtime this expression will be 1915 00:44:28,000 --> 00:44:31,560 runtime this expression will be evaluated what we have in between curly 1916 00:44:31,560 --> 00:44:31,570 evaluated what we have in between curly 1917 00:44:31,570 --> 00:44:35,550 evaluated what we have in between curly braces will be replaced at runtime now 1918 00:44:35,550 --> 00:44:35,560 braces will be replaced at runtime now 1919 00:44:35,560 --> 00:44:38,310 braces will be replaced at runtime now let's run this program one more time we 1920 00:44:38,310 --> 00:44:38,320 let's run this program one more time we 1921 00:44:38,320 --> 00:44:41,430 let's run this program one more time we get the exact same result just be aware 1922 00:44:41,430 --> 00:44:41,440 get the exact same result just be aware 1923 00:44:41,440 --> 00:44:43,860 get the exact same result just be aware that you can put any valid expressions 1924 00:44:43,860 --> 00:44:43,870 that you can put any valid expressions 1925 00:44:43,870 --> 00:44:47,100 that you can put any valid expressions in between curly braces so earlier you 1926 00:44:47,100 --> 00:44:47,110 in between curly braces so earlier you 1927 00:44:47,110 --> 00:44:49,640 in between curly braces so earlier you learned about the built-in Len function 1928 00:44:49,640 --> 00:44:49,650 learned about the built-in Len function 1929 00:44:49,650 --> 00:44:53,220 learned about the built-in Len function we can call Len here to get the length 1930 00:44:53,220 --> 00:44:53,230 we can call Len here to get the length 1931 00:44:53,230 --> 00:44:56,490 we can call Len here to get the length of this string let's run this program 1932 00:44:56,490 --> 00:44:56,500 of this string let's run this program 1933 00:44:56,500 --> 00:44:59,450 of this string let's run this program one more time so we get four 1934 00:44:59,450 --> 00:44:59,460 one more time so we get four 1935 00:44:59,460 --> 00:45:01,640 one more time so we get four we can also replace last with an 1936 00:45:01,640 --> 00:45:01,650 we can also replace last with an 1937 00:45:01,650 --> 00:45:05,180 we can also replace last with an expression like this 2+2 let's run this 1938 00:45:05,180 --> 00:45:05,190 expression like this 2+2 let's run this 1939 00:45:05,190 --> 00:45:07,599 expression like this 2+2 let's run this program we get 4 & 4 1940 00:45:07,599 --> 00:45:07,609 program we get 4 & 4 1941 00:45:07,609 --> 00:45:11,270 program we get 4 & 4 so when using formatted strings you can 1942 00:45:11,270 --> 00:45:11,280 so when using formatted strings you can 1943 00:45:11,280 --> 00:45:13,849 so when using formatted strings you can put any valid expressions in between 1944 00:45:13,849 --> 00:45:13,859 put any valid expressions in between 1945 00:45:13,859 --> 00:45:21,729 put any valid expressions in between curly braces 1946 00:45:21,729 --> 00:45:21,739 1947 00:45:21,739 --> 00:45:25,069 in this lecture we're going to look at a 1948 00:45:25,069 --> 00:45:25,079 in this lecture we're going to look at a 1949 00:45:25,079 --> 00:45:27,440 in this lecture we're going to look at a few useful functions available to work 1950 00:45:27,440 --> 00:45:27,450 few useful functions available to work 1951 00:45:27,450 --> 00:45:29,630 few useful functions available to work with strings so earlier you learned 1952 00:45:29,630 --> 00:45:29,640 with strings so earlier you learned 1953 00:45:29,640 --> 00:45:33,019 with strings so earlier you learned about this built-in Len function this 1954 00:45:33,019 --> 00:45:33,029 about this built-in Len function this 1955 00:45:33,029 --> 00:45:35,089 about this built-in Len function this function is general-purpose so it's not 1956 00:45:35,089 --> 00:45:35,099 function is general-purpose so it's not 1957 00:45:35,099 --> 00:45:36,319 function is general-purpose so it's not limited to strings 1958 00:45:36,319 --> 00:45:36,329 limited to strings 1959 00:45:36,329 --> 00:45:38,329 limited to strings later I will show you how to use this 1960 00:45:38,329 --> 00:45:38,339 later I will show you how to use this 1961 00:45:38,339 --> 00:45:41,089 later I will show you how to use this function with other kind of objects but 1962 00:45:41,089 --> 00:45:41,099 function with other kind of objects but 1963 00:45:41,099 --> 00:45:43,099 function with other kind of objects but in Python we have quite a few functions 1964 00:45:43,099 --> 00:45:43,109 in Python we have quite a few functions 1965 00:45:43,109 --> 00:45:45,229 in Python we have quite a few functions that are specific to strings 1966 00:45:45,229 --> 00:45:45,239 that are specific to strings 1967 00:45:45,239 --> 00:45:47,779 that are specific to strings let me show you so here if we type 1968 00:45:47,779 --> 00:45:47,789 let me show you so here if we type 1969 00:45:47,789 --> 00:45:53,440 let me show you so here if we type course dot C all these are functions 1970 00:45:53,440 --> 00:45:53,450 course dot C all these are functions 1971 00:45:53,450 --> 00:45:57,319 course dot C all these are functions available on strings now in precise 1972 00:45:57,319 --> 00:45:57,329 available on strings now in precise 1973 00:45:57,329 --> 00:45:59,569 available on strings now in precise terms we refer to these functions as 1974 00:45:59,569 --> 00:45:59,579 terms we refer to these functions as 1975 00:45:59,579 --> 00:46:02,029 terms we refer to these functions as methods this is a term in 1976 00:46:02,029 --> 00:46:02,039 methods this is a term in 1977 00:46:02,039 --> 00:46:03,739 methods this is a term in object-oriented programming that you 1978 00:46:03,739 --> 00:46:03,749 object-oriented programming that you 1979 00:46:03,749 --> 00:46:05,960 object-oriented programming that you will learn about later in the course for 1980 00:46:05,960 --> 00:46:05,970 will learn about later in the course for 1981 00:46:05,970 --> 00:46:09,079 will learn about later in the course for now what I want you to take away is that 1982 00:46:09,079 --> 00:46:09,089 now what I want you to take away is that 1983 00:46:09,089 --> 00:46:12,130 now what I want you to take away is that everything in Python is an object and 1984 00:46:12,130 --> 00:46:12,140 everything in Python is an object and 1985 00:46:12,140 --> 00:46:15,109 everything in Python is an object and objects have functions we call methods 1986 00:46:15,109 --> 00:46:15,119 objects have functions we call methods 1987 00:46:15,119 --> 00:46:17,420 objects have functions we call methods that we can access using the dot 1988 00:46:17,420 --> 00:46:17,430 that we can access using the dot 1989 00:46:17,430 --> 00:46:21,349 that we can access using the dot notation so here course is an object we 1990 00:46:21,349 --> 00:46:21,359 notation so here course is an object we 1991 00:46:21,359 --> 00:46:23,569 notation so here course is an object we use the dot notation to access its 1992 00:46:23,569 --> 00:46:23,579 use the dot notation to access its 1993 00:46:23,579 --> 00:46:25,999 use the dot notation to access its functions or more accurately methods 1994 00:46:25,999 --> 00:46:26,009 functions or more accurately methods 1995 00:46:26,009 --> 00:46:27,920 functions or more accurately methods let's take a look at a few of these 1996 00:46:27,920 --> 00:46:27,930 let's take a look at a few of these 1997 00:46:27,930 --> 00:46:31,009 let's take a look at a few of these methods we have upper to convert a 1998 00:46:31,009 --> 00:46:31,019 methods we have upper to convert a 1999 00:46:31,019 --> 00:46:34,339 methods we have upper to convert a string to uppercase now let's print this 2000 00:46:34,339 --> 00:46:34,349 string to uppercase now let's print this 2001 00:46:34,349 --> 00:46:38,059 string to uppercase now let's print this and run the program here is what we get 2002 00:46:38,059 --> 00:46:38,069 and run the program here is what we get 2003 00:46:38,069 --> 00:46:40,789 and run the program here is what we get beautiful now note that the metals that 2004 00:46:40,789 --> 00:46:40,799 beautiful now note that the metals that 2005 00:46:40,799 --> 00:46:44,210 beautiful now note that the metals that you call here return a new string so the 2006 00:46:44,210 --> 00:46:44,220 you call here return a new string so the 2007 00:46:44,220 --> 00:46:46,640 you call here return a new string so the original string is not affected let me 2008 00:46:46,640 --> 00:46:46,650 original string is not affected let me 2009 00:46:46,650 --> 00:46:46,999 original string is not affected let me show you 2010 00:46:46,999 --> 00:46:47,009 show you 2011 00:46:47,009 --> 00:46:51,049 show you so print course run the program one more 2012 00:46:51,049 --> 00:46:51,059 so print course run the program one more 2013 00:46:51,059 --> 00:46:53,720 so print course run the program one more time look this is our original string 2014 00:46:53,720 --> 00:46:53,730 time look this is our original string 2015 00:46:53,730 --> 00:46:57,620 time look this is our original string right so course the upper returns a new 2016 00:46:57,620 --> 00:46:57,630 right so course the upper returns a new 2017 00:46:57,630 --> 00:47:00,529 right so course the upper returns a new string a new value we can store it in a 2018 00:47:00,529 --> 00:47:00,539 string a new value we can store it in a 2019 00:47:00,539 --> 00:47:04,269 string a new value we can store it in a variable like course underlined capital 2020 00:47:04,269 --> 00:47:04,279 variable like course underlined capital 2021 00:47:04,279 --> 00:47:08,059 variable like course underlined capital like this now to keep this demo simple 2022 00:47:08,059 --> 00:47:08,069 like this now to keep this demo simple 2023 00:47:08,069 --> 00:47:09,890 like this now to keep this demo simple and consistent I'm gonna revert this 2024 00:47:09,890 --> 00:47:09,900 and consistent I'm gonna revert this 2025 00:47:09,900 --> 00:47:14,210 and consistent I'm gonna revert this back and use a print statement we also 2026 00:47:14,210 --> 00:47:14,220 back and use a print statement we also 2027 00:47:14,220 --> 00:47:17,479 back and use a print statement we also have the lower method to convert a 2028 00:47:17,479 --> 00:47:17,489 have the lower method to convert a 2029 00:47:17,489 --> 00:47:21,170 have the lower method to convert a string to lowercase we also have title 2030 00:47:21,170 --> 00:47:21,180 string to lowercase we also have title 2031 00:47:21,180 --> 00:47:23,930 string to lowercase we also have title which will capitalize the first letter 2032 00:47:23,930 --> 00:47:23,940 which will capitalize the first letter 2033 00:47:23,940 --> 00:47:27,529 which will capitalize the first letter of every word so if our string was like 2034 00:47:27,529 --> 00:47:27,539 of every word so if our string was like 2035 00:47:27,539 --> 00:47:32,239 of every word so if our string was like this when we call the title method we 2036 00:47:32,239 --> 00:47:32,249 this when we call the title method we 2037 00:47:32,249 --> 00:47:33,060 this when we call the title method we get Python 2038 00:47:33,060 --> 00:47:33,070 get Python 2039 00:47:33,070 --> 00:47:37,320 get Python programming as you see here okay another 2040 00:47:37,320 --> 00:47:37,330 programming as you see here okay another 2041 00:47:37,330 --> 00:47:39,870 programming as you see here okay another useful method is strip and we use it to 2042 00:47:39,870 --> 00:47:39,880 useful method is strip and we use it to 2043 00:47:39,880 --> 00:47:42,660 useful method is strip and we use it to trim any white space at the beginning or 2044 00:47:42,660 --> 00:47:42,670 trim any white space at the beginning or 2045 00:47:42,670 --> 00:47:44,850 trim any white space at the beginning or end of a string this is particularly 2046 00:47:44,850 --> 00:47:44,860 end of a string this is particularly 2047 00:47:44,860 --> 00:47:47,310 end of a string this is particularly useful when we receive input from the 2048 00:47:47,310 --> 00:47:47,320 useful when we receive input from the 2049 00:47:47,320 --> 00:47:50,360 useful when we receive input from the user let me show you so let's imagine 2050 00:47:50,360 --> 00:47:50,370 user let me show you so let's imagine 2051 00:47:50,370 --> 00:47:53,700 user let me show you so let's imagine the user entered a couple of white 2052 00:47:53,700 --> 00:47:53,710 the user entered a couple of white 2053 00:47:53,710 --> 00:47:55,760 the user entered a couple of white spaces at the beginning of their string 2054 00:47:55,760 --> 00:47:55,770 spaces at the beginning of their string 2055 00:47:55,770 --> 00:48:00,000 spaces at the beginning of their string when we call course that strip those 2056 00:48:00,000 --> 00:48:00,010 when we call course that strip those 2057 00:48:00,010 --> 00:48:01,800 when we call course that strip those white spaces will be removed 2058 00:48:01,800 --> 00:48:01,810 white spaces will be removed 2059 00:48:01,810 --> 00:48:04,860 white spaces will be removed take a look so note that in the first 2060 00:48:04,860 --> 00:48:04,870 take a look so note that in the first 2061 00:48:04,870 --> 00:48:07,380 take a look so note that in the first three examples we have those white 2062 00:48:07,380 --> 00:48:07,390 three examples we have those white 2063 00:48:07,390 --> 00:48:10,020 three examples we have those white spaces but in the last one it is removed 2064 00:48:10,020 --> 00:48:10,030 spaces but in the last one it is removed 2065 00:48:10,030 --> 00:48:12,810 spaces but in the last one it is removed so a strip removed the whitespace from 2066 00:48:12,810 --> 00:48:12,820 so a strip removed the whitespace from 2067 00:48:12,820 --> 00:48:15,000 so a strip removed the whitespace from both the beginning and end of a string 2068 00:48:15,000 --> 00:48:15,010 both the beginning and end of a string 2069 00:48:15,010 --> 00:48:18,180 both the beginning and end of a string we also have L strip which is short for 2070 00:48:18,180 --> 00:48:18,190 we also have L strip which is short for 2071 00:48:18,190 --> 00:48:21,150 we also have L strip which is short for left strip and our strip which is short 2072 00:48:21,150 --> 00:48:21,160 left strip and our strip which is short 2073 00:48:21,160 --> 00:48:23,430 left strip and our strip which is short for right strip so it will remove the 2074 00:48:23,430 --> 00:48:23,440 for right strip so it will remove the 2075 00:48:23,440 --> 00:48:25,680 for right strip so it will remove the white space from the end of a string if 2076 00:48:25,680 --> 00:48:25,690 white space from the end of a string if 2077 00:48:25,690 --> 00:48:28,740 white space from the end of a string if you want to get the index of a character 2078 00:48:28,740 --> 00:48:28,750 you want to get the index of a character 2079 00:48:28,750 --> 00:48:31,020 you want to get the index of a character or a sequence of characters in your 2080 00:48:31,020 --> 00:48:31,030 or a sequence of characters in your 2081 00:48:31,030 --> 00:48:33,090 or a sequence of characters in your string you should use the find method 2082 00:48:33,090 --> 00:48:33,100 string you should use the find method 2083 00:48:33,100 --> 00:48:34,250 string you should use the find method and mosura 2084 00:48:34,250 --> 00:48:34,260 and mosura 2085 00:48:34,260 --> 00:48:39,840 and mosura so course that find so as an argument 2086 00:48:39,840 --> 00:48:39,850 so course that find so as an argument 2087 00:48:39,850 --> 00:48:43,140 so course that find so as an argument here we pass another string we can pass 2088 00:48:43,140 --> 00:48:43,150 here we pass another string we can pass 2089 00:48:43,150 --> 00:48:46,560 here we pass another string we can pass a character or a series of characters 2090 00:48:46,560 --> 00:48:46,570 a character or a series of characters 2091 00:48:46,570 --> 00:48:51,000 a character or a series of characters let's find the index of Pro run the 2092 00:48:51,000 --> 00:48:51,010 let's find the index of Pro run the 2093 00:48:51,010 --> 00:48:54,660 let's find the index of Pro run the program so the index of Pro is 9 so if 2094 00:48:54,660 --> 00:48:54,670 program so the index of Pro is 9 so if 2095 00:48:54,670 --> 00:48:57,720 program so the index of Pro is 9 so if you start from 0 here all the way to 9 2096 00:48:57,720 --> 00:48:57,730 you start from 0 here all the way to 9 2097 00:48:57,730 --> 00:49:02,250 you start from 0 here all the way to 9 this is the index of Pro ok now as I 2098 00:49:02,250 --> 00:49:02,260 this is the index of Pro ok now as I 2099 00:49:02,260 --> 00:49:03,870 this is the index of Pro ok now as I told you before python is a case 2100 00:49:03,870 --> 00:49:03,880 told you before python is a case 2101 00:49:03,880 --> 00:49:06,750 told you before python is a case sensitive language so if I pass a 2102 00:49:06,750 --> 00:49:06,760 sensitive language so if I pass a 2103 00:49:06,760 --> 00:49:09,540 sensitive language so if I pass a capital P here obviously we don't have 2104 00:49:09,540 --> 00:49:09,550 capital P here obviously we don't have 2105 00:49:09,550 --> 00:49:13,200 capital P here obviously we don't have these exact characters in our string so 2106 00:49:13,200 --> 00:49:13,210 these exact characters in our string so 2107 00:49:13,210 --> 00:49:16,380 these exact characters in our string so let's see what we get we get negative 1 2108 00:49:16,380 --> 00:49:16,390 let's see what we get we get negative 1 2109 00:49:16,390 --> 00:49:19,260 let's see what we get we get negative 1 that means this string was not found in 2110 00:49:19,260 --> 00:49:19,270 that means this string was not found in 2111 00:49:19,270 --> 00:49:22,230 that means this string was not found in the original string another useful 2112 00:49:22,230 --> 00:49:22,240 the original string another useful 2113 00:49:22,240 --> 00:49:26,750 the original string another useful method is replaced so we call replace 2114 00:49:26,750 --> 00:49:26,760 method is replaced so we call replace 2115 00:49:26,760 --> 00:49:29,700 method is replaced so we call replace with this we can replace a character or 2116 00:49:29,700 --> 00:49:29,710 with this we can replace a character or 2117 00:49:29,710 --> 00:49:31,800 with this we can replace a character or a sequence of characters with something 2118 00:49:31,800 --> 00:49:31,810 a sequence of characters with something 2119 00:49:31,810 --> 00:49:34,290 a sequence of characters with something else so let's say we want to replace all 2120 00:49:34,290 --> 00:49:34,300 else so let's say we want to replace all 2121 00:49:34,300 --> 00:49:39,830 else so let's say we want to replace all lowercase Peas with J with this we get 2122 00:49:39,830 --> 00:49:39,840 lowercase Peas with J with this we get 2123 00:49:39,840 --> 00:49:42,050 lowercase Peas with J with this we get jython Jeremy 2124 00:49:42,050 --> 00:49:42,060 jython Jeremy 2125 00:49:42,060 --> 00:49:45,630 jython Jeremy whatever that means and finally if you 2126 00:49:45,630 --> 00:49:45,640 whatever that means and finally if you 2127 00:49:45,640 --> 00:49:46,620 whatever that means and finally if you want to check for the 2128 00:49:46,620 --> 00:49:46,630 want to check for the 2129 00:49:46,630 --> 00:49:49,529 want to check for the existence of a character or a sequence 2130 00:49:49,529 --> 00:49:49,539 existence of a character or a sequence 2131 00:49:49,539 --> 00:49:51,809 existence of a character or a sequence of characters in your string you can use 2132 00:49:51,809 --> 00:49:51,819 of characters in your string you can use 2133 00:49:51,819 --> 00:49:56,120 of characters in your string you can use the in operator let me show you so print 2134 00:49:56,120 --> 00:49:56,130 the in operator let me show you so print 2135 00:49:56,130 --> 00:50:00,319 the in operator let me show you so print rewrite an expression like this pro in 2136 00:50:00,319 --> 00:50:00,329 rewrite an expression like this pro in 2137 00:50:00,329 --> 00:50:04,470 rewrite an expression like this pro in chorus so this is an expression as I 2138 00:50:04,470 --> 00:50:04,480 chorus so this is an expression as I 2139 00:50:04,480 --> 00:50:06,390 chorus so this is an expression as I told you before an expression is a piece 2140 00:50:06,390 --> 00:50:06,400 told you before an expression is a piece 2141 00:50:06,400 --> 00:50:09,329 told you before an expression is a piece of code that produces a value so this 2142 00:50:09,329 --> 00:50:09,339 of code that produces a value so this 2143 00:50:09,339 --> 00:50:11,640 of code that produces a value so this expression checks to see if you have Pro 2144 00:50:11,640 --> 00:50:11,650 expression checks to see if you have Pro 2145 00:50:11,650 --> 00:50:14,759 expression checks to see if you have Pro in course the difference between this 2146 00:50:14,759 --> 00:50:14,769 in course the difference between this 2147 00:50:14,769 --> 00:50:17,160 in course the difference between this expression and calling the find method 2148 00:50:17,160 --> 00:50:17,170 expression and calling the find method 2149 00:50:17,170 --> 00:50:19,529 expression and calling the find method is that the find method returns the 2150 00:50:19,529 --> 00:50:19,539 is that the find method returns the 2151 00:50:19,539 --> 00:50:23,190 is that the find method returns the index of these characters in our string 2152 00:50:23,190 --> 00:50:23,200 index of these characters in our string 2153 00:50:23,200 --> 00:50:25,890 index of these characters in our string but as this expression returns a boolean 2154 00:50:25,890 --> 00:50:25,900 but as this expression returns a boolean 2155 00:50:25,900 --> 00:50:28,410 but as this expression returns a boolean so it's a true or false let me show you 2156 00:50:28,410 --> 00:50:28,420 so it's a true or false let me show you 2157 00:50:28,420 --> 00:50:32,849 so it's a true or false let me show you so run the program we get the boolean 2158 00:50:32,849 --> 00:50:32,859 so run the program we get the boolean 2159 00:50:32,859 --> 00:50:36,480 so run the program we get the boolean true and finally we have the not 2160 00:50:36,480 --> 00:50:36,490 true and finally we have the not 2161 00:50:36,490 --> 00:50:39,059 true and finally we have the not operator and we use that to see if our 2162 00:50:39,059 --> 00:50:39,069 operator and we use that to see if our 2163 00:50:39,069 --> 00:50:42,359 operator and we use that to see if our string does not contain a character or 2164 00:50:42,359 --> 00:50:42,369 string does not contain a character or 2165 00:50:42,369 --> 00:50:47,069 string does not contain a character or sequence of characters so let's change 2166 00:50:47,069 --> 00:50:47,079 sequence of characters so let's change 2167 00:50:47,079 --> 00:50:53,519 sequence of characters so let's change this to swift not in course when this 2168 00:50:53,519 --> 00:50:53,529 this to swift not in course when this 2169 00:50:53,529 --> 00:50:55,680 this to swift not in course when this expression is evaluated what do you 2170 00:50:55,680 --> 00:50:55,690 expression is evaluated what do you 2171 00:50:55,690 --> 00:50:58,140 expression is evaluated what do you think we're gonna get well we don't have 2172 00:50:58,140 --> 00:50:58,150 think we're gonna get well we don't have 2173 00:50:58,150 --> 00:51:02,160 think we're gonna get well we don't have Swift in this string so not in we'll 2174 00:51:02,160 --> 00:51:02,170 Swift in this string so not in we'll 2175 00:51:02,170 --> 00:51:06,450 Swift in this string so not in we'll return true let's take a look there you 2176 00:51:06,450 --> 00:51:06,460 return true let's take a look there you 2177 00:51:06,460 --> 00:51:07,790 return true let's take a look there you go 2178 00:51:07,790 --> 00:51:07,800 go 2179 00:51:07,800 --> 00:51:10,130 go so these are the useful string methods 2180 00:51:10,130 --> 00:51:10,140 so these are the useful string methods 2181 00:51:10,140 --> 00:51:19,079 so these are the useful string methods next we'll look at numbers 2182 00:51:19,079 --> 00:51:19,089 2183 00:51:19,089 --> 00:51:22,420 in Python we have three types of numbers 2184 00:51:22,420 --> 00:51:22,430 in Python we have three types of numbers 2185 00:51:22,430 --> 00:51:24,249 in Python we have three types of numbers two of these you have already seen 2186 00:51:24,249 --> 00:51:24,259 two of these you have already seen 2187 00:51:24,259 --> 00:51:28,690 two of these you have already seen before they are integers and floats we 2188 00:51:28,690 --> 00:51:28,700 before they are integers and floats we 2189 00:51:28,700 --> 00:51:32,289 before they are integers and floats we also have complex numbers so complex 2190 00:51:32,289 --> 00:51:32,299 also have complex numbers so complex 2191 00:51:32,299 --> 00:51:35,230 also have complex numbers so complex numbers in math are in the form a plus 2192 00:51:35,230 --> 00:51:35,240 numbers in math are in the form a plus 2193 00:51:35,240 --> 00:51:39,370 numbers in math are in the form a plus bi where I is the imaginary number now 2194 00:51:39,370 --> 00:51:39,380 bi where I is the imaginary number now 2195 00:51:39,380 --> 00:51:40,630 bi where I is the imaginary number now if you're not familiar with this concept 2196 00:51:40,630 --> 00:51:40,640 if you're not familiar with this concept 2197 00:51:40,640 --> 00:51:42,759 if you're not familiar with this concept don't worry this is something that is 2198 00:51:42,759 --> 00:51:42,769 don't worry this is something that is 2199 00:51:42,769 --> 00:51:44,980 don't worry this is something that is used a lot in mathematics and electrical 2200 00:51:44,980 --> 00:51:44,990 used a lot in mathematics and electrical 2201 00:51:44,990 --> 00:51:47,859 used a lot in mathematics and electrical engineering if you want to use Python to 2202 00:51:47,859 --> 00:51:47,869 engineering if you want to use Python to 2203 00:51:47,869 --> 00:51:49,749 engineering if you want to use Python to build web applications you're never 2204 00:51:49,749 --> 00:51:49,759 build web applications you're never 2205 00:51:49,759 --> 00:51:52,150 build web applications you're never gonna use complex numbers but let me 2206 00:51:52,150 --> 00:51:52,160 gonna use complex numbers but let me 2207 00:51:52,160 --> 00:51:53,620 gonna use complex numbers but let me quickly show you the syntax for 2208 00:51:53,620 --> 00:51:53,630 quickly show you the syntax for 2209 00:51:53,630 --> 00:51:56,769 quickly show you the syntax for representing complex numbers instead of 2210 00:51:56,769 --> 00:51:56,779 representing complex numbers instead of 2211 00:51:56,779 --> 00:52:01,299 representing complex numbers instead of i we use J so here is an example 1 plus 2212 00:52:01,299 --> 00:52:01,309 i we use J so here is an example 1 plus 2213 00:52:01,309 --> 00:52:05,920 i we use J so here is an example 1 plus 2 J so X now is a complex number and by 2214 00:52:05,920 --> 00:52:05,930 2 J so X now is a complex number and by 2215 00:52:05,930 --> 00:52:07,450 2 J so X now is a complex number and by the way as I told you before this is 2216 00:52:07,450 --> 00:52:07,460 the way as I told you before this is 2217 00:52:07,460 --> 00:52:10,359 the way as I told you before this is just a comment or an additional note in 2218 00:52:10,359 --> 00:52:10,369 just a comment or an additional note in 2219 00:52:10,369 --> 00:52:12,359 just a comment or an additional note in our program when we run this program 2220 00:52:12,359 --> 00:52:12,369 our program when we run this program 2221 00:52:12,369 --> 00:52:14,829 our program when we run this program anything after this hash sign will be 2222 00:52:14,829 --> 00:52:14,839 anything after this hash sign will be 2223 00:52:14,839 --> 00:52:17,529 anything after this hash sign will be ignored so these are the three types of 2224 00:52:17,529 --> 00:52:17,539 ignored so these are the three types of 2225 00:52:17,539 --> 00:52:20,079 ignored so these are the three types of numbers we have in Python for all these 2226 00:52:20,079 --> 00:52:20,089 numbers we have in Python for all these 2227 00:52:20,089 --> 00:52:22,569 numbers we have in Python for all these types of numbers we have the standard 2228 00:52:22,569 --> 00:52:22,579 types of numbers we have the standard 2229 00:52:22,579 --> 00:52:25,180 types of numbers we have the standard arithmetic operations that we have in 2230 00:52:25,180 --> 00:52:25,190 arithmetic operations that we have in 2231 00:52:25,190 --> 00:52:30,989 arithmetic operations that we have in math let me show you so we have addition 2232 00:52:30,989 --> 00:52:30,999 math let me show you so we have addition 2233 00:52:30,999 --> 00:52:36,069 math let me show you so we have addition subtraction multiplication division but 2234 00:52:36,069 --> 00:52:36,079 subtraction multiplication division but 2235 00:52:36,079 --> 00:52:37,749 subtraction multiplication division but we actually have two different types of 2236 00:52:37,749 --> 00:52:37,759 we actually have two different types of 2237 00:52:37,759 --> 00:52:40,599 we actually have two different types of divisions let me show you first let's 2238 00:52:40,599 --> 00:52:40,609 divisions let me show you first let's 2239 00:52:40,609 --> 00:52:43,089 divisions let me show you first let's run this program so with this division 2240 00:52:43,089 --> 00:52:43,099 run this program so with this division 2241 00:52:43,099 --> 00:52:46,329 run this program so with this division operator which is a slash we get a 2242 00:52:46,329 --> 00:52:46,339 operator which is a slash we get a 2243 00:52:46,339 --> 00:52:49,089 operator which is a slash we get a floating-point number if you want an 2244 00:52:49,089 --> 00:52:49,099 floating-point number if you want an 2245 00:52:49,099 --> 00:52:52,390 floating-point number if you want an integer you use double slashes let me 2246 00:52:52,390 --> 00:52:52,400 integer you use double slashes let me 2247 00:52:52,400 --> 00:52:56,940 integer you use double slashes let me show you so double slash run the program 2248 00:52:56,940 --> 00:52:56,950 show you so double slash run the program 2249 00:52:56,950 --> 00:53:03,400 show you so double slash run the program we get 3 ok we also have modulus which 2250 00:53:03,400 --> 00:53:03,410 we get 3 ok we also have modulus which 2251 00:53:03,410 --> 00:53:05,220 we get 3 ok we also have modulus which is the remainder of a division and 2252 00:53:05,220 --> 00:53:05,230 is the remainder of a division and 2253 00:53:05,230 --> 00:53:09,220 is the remainder of a division and finally exponent which is left to the 2254 00:53:09,220 --> 00:53:09,230 finally exponent which is left to the 2255 00:53:09,230 --> 00:53:12,309 finally exponent which is left to the power of right so 10 to the power of 3 2256 00:53:12,309 --> 00:53:12,319 power of right so 10 to the power of 3 2257 00:53:12,319 --> 00:53:14,859 power of right so 10 to the power of 3 will be a thousand these are the 2258 00:53:14,859 --> 00:53:14,869 will be a thousand these are the 2259 00:53:14,869 --> 00:53:17,890 will be a thousand these are the standard arithmetic operators now for 2260 00:53:17,890 --> 00:53:17,900 standard arithmetic operators now for 2261 00:53:17,900 --> 00:53:20,170 standard arithmetic operators now for all these operators we have a special 2262 00:53:20,170 --> 00:53:20,180 all these operators we have a special 2263 00:53:20,180 --> 00:53:23,170 all these operators we have a special operator called augmented assignment 2264 00:53:23,170 --> 00:53:23,180 operator called augmented assignment 2265 00:53:23,180 --> 00:53:25,809 operator called augmented assignment operator let me show you so let's 2266 00:53:25,809 --> 00:53:25,819 operator let me show you so let's 2267 00:53:25,819 --> 00:53:29,700 operator let me show you so let's imagine we have X set to 10 2268 00:53:29,700 --> 00:53:29,710 imagine we have X set to 10 2269 00:53:29,710 --> 00:53:32,579 imagine we have X set to 10 we want to increment X by let's say 2270 00:53:32,579 --> 00:53:32,589 we want to increment X by let's say 2271 00:53:32,589 --> 00:53:35,040 we want to increment X by let's say three we can write an expression like 2272 00:53:35,040 --> 00:53:35,050 three we can write an expression like 2273 00:53:35,050 --> 00:53:39,270 three we can write an expression like this x equals x plus three or we can use 2274 00:53:39,270 --> 00:53:39,280 this x equals x plus three or we can use 2275 00:53:39,280 --> 00:53:42,150 this x equals x plus three or we can use an Augmented assignment operator that is 2276 00:53:42,150 --> 00:53:42,160 an Augmented assignment operator that is 2277 00:53:42,160 --> 00:53:45,200 an Augmented assignment operator that is a little bit shorter so we write x plus 2278 00:53:45,200 --> 00:53:45,210 a little bit shorter so we write x plus 2279 00:53:45,210 --> 00:53:49,020 a little bit shorter so we write x plus equal three these two statements are 2280 00:53:49,020 --> 00:53:49,030 equal three these two statements are 2281 00:53:49,030 --> 00:53:51,770 equal three these two statements are exactly the same now here I'm using 2282 00:53:51,770 --> 00:53:51,780 exactly the same now here I'm using 2283 00:53:51,780 --> 00:53:54,660 exactly the same now here I'm using addition as an example you can use any 2284 00:53:54,660 --> 00:53:54,670 addition as an example you can use any 2285 00:53:54,670 --> 00:53:58,170 addition as an example you can use any of these operators here next I'm going 2286 00:53:58,170 --> 00:53:58,180 of these operators here next I'm going 2287 00:53:58,180 --> 00:54:00,089 of these operators here next I'm going to show you some useful functions to 2288 00:54:00,089 --> 00:54:00,099 to show you some useful functions to 2289 00:54:00,099 --> 00:54:07,600 to show you some useful functions to work with numbers 2290 00:54:07,600 --> 00:54:07,610 2291 00:54:07,610 --> 00:54:10,430 in this lecture we're going to look at a 2292 00:54:10,430 --> 00:54:10,440 in this lecture we're going to look at a 2293 00:54:10,440 --> 00:54:12,350 in this lecture we're going to look at a few useful functions to work with 2294 00:54:12,350 --> 00:54:12,360 few useful functions to work with 2295 00:54:12,360 --> 00:54:14,930 few useful functions to work with numbers so we have this built-in 2296 00:54:14,930 --> 00:54:14,940 numbers so we have this built-in 2297 00:54:14,940 --> 00:54:18,770 numbers so we have this built-in function round for rounding a number so 2298 00:54:18,770 --> 00:54:18,780 function round for rounding a number so 2299 00:54:18,780 --> 00:54:22,420 function round for rounding a number so if we pass 2.9 here and print the result 2300 00:54:22,420 --> 00:54:22,430 if we pass 2.9 here and print the result 2301 00:54:22,430 --> 00:54:26,900 if we pass 2.9 here and print the result we'll get 3 we have another useful 2302 00:54:26,900 --> 00:54:26,910 we'll get 3 we have another useful 2303 00:54:26,910 --> 00:54:29,600 we'll get 3 we have another useful built-in function called ABS which 2304 00:54:29,600 --> 00:54:29,610 built-in function called ABS which 2305 00:54:29,610 --> 00:54:31,760 built-in function called ABS which returns the absolute value of a number 2306 00:54:31,760 --> 00:54:31,770 returns the absolute value of a number 2307 00:54:31,770 --> 00:54:35,390 returns the absolute value of a number so if you pass negative 2.9 here we'll 2308 00:54:35,390 --> 00:54:35,400 so if you pass negative 2.9 here we'll 2309 00:54:35,400 --> 00:54:41,000 so if you pass negative 2.9 here we'll get positive 2.9 technically we have 2310 00:54:41,000 --> 00:54:41,010 get positive 2.9 technically we have 2311 00:54:41,010 --> 00:54:43,670 get positive 2.9 technically we have only a handful of built-in functions to 2312 00:54:43,670 --> 00:54:43,680 only a handful of built-in functions to 2313 00:54:43,680 --> 00:54:45,770 only a handful of built-in functions to work with numbers if you want to write a 2314 00:54:45,770 --> 00:54:45,780 work with numbers if you want to write a 2315 00:54:45,780 --> 00:54:48,190 work with numbers if you want to write a program that involves complex 2316 00:54:48,190 --> 00:54:48,200 program that involves complex 2317 00:54:48,200 --> 00:54:50,900 program that involves complex mathematical calculations you need to 2318 00:54:50,900 --> 00:54:50,910 mathematical calculations you need to 2319 00:54:50,910 --> 00:54:54,080 mathematical calculations you need to use the math module a module is like a 2320 00:54:54,080 --> 00:54:54,090 use the math module a module is like a 2321 00:54:54,090 --> 00:54:56,900 use the math module a module is like a separate file with some Python code so 2322 00:54:56,900 --> 00:54:56,910 separate file with some Python code so 2323 00:54:56,910 --> 00:54:59,330 separate file with some Python code so in Python we have this math module which 2324 00:54:59,330 --> 00:54:59,340 in Python we have this math module which 2325 00:54:59,340 --> 00:55:01,790 in Python we have this math module which includes lots of mathematical functions 2326 00:55:01,790 --> 00:55:01,800 includes lots of mathematical functions 2327 00:55:01,800 --> 00:55:04,130 includes lots of mathematical functions or working with numbers but we need to 2328 00:55:04,130 --> 00:55:04,140 or working with numbers but we need to 2329 00:55:04,140 --> 00:55:07,340 or working with numbers but we need to import this module so we can use it on 2330 00:55:07,340 --> 00:55:07,350 import this module so we can use it on 2331 00:55:07,350 --> 00:55:12,590 import this module so we can use it on the top we type import math now math in 2332 00:55:12,590 --> 00:55:12,600 the top we type import math now math in 2333 00:55:12,600 --> 00:55:15,980 the top we type import math now math in this program is an object so we can use 2334 00:55:15,980 --> 00:55:15,990 this program is an object so we can use 2335 00:55:15,990 --> 00:55:19,220 this program is an object so we can use the dot notation to see all the 2336 00:55:19,220 --> 00:55:19,230 the dot notation to see all the 2337 00:55:19,230 --> 00:55:21,860 the dot notation to see all the functions or more accurately all the 2338 00:55:21,860 --> 00:55:21,870 functions or more accurately all the 2339 00:55:21,870 --> 00:55:25,220 functions or more accurately all the methods available in this object as an 2340 00:55:25,220 --> 00:55:25,230 methods available in this object as an 2341 00:55:25,230 --> 00:55:28,790 methods available in this object as an example we have math dot seal for 2342 00:55:28,790 --> 00:55:28,800 example we have math dot seal for 2343 00:55:28,800 --> 00:55:31,040 example we have math dot seal for getting the sealing of a number so if 2344 00:55:31,040 --> 00:55:31,050 getting the sealing of a number so if 2345 00:55:31,050 --> 00:55:35,530 getting the sealing of a number so if you pass 2.2 here and run this program 2346 00:55:35,530 --> 00:55:35,540 you pass 2.2 here and run this program 2347 00:55:35,540 --> 00:55:40,520 you pass 2.2 here and run this program we get 3 now in this math module we have 2348 00:55:40,520 --> 00:55:40,530 we get 3 now in this math module we have 2349 00:55:40,530 --> 00:55:42,590 we get 3 now in this math module we have lots of functions let me show you how to 2350 00:55:42,590 --> 00:55:42,600 lots of functions let me show you how to 2351 00:55:42,600 --> 00:55:45,890 lots of functions let me show you how to find the conflict list here on Google 2352 00:55:45,890 --> 00:55:45,900 find the conflict list here on Google 2353 00:55:45,900 --> 00:55:49,550 find the conflict list here on Google search for Python 3 make sure to add the 2354 00:55:49,550 --> 00:55:49,560 search for Python 3 make sure to add the 2355 00:55:49,560 --> 00:55:56,710 search for Python 3 make sure to add the version number math module on this page 2356 00:55:56,710 --> 00:55:56,720 version number math module on this page 2357 00:55:56,720 --> 00:55:59,110 version number math module on this page you can see all the functions in the 2358 00:55:59,110 --> 00:55:59,120 you can see all the functions in the 2359 00:55:59,120 --> 00:56:01,240 you can see all the functions in the math module so in this lecture we looked 2360 00:56:01,240 --> 00:56:01,250 math module so in this lecture we looked 2361 00:56:01,250 --> 00:56:04,930 math module so in this lecture we looked at math dot seal we also have math but 2362 00:56:04,930 --> 00:56:04,940 at math dot seal we also have math but 2363 00:56:04,940 --> 00:56:08,410 at math dot seal we also have math but copy sign fabs and so on as an exercise 2364 00:56:08,410 --> 00:56:08,420 copy sign fabs and so on as an exercise 2365 00:56:08,420 --> 00:56:10,480 copy sign fabs and so on as an exercise I encourage you to play with a couple of 2366 00:56:10,480 --> 00:56:10,490 I encourage you to play with a couple of 2367 00:56:10,490 --> 00:56:19,180 I encourage you to play with a couple of functions in this module 2368 00:56:19,180 --> 00:56:19,190 2369 00:56:19,190 --> 00:56:21,829 alright now let's take a look at another 2370 00:56:21,829 --> 00:56:21,839 alright now let's take a look at another 2371 00:56:21,839 --> 00:56:25,099 alright now let's take a look at another useful built-in function in Python we 2372 00:56:25,099 --> 00:56:25,109 useful built-in function in Python we 2373 00:56:25,109 --> 00:56:27,650 useful built-in function in Python we use the input function to get input from 2374 00:56:27,650 --> 00:56:27,660 use the input function to get input from 2375 00:56:27,660 --> 00:56:31,339 use the input function to get input from the user as an argument to pass a string 2376 00:56:31,339 --> 00:56:31,349 the user as an argument to pass a string 2377 00:56:31,349 --> 00:56:33,410 the user as an argument to pass a string this will be a label that will be 2378 00:56:33,410 --> 00:56:33,420 this will be a label that will be 2379 00:56:33,420 --> 00:56:35,509 this will be a label that will be displayed in the terminal you will see 2380 00:56:35,509 --> 00:56:35,519 displayed in the terminal you will see 2381 00:56:35,519 --> 00:56:39,289 displayed in the terminal you will see that in a second so let's add X : 2382 00:56:39,289 --> 00:56:39,299 that in a second so let's add X : 2383 00:56:39,299 --> 00:56:42,559 that in a second so let's add X : now this function returns a string so we 2384 00:56:42,559 --> 00:56:42,569 now this function returns a string so we 2385 00:56:42,569 --> 00:56:46,400 now this function returns a string so we can store it in this variable now let's 2386 00:56:46,400 --> 00:56:46,410 can store it in this variable now let's 2387 00:56:46,410 --> 00:56:51,380 can store it in this variable now let's imagine that Y should be X plus 1 save 2388 00:56:51,380 --> 00:56:51,390 imagine that Y should be X plus 1 save 2389 00:56:51,390 --> 00:56:53,809 imagine that Y should be X plus 1 save the changes now don't run this program 2390 00:56:53,809 --> 00:56:53,819 the changes now don't run this program 2391 00:56:53,819 --> 00:56:56,660 the changes now don't run this program using the code runner extension because 2392 00:56:56,660 --> 00:56:56,670 using the code runner extension because 2393 00:56:56,670 --> 00:56:59,449 using the code runner extension because code Runner by default runs your program 2394 00:56:59,449 --> 00:56:59,459 code Runner by default runs your program 2395 00:56:59,459 --> 00:57:01,309 code Runner by default runs your program in the output window which is read-only 2396 00:57:01,309 --> 00:57:01,319 in the output window which is read-only 2397 00:57:01,319 --> 00:57:04,880 in the output window which is read-only so you won't be able to enter a value so 2398 00:57:04,880 --> 00:57:04,890 so you won't be able to enter a value so 2399 00:57:04,890 --> 00:57:07,430 so you won't be able to enter a value so open up the terminal using ctrl + 2400 00:57:07,430 --> 00:57:07,440 open up the terminal using ctrl + 2401 00:57:07,440 --> 00:57:10,130 open up the terminal using ctrl + backspace once again if you're on 2402 00:57:10,130 --> 00:57:10,140 backspace once again if you're on 2403 00:57:10,140 --> 00:57:12,380 backspace once again if you're on Windows type Python if you're on Mac or 2404 00:57:12,380 --> 00:57:12,390 Windows type Python if you're on Mac or 2405 00:57:12,390 --> 00:57:16,209 Windows type Python if you're on Mac or Linux type Python 3 and then app that PI 2406 00:57:16,209 --> 00:57:16,219 Linux type Python 3 and then app that PI 2407 00:57:16,219 --> 00:57:19,279 Linux type Python 3 and then app that PI so here's our label let's enter a value 2408 00:57:19,279 --> 00:57:19,289 so here's our label let's enter a value 2409 00:57:19,289 --> 00:57:24,049 so here's our label let's enter a value like fun we got an error type error what 2410 00:57:24,049 --> 00:57:24,059 like fun we got an error type error what 2411 00:57:24,059 --> 00:57:27,559 like fun we got an error type error what is going on here well when we receive 2412 00:57:27,559 --> 00:57:27,569 is going on here well when we receive 2413 00:57:27,569 --> 00:57:29,749 is going on here well when we receive input from the user this input always 2414 00:57:29,749 --> 00:57:29,759 input from the user this input always 2415 00:57:29,759 --> 00:57:33,589 input from the user this input always comes as a string so this expression at 2416 00:57:33,589 --> 00:57:33,599 comes as a string so this expression at 2417 00:57:33,599 --> 00:57:37,249 comes as a string so this expression at runtime will look like this string 1 2418 00:57:37,249 --> 00:57:37,259 runtime will look like this string 1 2419 00:57:37,259 --> 00:57:40,489 runtime will look like this string 1 plus 1 note that the number 1 is 2420 00:57:40,489 --> 00:57:40,499 plus 1 note that the number 1 is 2421 00:57:40,499 --> 00:57:42,890 plus 1 note that the number 1 is different from string 1 because these 2422 00:57:42,890 --> 00:57:42,900 different from string 1 because these 2423 00:57:42,900 --> 00:57:44,150 different from string 1 because these are two different types 2424 00:57:44,150 --> 00:57:44,160 are two different types 2425 00:57:44,160 --> 00:57:46,670 are two different types now when Python sees this expression it 2426 00:57:46,670 --> 00:57:46,680 now when Python sees this expression it 2427 00:57:46,680 --> 00:57:49,069 now when Python sees this expression it doesn't know what to do because two 2428 00:57:49,069 --> 00:57:49,079 doesn't know what to do because two 2429 00:57:49,079 --> 00:57:51,410 doesn't know what to do because two objects can be concatenated if there are 2430 00:57:51,410 --> 00:57:51,420 objects can be concatenated if there are 2431 00:57:51,420 --> 00:57:53,930 objects can be concatenated if there are of the same type so here we need to 2432 00:57:53,930 --> 00:57:53,940 of the same type so here we need to 2433 00:57:53,940 --> 00:57:57,439 of the same type so here we need to convert this string 1 to a number in 2434 00:57:57,439 --> 00:57:57,449 convert this string 1 to a number in 2435 00:57:57,449 --> 00:57:59,839 convert this string 1 to a number in Python we have a few built-in functions 2436 00:57:59,839 --> 00:57:59,849 Python we have a few built-in functions 2437 00:57:59,849 --> 00:58:03,920 Python we have a few built-in functions for type conversion we have int for 2438 00:58:03,920 --> 00:58:03,930 for type conversion we have int for 2439 00:58:03,930 --> 00:58:06,620 for type conversion we have int for converting a number to an integer we 2440 00:58:06,620 --> 00:58:06,630 converting a number to an integer we 2441 00:58:06,630 --> 00:58:08,750 converting a number to an integer we have float 2442 00:58:08,750 --> 00:58:08,760 have float 2443 00:58:08,760 --> 00:58:13,310 have float we have bull and stir or string now in 2444 00:58:13,310 --> 00:58:13,320 we have bull and stir or string now in 2445 00:58:13,320 --> 00:58:14,930 we have bull and stir or string now in this case we don't need to convert eggs 2446 00:58:14,930 --> 00:58:14,940 this case we don't need to convert eggs 2447 00:58:14,940 --> 00:58:17,180 this case we don't need to convert eggs to a string because X is already a 2448 00:58:17,180 --> 00:58:17,190 to a string because X is already a 2449 00:58:17,190 --> 00:58:19,070 to a string because X is already a string if you don't believe me let me 2450 00:58:19,070 --> 00:58:19,080 string if you don't believe me let me 2451 00:58:19,080 --> 00:58:21,560 string if you don't believe me let me show you so I'm gonna comment out these 2452 00:58:21,560 --> 00:58:21,570 show you so I'm gonna comment out these 2453 00:58:21,570 --> 00:58:29,720 show you so I'm gonna comment out these few lines now let's print type of X so 2454 00:58:29,720 --> 00:58:29,730 few lines now let's print type of X so 2455 00:58:29,730 --> 00:58:32,210 few lines now let's print type of X so type is another built-in function we 2456 00:58:32,210 --> 00:58:32,220 type is another built-in function we 2457 00:58:32,220 --> 00:58:34,670 type is another built-in function we pass an object as an argument and it 2458 00:58:34,670 --> 00:58:34,680 pass an object as an argument and it 2459 00:58:34,680 --> 00:58:37,430 pass an object as an argument and it returns its type also I'm gonna comment 2460 00:58:37,430 --> 00:58:37,440 returns its type also I'm gonna comment 2461 00:58:37,440 --> 00:58:39,830 returns its type also I'm gonna comment out this line because that's the bad boy 2462 00:58:39,830 --> 00:58:39,840 out this line because that's the bad boy 2463 00:58:39,840 --> 00:58:41,930 out this line because that's the bad boy we don't want to execute this save the 2464 00:58:41,930 --> 00:58:41,940 we don't want to execute this save the 2465 00:58:41,940 --> 00:58:44,690 we don't want to execute this save the changes back in the terminal let's run 2466 00:58:44,690 --> 00:58:44,700 changes back in the terminal let's run 2467 00:58:44,700 --> 00:58:48,160 changes back in the terminal let's run this program one more time enter 1 look 2468 00:58:48,160 --> 00:58:48,170 this program one more time enter 1 look 2469 00:58:48,170 --> 00:58:50,810 this program one more time enter 1 look this is what the type function returns 2470 00:58:50,810 --> 00:58:50,820 this is what the type function returns 2471 00:58:50,820 --> 00:58:53,450 this is what the type function returns don't worry about the class we'll talk 2472 00:58:53,450 --> 00:58:53,460 don't worry about the class we'll talk 2473 00:58:53,460 --> 00:58:55,850 don't worry about the class we'll talk about classes later in the course so the 2474 00:58:55,850 --> 00:58:55,860 about classes later in the course so the 2475 00:58:55,860 --> 00:59:01,250 about classes later in the course so the type of X is histor or string so let's 2476 00:59:01,250 --> 00:59:01,260 type of X is histor or string so let's 2477 00:59:01,260 --> 00:59:04,790 type of X is histor or string so let's delete this line to fix this problem we 2478 00:59:04,790 --> 00:59:04,800 delete this line to fix this problem we 2479 00:59:04,800 --> 00:59:08,540 delete this line to fix this problem we need to convert X to an integer and then 2480 00:59:08,540 --> 00:59:08,550 need to convert X to an integer and then 2481 00:59:08,550 --> 00:59:11,600 need to convert X to an integer and then we can print both x and y using a 2482 00:59:11,600 --> 00:59:11,610 we can print both x and y using a 2483 00:59:11,610 --> 00:59:14,660 we can print both x and y using a formatted string remember so we had an F 2484 00:59:14,660 --> 00:59:14,670 formatted string remember so we had an F 2485 00:59:14,670 --> 00:59:17,930 formatted string remember so we had an F close now here we add a label like X 2486 00:59:17,930 --> 00:59:17,940 close now here we add a label like X 2487 00:59:17,940 --> 00:59:21,800 close now here we add a label like X then we'll add a field so here we want 2488 00:59:21,800 --> 00:59:21,810 then we'll add a field so here we want 2489 00:59:21,810 --> 00:59:25,400 then we'll add a field so here we want to print the value of X variable after 2490 00:59:25,400 --> 00:59:25,410 to print the value of X variable after 2491 00:59:25,410 --> 00:59:28,520 to print the value of X variable after that we add some more text and finally 2492 00:59:28,520 --> 00:59:28,530 that we add some more text and finally 2493 00:59:28,530 --> 00:59:32,150 that we add some more text and finally we want to print the value of y let's 2494 00:59:32,150 --> 00:59:32,160 we want to print the value of y let's 2495 00:59:32,160 --> 00:59:35,660 we want to print the value of y let's run this program one more time so here 2496 00:59:35,660 --> 00:59:35,670 run this program one more time so here 2497 00:59:35,670 --> 00:59:39,560 run this program one more time so here in the terminal let's enter 1 and here's 2498 00:59:39,560 --> 00:59:39,570 in the terminal let's enter 1 and here's 2499 00:59:39,570 --> 00:59:42,820 in the terminal let's enter 1 and here's the result X is 1 and Y is 2 beautiful 2500 00:59:42,820 --> 00:59:42,830 the result X is 1 and Y is 2 beautiful 2501 00:59:42,830 --> 00:59:45,290 the result X is 1 and Y is 2 beautiful now all these built-in functions are 2502 00:59:45,290 --> 00:59:45,300 now all these built-in functions are 2503 00:59:45,300 --> 00:59:48,200 now all these built-in functions are self explanatory the only tricky one is 2504 00:59:48,200 --> 00:59:48,210 self explanatory the only tricky one is 2505 00:59:48,210 --> 00:59:50,240 self explanatory the only tricky one is bull because in Python we have this 2506 00:59:50,240 --> 00:59:50,250 bull because in Python we have this 2507 00:59:50,250 --> 00:59:54,200 bull because in Python we have this concept of truthy and falsy values these 2508 00:59:54,200 --> 00:59:54,210 concept of truthy and falsy values these 2509 00:59:54,210 --> 00:59:56,000 concept of truthy and falsy values these are values that are not exactly a 2510 00:59:56,000 --> 00:59:56,010 are values that are not exactly a 2511 00:59:56,010 --> 00:59:58,760 are values that are not exactly a boolean true or false but they can be 2512 00:59:58,760 --> 00:59:58,770 boolean true or false but they can be 2513 00:59:58,770 --> 01:00:01,540 boolean true or false but they can be interpreted as a boolean true or false 2514 01:00:01,540 --> 01:00:01,550 interpreted as a boolean true or false 2515 01:00:01,550 --> 01:00:04,940 interpreted as a boolean true or false so here are the false if values in 2516 01:00:04,940 --> 01:00:04,950 so here are the false if values in 2517 01:00:04,950 --> 01:00:08,090 so here are the false if values in Python empty strings are considered 2518 01:00:08,090 --> 01:00:08,100 Python empty strings are considered 2519 01:00:08,100 --> 01:00:10,160 Python empty strings are considered false e so they're interpreted as a 2520 01:00:10,160 --> 01:00:10,170 false e so they're interpreted as a 2521 01:00:10,170 --> 01:00:13,430 false e so they're interpreted as a boolean false number zero is also false 2522 01:00:13,430 --> 01:00:13,440 boolean false number zero is also false 2523 01:00:13,440 --> 01:00:16,550 boolean false number zero is also false e we have an object called nan which 2524 01:00:16,550 --> 01:00:16,560 e we have an object called nan which 2525 01:00:16,560 --> 01:00:19,100 e we have an object called nan which represents the absence of a value we'll 2526 01:00:19,100 --> 01:00:19,110 represents the absence of a value we'll 2527 01:00:19,110 --> 01:00:21,320 represents the absence of a value we'll look at this later in the course so 2528 01:00:21,320 --> 01:00:21,330 look at this later in the course so 2529 01:00:21,330 --> 01:00:22,579 look at this later in the course so whenever we use 2530 01:00:22,579 --> 01:00:22,589 whenever we use 2531 01:00:22,589 --> 01:00:25,940 whenever we use these values in a boolean context will 2532 01:00:25,940 --> 01:00:25,950 these values in a boolean context will 2533 01:00:25,950 --> 01:00:29,630 these values in a boolean context will get false anything else will be true let 2534 01:00:29,630 --> 01:00:29,640 get false anything else will be true let 2535 01:00:29,640 --> 01:00:32,479 get false anything else will be true let me show you a few examples so in this 2536 01:00:32,479 --> 01:00:32,489 me show you a few examples so in this 2537 01:00:32,489 --> 01:00:34,910 me show you a few examples so in this interactive shell in Python let's 2538 01:00:34,910 --> 01:00:34,920 interactive shell in Python let's 2539 01:00:34,920 --> 01:00:39,259 interactive shell in Python let's convert number 0 to bull that's false II 2540 01:00:39,259 --> 01:00:39,269 convert number 0 to bull that's false II 2541 01:00:39,269 --> 01:00:40,309 convert number 0 to bull that's false II so we get false 2542 01:00:40,309 --> 01:00:40,319 so we get false 2543 01:00:40,319 --> 01:00:44,870 so we get false what about pool of 1 we get true if you 2544 01:00:44,870 --> 01:00:44,880 what about pool of 1 we get true if you 2545 01:00:44,880 --> 01:00:47,239 what about pool of 1 we get true if you pass a negative number will also get 2546 01:00:47,239 --> 01:00:47,249 pass a negative number will also get 2547 01:00:47,249 --> 01:00:50,719 pass a negative number will also get true if we pass a number larger than 1 2548 01:00:50,719 --> 01:00:50,729 true if we pass a number larger than 1 2549 01:00:50,729 --> 01:00:53,809 true if we pass a number larger than 1 like 5 we still get true so we only get 2550 01:00:53,809 --> 01:00:53,819 like 5 we still get true so we only get 2551 01:00:53,819 --> 01:00:56,420 like 5 we still get true so we only get false when we try to convert 0 to a 2552 01:00:56,420 --> 01:00:56,430 false when we try to convert 0 to a 2553 01:00:56,430 --> 01:00:59,239 false when we try to convert 0 to a boolean now it strings I told you that 2554 01:00:59,239 --> 01:00:59,249 boolean now it strings I told you that 2555 01:00:59,249 --> 01:01:02,509 boolean now it strings I told you that an empty string is false e so here we'll 2556 01:01:02,509 --> 01:01:02,519 an empty string is false e so here we'll 2557 01:01:02,519 --> 01:01:06,769 an empty string is false e so here we'll get false anything else is true so even 2558 01:01:06,769 --> 01:01:06,779 get false anything else is true so even 2559 01:01:06,779 --> 01:01:09,709 get false anything else is true so even if I have a string that is false 2560 01:01:09,709 --> 01:01:09,719 if I have a string that is false 2561 01:01:09,719 --> 01:01:12,829 if I have a string that is false we'll get true because this is not an 2562 01:01:12,829 --> 01:01:12,839 we'll get true because this is not an 2563 01:01:12,839 --> 01:01:15,049 we'll get true because this is not an empty string it's a string with a few 2564 01:01:15,049 --> 01:01:15,059 empty string it's a string with a few 2565 01:01:15,059 --> 01:01:17,839 empty string it's a string with a few characters that's why it's evaluated as 2566 01:01:17,839 --> 01:01:17,849 characters that's why it's evaluated as 2567 01:01:17,849 --> 01:01:24,359 characters that's why it's evaluated as true 2568 01:01:24,359 --> 01:01:24,369 2569 01:01:24,369 --> 01:01:26,890 all right once again it's time for 2570 01:01:26,890 --> 01:01:26,900 all right once again it's time for 2571 01:01:26,900 --> 01:01:28,780 all right once again it's time for another quiz let's see if you have been 2572 01:01:28,780 --> 01:01:28,790 another quiz let's see if you have been 2573 01:01:28,790 --> 01:01:30,579 another quiz let's see if you have been really paying attention to this tutorial 2574 01:01:30,579 --> 01:01:30,589 really paying attention to this tutorial 2575 01:01:30,589 --> 01:01:33,040 really paying attention to this tutorial so here's the first question what are 2576 01:01:33,040 --> 01:01:33,050 so here's the first question what are 2577 01:01:33,050 --> 01:01:39,570 so here's the first question what are the built in primitive types in Python 2578 01:01:39,570 --> 01:01:39,580 2579 01:01:39,580 --> 01:01:43,290 we have strings numbers and boolean 2580 01:01:43,290 --> 01:01:43,300 we have strings numbers and boolean 2581 01:01:43,300 --> 01:01:46,890 we have strings numbers and boolean numbers can be integers floats or 2582 01:01:46,890 --> 01:01:46,900 numbers can be integers floats or 2583 01:01:46,900 --> 01:01:50,020 numbers can be integers floats or complex numbers here's the second 2584 01:01:50,020 --> 01:01:50,030 complex numbers here's the second 2585 01:01:50,030 --> 01:01:52,240 complex numbers here's the second question you have this variable fruit 2586 01:01:52,240 --> 01:01:52,250 question you have this variable fruit 2587 01:01:52,250 --> 01:01:54,790 question you have this variable fruit set to Apple what do you think we will 2588 01:01:54,790 --> 01:01:54,800 set to Apple what do you think we will 2589 01:01:54,800 --> 01:01:57,400 set to Apple what do you think we will see on the terminal when we print fruit 2590 01:01:57,400 --> 01:01:57,410 see on the terminal when we print fruit 2591 01:01:57,410 --> 01:02:05,410 see on the terminal when we print fruit of one well using square brackets we can 2592 01:02:05,410 --> 01:02:05,420 of one well using square brackets we can 2593 01:02:05,420 --> 01:02:08,290 of one well using square brackets we can access individual characters the index 2594 01:02:08,290 --> 01:02:08,300 access individual characters the index 2595 01:02:08,300 --> 01:02:10,599 access individual characters the index of the first character is zero so this 2596 01:02:10,599 --> 01:02:10,609 of the first character is zero so this 2597 01:02:10,609 --> 01:02:12,700 of the first character is zero so this expression returns the second character 2598 01:02:12,700 --> 01:02:12,710 expression returns the second character 2599 01:02:12,710 --> 01:02:16,870 expression returns the second character which is P what if you add a colon and 2600 01:02:16,870 --> 01:02:16,880 which is P what if you add a colon and 2601 01:02:16,880 --> 01:02:22,329 which is P what if you add a colon and negative one here 2602 01:02:22,329 --> 01:02:22,339 2603 01:02:22,339 --> 01:02:25,280 well using the syntax we can slice a 2604 01:02:25,280 --> 01:02:25,290 well using the syntax we can slice a 2605 01:02:25,290 --> 01:02:28,370 well using the syntax we can slice a string re stored index is one and our 2606 01:02:28,370 --> 01:02:28,380 string re stored index is one and our 2607 01:02:28,380 --> 01:02:30,650 string re stored index is one and our end index is negative one which refers 2608 01:02:30,650 --> 01:02:30,660 end index is negative one which refers 2609 01:02:30,660 --> 01:02:32,930 end index is negative one which refers to the first character from the end of 2610 01:02:32,930 --> 01:02:32,940 to the first character from the end of 2611 01:02:32,940 --> 01:02:33,589 to the first character from the end of the string 2612 01:02:33,589 --> 01:02:33,599 the string 2613 01:02:33,599 --> 01:02:36,650 the string now when slicing a string the character 2614 01:02:36,650 --> 01:02:36,660 now when slicing a string the character 2615 01:02:36,660 --> 01:02:39,740 now when slicing a string the character at the end index or negative one is not 2616 01:02:39,740 --> 01:02:39,750 at the end index or negative one is not 2617 01:02:39,750 --> 01:02:41,960 at the end index or negative one is not included so with this expression we'll 2618 01:02:41,960 --> 01:02:41,970 included so with this expression we'll 2619 01:02:41,970 --> 01:02:44,930 included so with this expression we'll get all the characters starting from the 2620 01:02:44,930 --> 01:02:44,940 get all the characters starting from the 2621 01:02:44,940 --> 01:02:47,270 get all the characters starting from the second character which is P all the way 2622 01:02:47,270 --> 01:02:47,280 second character which is P all the way 2623 01:02:47,280 --> 01:02:50,540 second character which is P all the way until we get to e so the result of this 2624 01:02:50,540 --> 01:02:50,550 until we get to e so the result of this 2625 01:02:50,550 --> 01:02:54,109 until we get to e so the result of this expression is ppl here's another 2626 01:02:54,109 --> 01:02:54,119 expression is ppl here's another 2627 01:02:54,119 --> 01:02:56,660 expression is ppl here's another question what is the result of this 2628 01:02:56,660 --> 01:02:56,670 question what is the result of this 2629 01:02:56,670 --> 01:03:01,480 question what is the result of this expression 2630 01:03:01,480 --> 01:03:01,490 2631 01:03:01,490 --> 01:03:04,490 well this is what we call the modulus 2632 01:03:04,490 --> 01:03:04,500 well this is what we call the modulus 2633 01:03:04,500 --> 01:03:07,160 well this is what we call the modulus operator and it returns the remainder of 2634 01:03:07,160 --> 01:03:07,170 operator and it returns the remainder of 2635 01:03:07,170 --> 01:03:10,570 operator and it returns the remainder of a division which is in this case one and 2636 01:03:10,570 --> 01:03:10,580 a division which is in this case one and 2637 01:03:10,580 --> 01:03:13,460 a division which is in this case one and finally the last question what do you 2638 01:03:13,460 --> 01:03:13,470 finally the last question what do you 2639 01:03:13,470 --> 01:03:16,180 finally the last question what do you think we will see when we print wool of 2640 01:03:16,180 --> 01:03:16,190 think we will see when we print wool of 2641 01:03:16,190 --> 01:03:23,360 think we will see when we print wool of FOSS well earlier I told you about 2642 01:03:23,360 --> 01:03:23,370 FOSS well earlier I told you about 2643 01:03:23,370 --> 01:03:26,540 FOSS well earlier I told you about faulty values in Python so number zero 2644 01:03:26,540 --> 01:03:26,550 faulty values in Python so number zero 2645 01:03:26,550 --> 01:03:29,420 faulty values in Python so number zero an empty string and the non object these 2646 01:03:29,420 --> 01:03:29,430 an empty string and the non object these 2647 01:03:29,430 --> 01:03:30,980 an empty string and the non object these are all false if values 2648 01:03:30,980 --> 01:03:30,990 are all false if values 2649 01:03:30,990 --> 01:03:33,470 are all false if values anything that is not false is considered 2650 01:03:33,470 --> 01:03:33,480 anything that is not false is considered 2651 01:03:33,480 --> 01:03:35,810 anything that is not false is considered true see here we have a string that has 2652 01:03:35,810 --> 01:03:35,820 true see here we have a string that has 2653 01:03:35,820 --> 01:03:38,120 true see here we have a string that has five characters it doesn't matter what 2654 01:03:38,120 --> 01:03:38,130 five characters it doesn't matter what 2655 01:03:38,130 --> 01:03:40,490 five characters it doesn't matter what those characters are this is not an 2656 01:03:40,490 --> 01:03:40,500 those characters are this is not an 2657 01:03:40,500 --> 01:03:43,310 those characters are this is not an empty string so it's not fall see it's 2658 01:03:43,310 --> 01:03:43,320 empty string so it's not fall see it's 2659 01:03:43,320 --> 01:03:45,950 empty string so it's not fall see it's true see so when we convert it using the 2660 01:03:45,950 --> 01:03:45,960 true see so when we convert it using the 2661 01:03:45,960 --> 01:03:48,470 true see so when we convert it using the bull function we'll get a boolean true 2662 01:03:48,470 --> 01:03:48,480 bull function we'll get a boolean true 2663 01:03:48,480 --> 01:03:50,750 bull function we'll get a boolean true and this brings us to the end of this 2664 01:03:50,750 --> 01:03:50,760 and this brings us to the end of this 2665 01:03:50,760 --> 01:03:52,610 and this brings us to the end of this section in the next section you're going 2666 01:03:52,610 --> 01:03:52,620 section in the next section you're going 2667 01:03:52,620 --> 01:03:55,010 section in the next section you're going to learn the fundamentals of computer 2668 01:03:55,010 --> 01:03:55,020 to learn the fundamentals of computer 2669 01:03:55,020 --> 01:03:56,720 to learn the fundamentals of computer programming I hope you have enjoyed this 2670 01:03:56,720 --> 01:03:56,730 programming I hope you have enjoyed this 2671 01:03:56,730 --> 01:03:58,380 programming I hope you have enjoyed this section and thank you for watching 2672 01:03:58,380 --> 01:03:58,390 section and thank you for watching 2673 01:03:58,390 --> 01:04:10,599 section and thank you for watching [Music] 2674 01:04:10,599 --> 01:04:10,609 2675 01:04:10,609 --> 01:04:12,859 we're gonna start this section by 2676 01:04:12,859 --> 01:04:12,869 we're gonna start this section by 2677 01:04:12,869 --> 01:04:15,740 we're gonna start this section by exploring comparison operators we use 2678 01:04:15,740 --> 01:04:15,750 exploring comparison operators we use 2679 01:04:15,750 --> 01:04:18,019 exploring comparison operators we use comparison operators to compare values 2680 01:04:18,019 --> 01:04:18,029 comparison operators to compare values 2681 01:04:18,029 --> 01:04:21,380 comparison operators to compare values here are a few examples so 10 is greater 2682 01:04:21,380 --> 01:04:21,390 here are a few examples so 10 is greater 2683 01:04:21,390 --> 01:04:24,950 here are a few examples so 10 is greater than 3 we get true so what we have here 2684 01:04:24,950 --> 01:04:24,960 than 3 we get true so what we have here 2685 01:04:24,960 --> 01:04:27,829 than 3 we get true so what we have here is a boolean expression because when 2686 01:04:27,829 --> 01:04:27,839 is a boolean expression because when 2687 01:04:27,839 --> 01:04:30,230 is a boolean expression because when this expression is evaluated we'll get a 2688 01:04:30,230 --> 01:04:30,240 this expression is evaluated we'll get a 2689 01:04:30,240 --> 01:04:33,650 this expression is evaluated we'll get a boolean value that is true or false here 2690 01:04:33,650 --> 01:04:33,660 boolean value that is true or false here 2691 01:04:33,660 --> 01:04:36,319 boolean value that is true or false here is another example 10 is greater than or 2692 01:04:36,319 --> 01:04:36,329 is another example 10 is greater than or 2693 01:04:36,329 --> 01:04:40,460 is another example 10 is greater than or equal to 3 once again we get true we 2694 01:04:40,460 --> 01:04:40,470 equal to 3 once again we get true we 2695 01:04:40,470 --> 01:04:42,740 equal to 3 once again we get true we also have less than so 10 is less than 2696 01:04:42,740 --> 01:04:42,750 also have less than so 10 is less than 2697 01:04:42,750 --> 01:04:47,180 also have less than so 10 is less than 20 we have less than or equal to here's 2698 01:04:47,180 --> 01:04:47,190 20 we have less than or equal to here's 2699 01:04:47,190 --> 01:04:50,359 20 we have less than or equal to here's the Equality operator so 10 is equal to 2700 01:04:50,359 --> 01:04:50,369 the Equality operator so 10 is equal to 2701 01:04:50,369 --> 01:04:54,319 the Equality operator so 10 is equal to 10 what about this expression what do 2702 01:04:54,319 --> 01:04:54,329 10 what about this expression what do 2703 01:04:54,329 --> 01:04:56,359 10 what about this expression what do you think we're gonna get we get false 2704 01:04:56,359 --> 01:04:56,369 you think we're gonna get we get false 2705 01:04:56,369 --> 01:04:58,579 you think we're gonna get we get false because these values have different 2706 01:04:58,579 --> 01:04:58,589 because these values have different 2707 01:04:58,589 --> 01:05:00,950 because these values have different types and they're stored differently in 2708 01:05:00,950 --> 01:05:00,960 types and they're stored differently in 2709 01:05:00,960 --> 01:05:03,620 types and they're stored differently in the computer's memory and finally we 2710 01:05:03,620 --> 01:05:03,630 the computer's memory and finally we 2711 01:05:03,630 --> 01:05:08,120 the computer's memory and finally we have the nut equal operator so now with 2712 01:05:08,120 --> 01:05:08,130 have the nut equal operator so now with 2713 01:05:08,130 --> 01:05:09,980 have the nut equal operator so now with this expression we should get true 2714 01:05:09,980 --> 01:05:09,990 this expression we should get true 2715 01:05:09,990 --> 01:05:12,470 this expression we should get true beautiful we can also use this 2716 01:05:12,470 --> 01:05:12,480 beautiful we can also use this 2717 01:05:12,480 --> 01:05:15,289 beautiful we can also use this comparison operators with strings let me 2718 01:05:15,289 --> 01:05:15,299 comparison operators with strings let me 2719 01:05:15,299 --> 01:05:18,410 comparison operators with strings let me show you so we can check to see if bag 2720 01:05:18,410 --> 01:05:18,420 show you so we can check to see if bag 2721 01:05:18,420 --> 01:05:21,980 show you so we can check to see if bag is greater than Apple we get true 2722 01:05:21,980 --> 01:05:21,990 is greater than Apple we get true 2723 01:05:21,990 --> 01:05:25,010 is greater than Apple we get true because when we sort these two words bag 2724 01:05:25,010 --> 01:05:25,020 because when we sort these two words bag 2725 01:05:25,020 --> 01:05:27,279 because when we sort these two words bag comes after so it's considered greater 2726 01:05:27,279 --> 01:05:27,289 comes after so it's considered greater 2727 01:05:27,289 --> 01:05:30,529 comes after so it's considered greater now what about this one bag equals 2728 01:05:30,529 --> 01:05:30,539 now what about this one bag equals 2729 01:05:30,539 --> 01:05:33,710 now what about this one bag equals capital bag we get false 2730 01:05:33,710 --> 01:05:33,720 capital bag we get false 2731 01:05:33,720 --> 01:05:36,529 capital bag we get false here is the reason every character you 2732 01:05:36,529 --> 01:05:36,539 here is the reason every character you 2733 01:05:36,539 --> 01:05:38,990 here is the reason every character you see here has a numeric representation in 2734 01:05:38,990 --> 01:05:39,000 see here has a numeric representation in 2735 01:05:39,000 --> 01:05:41,299 see here has a numeric representation in programming let me show you so we have 2736 01:05:41,299 --> 01:05:41,309 programming let me show you so we have 2737 01:05:41,309 --> 01:05:44,000 programming let me show you so we have this built-in function called Ord don't 2738 01:05:44,000 --> 01:05:44,010 this built-in function called Ord don't 2739 01:05:44,010 --> 01:05:45,740 this built-in function called Ord don't worry about memorizing this because 2740 01:05:45,740 --> 01:05:45,750 worry about memorizing this because 2741 01:05:45,750 --> 01:05:47,210 worry about memorizing this because you're probably never gonna use this in 2742 01:05:47,210 --> 01:05:47,220 you're probably never gonna use this in 2743 01:05:47,220 --> 01:05:49,789 you're probably never gonna use this in the future but let me show you the 2744 01:05:49,789 --> 01:05:49,799 the future but let me show you the 2745 01:05:49,799 --> 01:05:52,569 the future but let me show you the numeric representation of the letter P 2746 01:05:52,569 --> 01:05:52,579 numeric representation of the letter P 2747 01:05:52,579 --> 01:05:54,500 numeric representation of the letter P so that is 98 2748 01:05:54,500 --> 01:05:54,510 so that is 98 2749 01:05:54,510 --> 01:05:58,519 so that is 98 in contrast capital B is represented as 2750 01:05:58,519 --> 01:05:58,529 in contrast capital B is represented as 2751 01:05:58,529 --> 01:06:02,329 in contrast capital B is represented as 66 that is the reason these two strings 2752 01:06:02,329 --> 01:06:02,339 66 that is the reason these two strings 2753 01:06:02,339 --> 01:06:05,089 66 that is the reason these two strings are not equal so these are the 2754 01:06:05,089 --> 01:06:05,099 are not equal so these are the 2755 01:06:05,099 --> 01:06:07,460 are not equal so these are the comparison operators in Python next 2756 01:06:07,460 --> 01:06:07,470 comparison operators in Python next 2757 01:06:07,470 --> 01:06:16,450 comparison operators in Python next we'll look at conditional statements 2758 01:06:16,450 --> 01:06:16,460 2759 01:06:16,460 --> 01:06:19,580 in almost every program there are times 2760 01:06:19,580 --> 01:06:19,590 in almost every program there are times 2761 01:06:19,590 --> 01:06:21,470 in almost every program there are times you need to make decisions and that's 2762 01:06:21,470 --> 01:06:21,480 you need to make decisions and that's 2763 01:06:21,480 --> 01:06:24,349 you need to make decisions and that's when you use an if statement here is an 2764 01:06:24,349 --> 01:06:24,359 when you use an if statement here is an 2765 01:06:24,359 --> 01:06:26,720 when you use an if statement here is an example let's say we have a variable 2766 01:06:26,720 --> 01:06:26,730 example let's say we have a variable 2767 01:06:26,730 --> 01:06:30,740 example let's say we have a variable called temperature we set it to 35 now 2768 01:06:30,740 --> 01:06:30,750 called temperature we set it to 35 now 2769 01:06:30,750 --> 01:06:32,810 called temperature we set it to 35 now if temperature is greater than 30 2770 01:06:32,810 --> 01:06:32,820 if temperature is greater than 30 2771 01:06:32,820 --> 01:06:35,300 if temperature is greater than 30 perhaps we want to display a message to 2772 01:06:35,300 --> 01:06:35,310 perhaps we want to display a message to 2773 01:06:35,310 --> 01:06:38,470 perhaps we want to display a message to the user so we use an if statement if 2774 01:06:38,470 --> 01:06:38,480 the user so we use an if statement if 2775 01:06:38,480 --> 01:06:41,630 the user so we use an if statement if after if we add a condition which is 2776 01:06:41,630 --> 01:06:41,640 after if we add a condition which is 2777 01:06:41,640 --> 01:06:43,580 after if we add a condition which is basically a boolean expression an 2778 01:06:43,580 --> 01:06:43,590 basically a boolean expression an 2779 01:06:43,590 --> 01:06:46,120 basically a boolean expression an expression that produces a boolean value 2780 01:06:46,120 --> 01:06:46,130 expression that produces a boolean value 2781 01:06:46,130 --> 01:06:49,609 expression that produces a boolean value so if temperature is greater than 30 2782 01:06:49,609 --> 01:06:49,619 so if temperature is greater than 30 2783 01:06:49,619 --> 01:06:52,160 so if temperature is greater than 30 here we have a boolean expression if 2784 01:06:52,160 --> 01:06:52,170 here we have a boolean expression if 2785 01:06:52,170 --> 01:06:55,190 here we have a boolean expression if this expression evaluates to true the 2786 01:06:55,190 --> 01:06:55,200 this expression evaluates to true the 2787 01:06:55,200 --> 01:06:56,570 this expression evaluates to true the following statements will be executed 2788 01:06:56,570 --> 01:06:56,580 following statements will be executed 2789 01:06:56,580 --> 01:06:59,270 following statements will be executed let me show you now here is the 2790 01:06:59,270 --> 01:06:59,280 let me show you now here is the 2791 01:06:59,280 --> 01:07:01,310 let me show you now here is the important part that a lot of beginners 2792 01:07:01,310 --> 01:07:01,320 important part that a lot of beginners 2793 01:07:01,320 --> 01:07:03,890 important part that a lot of beginners miss when you use an if statement 2794 01:07:03,890 --> 01:07:03,900 miss when you use an if statement 2795 01:07:03,900 --> 01:07:06,200 miss when you use an if statement you should always terminate your 2796 01:07:06,200 --> 01:07:06,210 you should always terminate your 2797 01:07:06,210 --> 01:07:09,260 you should always terminate your statement with a colon now let's see 2798 01:07:09,260 --> 01:07:09,270 statement with a colon now let's see 2799 01:07:09,270 --> 01:07:11,690 statement with a colon now let's see what happens when I press ENTER our 2800 01:07:11,690 --> 01:07:11,700 what happens when I press ENTER our 2801 01:07:11,700 --> 01:07:14,780 what happens when I press ENTER our cursor is indented so here we have two 2802 01:07:14,780 --> 01:07:14,790 cursor is indented so here we have two 2803 01:07:14,790 --> 01:07:17,150 cursor is indented so here we have two white spaces this is very important 2804 01:07:17,150 --> 01:07:17,160 white spaces this is very important 2805 01:07:17,160 --> 01:07:20,089 white spaces this is very important because using these indentations Python 2806 01:07:20,089 --> 01:07:20,099 because using these indentations Python 2807 01:07:20,099 --> 01:07:22,550 because using these indentations Python interpreter will know what statements 2808 01:07:22,550 --> 01:07:22,560 interpreter will know what statements 2809 01:07:22,560 --> 01:07:25,010 interpreter will know what statements should be executed if this condition is 2810 01:07:25,010 --> 01:07:25,020 should be executed if this condition is 2811 01:07:25,020 --> 01:07:27,260 should be executed if this condition is true here we want to print a message 2812 01:07:27,260 --> 01:07:27,270 true here we want to print a message 2813 01:07:27,270 --> 01:07:32,089 true here we want to print a message like it's warm we can print another 2814 01:07:32,089 --> 01:07:32,099 like it's warm we can print another 2815 01:07:32,099 --> 01:07:35,630 like it's warm we can print another message as well drink water so we can 2816 01:07:35,630 --> 01:07:35,640 message as well drink water so we can 2817 01:07:35,640 --> 01:07:37,820 message as well drink water so we can have as many statements as we want here 2818 01:07:37,820 --> 01:07:37,830 have as many statements as we want here 2819 01:07:37,830 --> 01:07:40,570 have as many statements as we want here as long as they are indented they belong 2820 01:07:40,570 --> 01:07:40,580 as long as they are indented they belong 2821 01:07:40,580 --> 01:07:44,359 as long as they are indented they belong to this if block now when we finish here 2822 01:07:44,359 --> 01:07:44,369 to this if block now when we finish here 2823 01:07:44,369 --> 01:07:47,300 to this if block now when we finish here we should remove indentation to indicate 2824 01:07:47,300 --> 01:07:47,310 we should remove indentation to indicate 2825 01:07:47,310 --> 01:07:50,120 we should remove indentation to indicate the end of this if block so here we can 2826 01:07:50,120 --> 01:07:50,130 the end of this if block so here we can 2827 01:07:50,130 --> 01:07:52,370 the end of this if block so here we can add a print statement with a message 2828 01:07:52,370 --> 01:07:52,380 add a print statement with a message 2829 01:07:52,380 --> 01:07:55,070 add a print statement with a message like done this statement will always be 2830 01:07:55,070 --> 01:07:55,080 like done this statement will always be 2831 01:07:55,080 --> 01:07:57,290 like done this statement will always be executed whether this condition is true 2832 01:07:57,290 --> 01:07:57,300 executed whether this condition is true 2833 01:07:57,300 --> 01:08:00,980 executed whether this condition is true or not now note that when I save the 2834 01:08:00,980 --> 01:08:00,990 or not now note that when I save the 2835 01:08:00,990 --> 01:08:03,920 or not now note that when I save the changes this indentation you see here is 2836 01:08:03,920 --> 01:08:03,930 changes this indentation you see here is 2837 01:08:03,930 --> 01:08:06,079 changes this indentation you see here is going to be doubled up take a look 2838 01:08:06,079 --> 01:08:06,089 going to be doubled up take a look 2839 01:08:06,089 --> 01:08:09,530 going to be doubled up take a look save there you go so when we save the 2840 01:08:09,530 --> 01:08:09,540 save there you go so when we save the 2841 01:08:09,540 --> 01:08:11,960 save there you go so when we save the changes auto kept eight reformat our 2842 01:08:11,960 --> 01:08:11,970 changes auto kept eight reformat our 2843 01:08:11,970 --> 01:08:14,599 changes auto kept eight reformat our code and uses four white spaces for 2844 01:08:14,599 --> 01:08:14,609 code and uses four white spaces for 2845 01:08:14,609 --> 01:08:17,749 code and uses four white spaces for indentation so one two three four it 2846 01:08:17,749 --> 01:08:17,759 indentation so one two three four it 2847 01:08:17,759 --> 01:08:19,729 indentation so one two three four it uses four white spaces because that's 2848 01:08:19,729 --> 01:08:19,739 uses four white spaces because that's 2849 01:08:19,739 --> 01:08:23,090 uses four white spaces because that's what pepp eight recommends alright now 2850 01:08:23,090 --> 01:08:23,100 what pepp eight recommends alright now 2851 01:08:23,100 --> 01:08:26,090 what pepp eight recommends alright now let's run this program so because 2852 01:08:26,090 --> 01:08:26,100 let's run this program so because 2853 01:08:26,100 --> 01:08:26,720 let's run this program so because temperature 2854 01:08:26,720 --> 01:08:26,730 temperature 2855 01:08:26,730 --> 01:08:29,240 temperature is greater than 30 we see the first two 2856 01:08:29,240 --> 01:08:29,250 is greater than 30 we see the first two 2857 01:08:29,250 --> 01:08:31,940 is greater than 30 we see the first two messages and we see the dawn message 2858 01:08:31,940 --> 01:08:31,950 messages and we see the dawn message 2859 01:08:31,950 --> 01:08:34,039 messages and we see the dawn message regardless so if I change the 2860 01:08:34,039 --> 01:08:34,049 regardless so if I change the 2861 01:08:34,049 --> 01:08:37,550 regardless so if I change the temperature to let's say 15 and run the 2862 01:08:37,550 --> 01:08:37,560 temperature to let's say 15 and run the 2863 01:08:37,560 --> 01:08:40,550 temperature to let's say 15 and run the program one more time look this dawn 2864 01:08:40,550 --> 01:08:40,560 program one more time look this dawn 2865 01:08:40,560 --> 01:08:43,249 program one more time look this dawn message is executed whether our 2866 01:08:43,249 --> 01:08:43,259 message is executed whether our 2867 01:08:43,259 --> 01:08:45,829 message is executed whether our condition is true or not so pay great 2868 01:08:45,829 --> 01:08:45,839 condition is true or not so pay great 2869 01:08:45,839 --> 01:08:48,019 condition is true or not so pay great attention to these indentations that's 2870 01:08:48,019 --> 01:08:48,029 attention to these indentations that's 2871 01:08:48,029 --> 01:08:49,940 attention to these indentations that's one of the issues I see in beginners 2872 01:08:49,940 --> 01:08:49,950 one of the issues I see in beginners 2873 01:08:49,950 --> 01:08:52,340 one of the issues I see in beginners code let's say they want both these 2874 01:08:52,340 --> 01:08:52,350 code let's say they want both these 2875 01:08:52,350 --> 01:08:54,320 code let's say they want both these print statements to be executed if the 2876 01:08:54,320 --> 01:08:54,330 print statements to be executed if the 2877 01:08:54,330 --> 01:08:57,349 print statements to be executed if the condition is true accidentally they 2878 01:08:57,349 --> 01:08:57,359 condition is true accidentally they 2879 01:08:57,359 --> 01:08:59,510 condition is true accidentally they remove the indentation on the fourth 2880 01:08:59,510 --> 01:08:59,520 remove the indentation on the fourth 2881 01:08:59,520 --> 01:09:01,460 remove the indentation on the fourth line and that's why their program 2882 01:09:01,460 --> 01:09:01,470 line and that's why their program 2883 01:09:01,470 --> 01:09:03,890 line and that's why their program doesn't work as they expect so be 2884 01:09:03,890 --> 01:09:03,900 doesn't work as they expect so be 2885 01:09:03,900 --> 01:09:06,650 doesn't work as they expect so be careful about this now what if you want 2886 01:09:06,650 --> 01:09:06,660 careful about this now what if you want 2887 01:09:06,660 --> 01:09:09,640 careful about this now what if you want to have multiple conditions we use an 2888 01:09:09,640 --> 01:09:09,650 to have multiple conditions we use an 2889 01:09:09,650 --> 01:09:14,320 to have multiple conditions we use an elephant so L if that is short for LS if 2890 01:09:14,320 --> 01:09:14,330 elephant so L if that is short for LS if 2891 01:09:14,330 --> 01:09:16,820 elephant so L if that is short for LS if here we can add another condition 2892 01:09:16,820 --> 01:09:16,830 here we can add another condition 2893 01:09:16,830 --> 01:09:19,550 here we can add another condition another expression so temperature is 2894 01:09:19,550 --> 01:09:19,560 another expression so temperature is 2895 01:09:19,560 --> 01:09:24,800 another expression so temperature is greater than 20 once again : enter a by 2896 01:09:24,800 --> 01:09:24,810 greater than 20 once again : enter a by 2897 01:09:24,810 --> 01:09:27,170 greater than 20 once again : enter a by default here vs code is using two white 2898 01:09:27,170 --> 01:09:27,180 default here vs code is using two white 2899 01:09:27,180 --> 01:09:29,599 default here vs code is using two white spaces so don't worry about this as soon 2900 01:09:29,599 --> 01:09:29,609 spaces so don't worry about this as soon 2901 01:09:29,609 --> 01:09:31,910 spaces so don't worry about this as soon as you save the changes those two white 2902 01:09:31,910 --> 01:09:31,920 as you save the changes those two white 2903 01:09:31,920 --> 01:09:34,010 as you save the changes those two white spaces will be converted to four white 2904 01:09:34,010 --> 01:09:34,020 spaces will be converted to four white 2905 01:09:34,020 --> 01:09:36,590 spaces will be converted to four white spaces so let's print a different 2906 01:09:36,590 --> 01:09:36,600 spaces so let's print a different 2907 01:09:36,600 --> 01:09:37,190 spaces so let's print a different message 2908 01:09:37,190 --> 01:09:37,200 message 2909 01:09:37,200 --> 01:09:42,800 message it's nice save the changes now look all 2910 01:09:42,800 --> 01:09:42,810 it's nice save the changes now look all 2911 01:09:42,810 --> 01:09:45,710 it's nice save the changes now look all these lines are indented consistently 2912 01:09:45,710 --> 01:09:45,720 these lines are indented consistently 2913 01:09:45,720 --> 01:09:48,470 these lines are indented consistently you can have as many Elif statements as 2914 01:09:48,470 --> 01:09:48,480 you can have as many Elif statements as 2915 01:09:48,480 --> 01:09:50,870 you can have as many Elif statements as you want and optionally you can also 2916 01:09:50,870 --> 01:09:50,880 you want and optionally you can also 2917 01:09:50,880 --> 01:09:54,320 you want and optionally you can also have an else statement so if none of the 2918 01:09:54,320 --> 01:09:54,330 have an else statement so if none of the 2919 01:09:54,330 --> 01:09:57,530 have an else statement so if none of the previous conditions are true then what 2920 01:09:57,530 --> 01:09:57,540 previous conditions are true then what 2921 01:09:57,540 --> 01:09:59,000 previous conditions are true then what you have in the else block will be 2922 01:09:59,000 --> 01:09:59,010 you have in the else block will be 2923 01:09:59,010 --> 01:10:02,290 you have in the else block will be executed once again we add the colon 2924 01:10:02,290 --> 01:10:02,300 executed once again we add the colon 2925 01:10:02,300 --> 01:10:05,930 executed once again we add the colon annotation print here we can add a 2926 01:10:05,930 --> 01:10:05,940 annotation print here we can add a 2927 01:10:05,940 --> 01:10:09,290 annotation print here we can add a message like it's called saying the 2928 01:10:09,290 --> 01:10:09,300 message like it's called saying the 2929 01:10:09,300 --> 01:10:12,020 message like it's called saying the changes in this case temperature is 15 2930 01:10:12,020 --> 01:10:12,030 changes in this case temperature is 15 2931 01:10:12,030 --> 01:10:15,620 changes in this case temperature is 15 so none of these two conditions will be 2932 01:10:15,620 --> 01:10:15,630 so none of these two conditions will be 2933 01:10:15,630 --> 01:10:18,560 so none of these two conditions will be true and we will see it's called let's 2934 01:10:18,560 --> 01:10:18,570 true and we will see it's called let's 2935 01:10:18,570 --> 01:10:27,720 true and we will see it's called let's run the program there you go 2936 01:10:27,720 --> 01:10:27,730 2937 01:10:27,730 --> 01:10:30,250 in this lecture I'm going to show you a 2938 01:10:30,250 --> 01:10:30,260 in this lecture I'm going to show you a 2939 01:10:30,260 --> 01:10:33,280 in this lecture I'm going to show you a technique for writing cleaner code so 2940 01:10:33,280 --> 01:10:33,290 technique for writing cleaner code so 2941 01:10:33,290 --> 01:10:34,840 technique for writing cleaner code so let's say we're building an application 2942 01:10:34,840 --> 01:10:34,850 let's say we're building an application 2943 01:10:34,850 --> 01:10:37,480 let's say we're building an application for University and we want to check to 2944 01:10:37,480 --> 01:10:37,490 for University and we want to check to 2945 01:10:37,490 --> 01:10:40,120 for University and we want to check to see if the person who's applying for 2946 01:10:40,120 --> 01:10:40,130 see if the person who's applying for 2947 01:10:40,130 --> 01:10:42,400 see if the person who's applying for this university program is eligible or 2948 01:10:42,400 --> 01:10:42,410 this university program is eligible or 2949 01:10:42,410 --> 01:10:45,610 this university program is eligible or not so we start by defining a variable 2950 01:10:45,610 --> 01:10:45,620 not so we start by defining a variable 2951 01:10:45,620 --> 01:10:48,040 not so we start by defining a variable called age set it to 22 2952 01:10:48,040 --> 01:10:48,050 called age set it to 22 2953 01:10:48,050 --> 01:10:52,660 called age set it to 22 now if H is greater than or equal to 18 2954 01:10:52,660 --> 01:10:52,670 now if H is greater than or equal to 18 2955 01:10:52,670 --> 01:10:58,840 now if H is greater than or equal to 18 colon print eligible remove the 2956 01:10:58,840 --> 01:10:58,850 colon print eligible remove the 2957 01:10:58,850 --> 01:11:02,860 colon print eligible remove the indentation else colon print not 2958 01:11:02,860 --> 01:11:02,870 indentation else colon print not 2959 01:11:02,870 --> 01:11:07,180 indentation else colon print not eligible let's run the program make sure 2960 01:11:07,180 --> 01:11:07,190 eligible let's run the program make sure 2961 01:11:07,190 --> 01:11:10,540 eligible let's run the program make sure it works beautiful now there is nothing 2962 01:11:10,540 --> 01:11:10,550 it works beautiful now there is nothing 2963 01:11:10,550 --> 01:11:12,610 it works beautiful now there is nothing wrong in this piece of code but I want 2964 01:11:12,610 --> 01:11:12,620 wrong in this piece of code but I want 2965 01:11:12,620 --> 01:11:14,860 wrong in this piece of code but I want to show you a cleaner way to achieve the 2966 01:11:14,860 --> 01:11:14,870 to show you a cleaner way to achieve the 2967 01:11:14,870 --> 01:11:17,590 to show you a cleaner way to achieve the same result instead of having a print 2968 01:11:17,590 --> 01:11:17,600 same result instead of having a print 2969 01:11:17,600 --> 01:11:20,080 same result instead of having a print statement here we can define a variable 2970 01:11:20,080 --> 01:11:20,090 statement here we can define a variable 2971 01:11:20,090 --> 01:11:23,760 statement here we can define a variable like message and set it to this string 2972 01:11:23,760 --> 01:11:23,770 like message and set it to this string 2973 01:11:23,770 --> 01:11:28,030 like message and set it to this string that is the first step so message equals 2974 01:11:28,030 --> 01:11:28,040 that is the first step so message equals 2975 01:11:28,040 --> 01:11:32,650 that is the first step so message equals this string and then we will print this 2976 01:11:32,650 --> 01:11:32,660 this string and then we will print this 2977 01:11:32,660 --> 01:11:36,310 this string and then we will print this message now when you have an if-else 2978 01:11:36,310 --> 01:11:36,320 message now when you have an if-else 2979 01:11:36,320 --> 01:11:38,470 message now when you have an if-else statement with this structure where 2980 01:11:38,470 --> 01:11:38,480 statement with this structure where 2981 01:11:38,480 --> 01:11:40,660 statement with this structure where you're basically assigning a value to a 2982 01:11:40,660 --> 01:11:40,670 you're basically assigning a value to a 2983 01:11:40,670 --> 01:11:43,120 you're basically assigning a value to a variable you can rewrite this in a 2984 01:11:43,120 --> 01:11:43,130 variable you can rewrite this in a 2985 01:11:43,130 --> 01:11:47,350 variable you can rewrite this in a simpler way so this is how it works all 2986 01:11:47,350 --> 01:11:47,360 simpler way so this is how it works all 2987 01:11:47,360 --> 01:11:49,870 simpler way so this is how it works all we want to do over these few lines is to 2988 01:11:49,870 --> 01:11:49,880 we want to do over these few lines is to 2989 01:11:49,880 --> 01:11:52,420 we want to do over these few lines is to assign a value to this message variable 2990 01:11:52,420 --> 01:11:52,430 assign a value to this message variable 2991 01:11:52,430 --> 01:11:56,170 assign a value to this message variable right so we start with message we set it 2992 01:11:56,170 --> 01:11:56,180 right so we start with message we set it 2993 01:11:56,180 --> 01:12:00,460 right so we start with message we set it to eligible if age is greater than or 2994 01:12:00,460 --> 01:12:00,470 to eligible if age is greater than or 2995 01:12:00,470 --> 01:12:03,310 to eligible if age is greater than or equal to 18 else we set it to not 2996 01:12:03,310 --> 01:12:03,320 equal to 18 else we set it to not 2997 01:12:03,320 --> 01:12:05,100 equal to 18 else we set it to not eligible 2998 01:12:05,100 --> 01:12:05,110 eligible 2999 01:12:05,110 --> 01:12:07,930 eligible this statement is almost like plain 3000 01:12:07,930 --> 01:12:07,940 this statement is almost like plain 3001 01:12:07,940 --> 01:12:10,980 this statement is almost like plain English so what we have on line 7 is 3002 01:12:10,980 --> 01:12:10,990 English so what we have on line 7 is 3003 01:12:10,990 --> 01:12:14,560 English so what we have on line 7 is exactly equivalent to these four lines 3004 01:12:14,560 --> 01:12:14,570 exactly equivalent to these four lines 3005 01:12:14,570 --> 01:12:15,010 exactly equivalent to these four lines of code 3006 01:12:15,010 --> 01:12:15,020 of code 3007 01:12:15,020 --> 01:12:19,390 of code delete save the changes run the program 3008 01:12:19,390 --> 01:12:19,400 delete save the changes run the program 3009 01:12:19,400 --> 01:12:22,300 delete save the changes run the program you can see this person is eligible if I 3010 01:12:22,300 --> 01:12:22,310 you can see this person is eligible if I 3011 01:12:22,310 --> 01:12:25,720 you can see this person is eligible if I change the age to 12 and run the program 3012 01:12:25,720 --> 01:12:25,730 change the age to 12 and run the program 3013 01:12:25,730 --> 01:12:28,609 change the age to 12 and run the program we get not eligible 3014 01:12:28,609 --> 01:12:28,619 we get not eligible 3015 01:12:28,619 --> 01:12:31,100 we get not eligible so what we have here is called ternary 3016 01:12:31,100 --> 01:12:31,110 so what we have here is called ternary 3017 01:12:31,110 --> 01:12:38,410 so what we have here is called ternary operator 3018 01:12:38,410 --> 01:12:38,420 3019 01:12:38,420 --> 01:12:41,959 in Python we have three logical 3020 01:12:41,959 --> 01:12:41,969 in Python we have three logical 3021 01:12:41,969 --> 01:12:44,750 in Python we have three logical operators and we use these operators to 3022 01:12:44,750 --> 01:12:44,760 operators and we use these operators to 3023 01:12:44,760 --> 01:12:48,200 operators and we use these operators to model more complex conditions so these 3024 01:12:48,200 --> 01:12:48,210 model more complex conditions so these 3025 01:12:48,210 --> 01:12:53,330 model more complex conditions so these operators are and or and not let's see a 3026 01:12:53,330 --> 01:12:53,340 operators are and or and not let's see a 3027 01:12:53,340 --> 01:12:54,950 operators are and or and not let's see a real-world example of using these 3028 01:12:54,950 --> 01:12:54,960 real-world example of using these 3029 01:12:54,960 --> 01:12:57,320 real-world example of using these operators so imagine we're building an 3030 01:12:57,320 --> 01:12:57,330 operators so imagine we're building an 3031 01:12:57,330 --> 01:13:00,379 operators so imagine we're building an application for processing loans so we 3032 01:13:00,379 --> 01:13:00,389 application for processing loans so we 3033 01:13:00,389 --> 01:13:04,220 application for processing loans so we need two variables high income we can 3034 01:13:04,220 --> 01:13:04,230 need two variables high income we can 3035 01:13:04,230 --> 01:13:08,510 need two variables high income we can set this to true and good underline 3036 01:13:08,510 --> 01:13:08,520 set this to true and good underline 3037 01:13:08,520 --> 01:13:11,899 set this to true and good underline credit we set it to true now here's the 3038 01:13:11,899 --> 01:13:11,909 credit we set it to true now here's the 3039 01:13:11,909 --> 01:13:14,450 credit we set it to true now here's the condition we want to implement if the 3040 01:13:14,450 --> 01:13:14,460 condition we want to implement if the 3041 01:13:14,460 --> 01:13:17,300 condition we want to implement if the applicant has high income and good 3042 01:13:17,300 --> 01:13:17,310 applicant has high income and good 3043 01:13:17,310 --> 01:13:19,970 applicant has high income and good credit score then they are eligible for 3044 01:13:19,970 --> 01:13:19,980 credit score then they are eligible for 3045 01:13:19,980 --> 01:13:20,689 credit score then they are eligible for the loan 3046 01:13:20,689 --> 01:13:20,699 the loan 3047 01:13:20,699 --> 01:13:26,839 the loan so if high income and good credit we add 3048 01:13:26,839 --> 01:13:26,849 so if high income and good credit we add 3049 01:13:26,849 --> 01:13:31,580 so if high income and good credit we add the colon and print eligible now note 3050 01:13:31,580 --> 01:13:31,590 the colon and print eligible now note 3051 01:13:31,590 --> 01:13:33,770 the colon and print eligible now note that here I have not compared the value 3052 01:13:33,770 --> 01:13:33,780 that here I have not compared the value 3053 01:13:33,780 --> 01:13:36,890 that here I have not compared the value of this variable with true that is one 3054 01:13:36,890 --> 01:13:36,900 of this variable with true that is one 3055 01:13:36,900 --> 01:13:38,419 of this variable with true that is one of the issues I see in a lot of 3056 01:13:38,419 --> 01:13:38,429 of the issues I see in a lot of 3057 01:13:38,429 --> 01:13:40,609 of the issues I see in a lot of beginners code this is redundant and 3058 01:13:40,609 --> 01:13:40,619 beginners code this is redundant and 3059 01:13:40,619 --> 01:13:43,310 beginners code this is redundant and unprofessional because high income is a 3060 01:13:43,310 --> 01:13:43,320 unprofessional because high income is a 3061 01:13:43,320 --> 01:13:46,520 unprofessional because high income is a boolean so it's either true or false we 3062 01:13:46,520 --> 01:13:46,530 boolean so it's either true or false we 3063 01:13:46,530 --> 01:13:49,879 boolean so it's either true or false we don't need to compare true with true so 3064 01:13:49,879 --> 01:13:49,889 don't need to compare true with true so 3065 01:13:49,889 --> 01:13:52,729 don't need to compare true with true so if this condition is true and this 3066 01:13:52,729 --> 01:13:52,739 if this condition is true and this 3067 01:13:52,739 --> 01:13:55,040 if this condition is true and this second condition is true then we will 3068 01:13:55,040 --> 01:13:55,050 second condition is true then we will 3069 01:13:55,050 --> 01:13:59,359 second condition is true then we will print eligible in the terminal so save 3070 01:13:59,359 --> 01:13:59,369 print eligible in the terminal so save 3071 01:13:59,369 --> 01:14:01,040 print eligible in the terminal so save the changes and run the program 3072 01:14:01,040 --> 01:14:01,050 the changes and run the program 3073 01:14:01,050 --> 01:14:03,609 the changes and run the program obviously this person is eligible 3074 01:14:03,609 --> 01:14:03,619 obviously this person is eligible 3075 01:14:03,619 --> 01:14:06,560 obviously this person is eligible however if one of these conditions is 3076 01:14:06,560 --> 01:14:06,570 however if one of these conditions is 3077 01:14:06,570 --> 01:14:10,070 however if one of these conditions is false we will not see eligible in the 3078 01:14:10,070 --> 01:14:10,080 false we will not see eligible in the 3079 01:14:10,080 --> 01:14:13,160 false we will not see eligible in the terminal so let's add an else statement 3080 01:14:13,160 --> 01:14:13,170 terminal so let's add an else statement 3081 01:14:13,170 --> 01:14:19,250 terminal so let's add an else statement here and print not eligible run the 3082 01:14:19,250 --> 01:14:19,260 here and print not eligible run the 3083 01:14:19,260 --> 01:14:23,030 here and print not eligible run the program we see not eligible so this is 3084 01:14:23,030 --> 01:14:23,040 program we see not eligible so this is 3085 01:14:23,040 --> 01:14:25,669 program we see not eligible so this is how the and operator works with and 3086 01:14:25,669 --> 01:14:25,679 how the and operator works with and 3087 01:14:25,679 --> 01:14:28,790 how the and operator works with and operator if both conditions are true the 3088 01:14:28,790 --> 01:14:28,800 operator if both conditions are true the 3089 01:14:28,800 --> 01:14:31,910 operator if both conditions are true the result will be true in contrast with the 3090 01:14:31,910 --> 01:14:31,920 result will be true in contrast with the 3091 01:14:31,920 --> 01:14:34,729 result will be true in contrast with the or operator as long as at least one of 3092 01:14:34,729 --> 01:14:34,739 or operator as long as at least one of 3093 01:14:34,739 --> 01:14:36,919 or operator as long as at least one of the conditions is true the result will 3094 01:14:36,919 --> 01:14:36,929 the conditions is true the result will 3095 01:14:36,929 --> 01:14:41,149 the conditions is true the result will be true so if I replace and with or here 3096 01:14:41,149 --> 01:14:41,159 be true so if I replace and with or here 3097 01:14:41,159 --> 01:14:44,479 be true so if I replace and with or here we should see eligible in the terminal 3098 01:14:44,479 --> 01:14:44,489 we should see eligible in the terminal 3099 01:14:44,489 --> 01:14:47,020 we should see eligible in the terminal let's run it one more time there you go 3100 01:14:47,020 --> 01:14:47,030 let's run it one more time there you go 3101 01:14:47,030 --> 01:14:50,060 let's run it one more time there you go so these are the and and or operators 3102 01:14:50,060 --> 01:14:50,070 so these are the and and or operators 3103 01:14:50,070 --> 01:14:52,040 so these are the and and or operators now let's take a look at an example of 3104 01:14:52,040 --> 01:14:52,050 now let's take a look at an example of 3105 01:14:52,050 --> 01:14:54,320 now let's take a look at an example of the nut operator so I'm going to define 3106 01:14:54,320 --> 01:14:54,330 the nut operator so I'm going to define 3107 01:14:54,330 --> 01:14:58,450 the nut operator so I'm going to define another variable student set it to true 3108 01:14:58,450 --> 01:14:58,460 another variable student set it to true 3109 01:14:58,460 --> 01:15:00,410 another variable student set it to true temporarily I'm gonna remove this 3110 01:15:00,410 --> 01:15:00,420 temporarily I'm gonna remove this 3111 01:15:00,420 --> 01:15:02,780 temporarily I'm gonna remove this expression and simplify it we'll come 3112 01:15:02,780 --> 01:15:02,790 expression and simplify it we'll come 3113 01:15:02,790 --> 01:15:05,750 expression and simplify it we'll come back to this later so let's say if the 3114 01:15:05,750 --> 01:15:05,760 back to this later so let's say if the 3115 01:15:05,760 --> 01:15:08,000 back to this later so let's say if the person is eligible if they are not a 3116 01:15:08,000 --> 01:15:08,010 person is eligible if they are not a 3117 01:15:08,010 --> 01:15:08,840 person is eligible if they are not a student 3118 01:15:08,840 --> 01:15:08,850 student 3119 01:15:08,850 --> 01:15:12,290 student the nut operator basically inverses the 3120 01:15:12,290 --> 01:15:12,300 the nut operator basically inverses the 3121 01:15:12,300 --> 01:15:14,450 the nut operator basically inverses the value of a boolean so in this case 3122 01:15:14,450 --> 01:15:14,460 value of a boolean so in this case 3123 01:15:14,460 --> 01:15:17,660 value of a boolean so in this case student is true when we apply the not 3124 01:15:17,660 --> 01:15:17,670 student is true when we apply the not 3125 01:15:17,670 --> 01:15:20,930 student is true when we apply the not operator the result will be false so in 3126 01:15:20,930 --> 01:15:20,940 operator the result will be false so in 3127 01:15:20,940 --> 01:15:22,640 operator the result will be false so in this case our condition will be false 3128 01:15:22,640 --> 01:15:22,650 this case our condition will be false 3129 01:15:22,650 --> 01:15:25,640 this case our condition will be false and that's why this print statement will 3130 01:15:25,640 --> 01:15:25,650 and that's why this print statement will 3131 01:15:25,650 --> 01:15:28,480 and that's why this print statement will not be executed let me show you so save 3132 01:15:28,480 --> 01:15:28,490 not be executed let me show you so save 3133 01:15:28,490 --> 01:15:32,510 not be executed let me show you so save run the program they are not eligible if 3134 01:15:32,510 --> 01:15:32,520 run the program they are not eligible if 3135 01:15:32,520 --> 01:15:36,410 run the program they are not eligible if student was false when we apply the nut 3136 01:15:36,410 --> 01:15:36,420 student was false when we apply the nut 3137 01:15:36,420 --> 01:15:38,720 student was false when we apply the nut operator will get true so our condition 3138 01:15:38,720 --> 01:15:38,730 operator will get true so our condition 3139 01:15:38,730 --> 01:15:40,940 operator will get true so our condition will be true and we'll see it eligible 3140 01:15:40,940 --> 01:15:40,950 will be true and we'll see it eligible 3141 01:15:40,950 --> 01:15:42,680 will be true and we'll see it eligible let's run it one more time 3142 01:15:42,680 --> 01:15:42,690 let's run it one more time 3143 01:15:42,690 --> 01:15:45,800 let's run it one more time there you go with this operators we can 3144 01:15:45,800 --> 01:15:45,810 there you go with this operators we can 3145 01:15:45,810 --> 01:15:48,890 there you go with this operators we can model even more complex conditions here 3146 01:15:48,890 --> 01:15:48,900 model even more complex conditions here 3147 01:15:48,900 --> 01:15:51,560 model even more complex conditions here is an example a person can be eligible 3148 01:15:51,560 --> 01:15:51,570 is an example a person can be eligible 3149 01:15:51,570 --> 01:15:55,550 is an example a person can be eligible if they have either high income or good 3150 01:15:55,550 --> 01:15:55,560 if they have either high income or good 3151 01:15:55,560 --> 01:15:58,760 if they have either high income or good credit and they should not be used to do 3152 01:15:58,760 --> 01:15:58,770 credit and they should not be used to do 3153 01:15:58,770 --> 01:16:00,800 credit and they should not be used to do that let me show you how to implement 3154 01:16:00,800 --> 01:16:00,810 that let me show you how to implement 3155 01:16:00,810 --> 01:16:06,260 that let me show you how to implement this condition so if high income or good 3156 01:16:06,260 --> 01:16:06,270 this condition so if high income or good 3157 01:16:06,270 --> 01:16:09,020 this condition so if high income or good credit we want at least one of these 3158 01:16:09,020 --> 01:16:09,030 credit we want at least one of these 3159 01:16:09,030 --> 01:16:12,820 credit we want at least one of these conditions to be true so we put these in 3160 01:16:12,820 --> 01:16:12,830 conditions to be true so we put these in 3161 01:16:12,830 --> 01:16:15,200 conditions to be true so we put these in parentheses we want to separate these 3162 01:16:15,200 --> 01:16:15,210 parentheses we want to separate these 3163 01:16:15,210 --> 01:16:17,930 parentheses we want to separate these from the other condition which is not a 3164 01:16:17,930 --> 01:16:17,940 from the other condition which is not a 3165 01:16:17,940 --> 01:16:20,630 from the other condition which is not a student now the result of this should be 3166 01:16:20,630 --> 01:16:20,640 student now the result of this should be 3167 01:16:20,640 --> 01:16:23,150 student now the result of this should be true which means at least one of these 3168 01:16:23,150 --> 01:16:23,160 true which means at least one of these 3169 01:16:23,160 --> 01:16:25,730 true which means at least one of these conditions should be true after that 3170 01:16:25,730 --> 01:16:25,740 conditions should be true after that 3171 01:16:25,740 --> 01:16:30,260 conditions should be true after that we'll add and not student 3172 01:16:30,260 --> 01:16:30,270 we'll add and not student 3173 01:16:30,270 --> 01:16:32,930 we'll add and not student and finally caught so with this 3174 01:16:32,930 --> 01:16:32,940 and finally caught so with this 3175 01:16:32,940 --> 01:16:35,390 and finally caught so with this operators you can model all kinds of 3176 01:16:35,390 --> 01:16:35,400 operators you can model all kinds of 3177 01:16:35,400 --> 01:16:43,580 operators you can model all kinds of real-world scenarios 3178 01:16:43,580 --> 01:16:43,590 3179 01:16:43,590 --> 01:16:45,959 so here's the example from the last 3180 01:16:45,959 --> 01:16:45,969 so here's the example from the last 3181 01:16:45,969 --> 01:16:48,479 so here's the example from the last lecture a person is eligible for a loan 3182 01:16:48,479 --> 01:16:48,489 lecture a person is eligible for a loan 3183 01:16:48,489 --> 01:16:52,140 lecture a person is eligible for a loan if they have high income and good credit 3184 01:16:52,140 --> 01:16:52,150 if they have high income and good credit 3185 01:16:52,150 --> 01:16:54,930 if they have high income and good credit and they are not a student 3186 01:16:54,930 --> 01:16:54,940 and they are not a student 3187 01:16:54,940 --> 01:16:56,640 and they are not a student now one thing you need to know about 3188 01:16:56,640 --> 01:16:56,650 now one thing you need to know about 3189 01:16:56,650 --> 01:16:58,950 now one thing you need to know about these boolean operators is that they're 3190 01:16:58,950 --> 01:16:58,960 these boolean operators is that they're 3191 01:16:58,960 --> 01:17:01,410 these boolean operators is that they're a short circuit what do we mean by that 3192 01:17:01,410 --> 01:17:01,420 a short circuit what do we mean by that 3193 01:17:01,420 --> 01:17:04,860 a short circuit what do we mean by that well when Python interpreter wants to 3194 01:17:04,860 --> 01:17:04,870 well when Python interpreter wants to 3195 01:17:04,870 --> 01:17:07,260 well when Python interpreter wants to evaluate this expression it starts from 3196 01:17:07,260 --> 01:17:07,270 evaluate this expression it starts from 3197 01:17:07,270 --> 01:17:10,590 evaluate this expression it starts from the first argument if this is true it 3198 01:17:10,590 --> 01:17:10,600 the first argument if this is true it 3199 01:17:10,600 --> 01:17:13,110 the first argument if this is true it continues the evaluation to see if the 3200 01:17:13,110 --> 01:17:13,120 continues the evaluation to see if the 3201 01:17:13,120 --> 01:17:15,540 continues the evaluation to see if the second argument is also true so it 3202 01:17:15,540 --> 01:17:15,550 second argument is also true so it 3203 01:17:15,550 --> 01:17:18,300 second argument is also true so it continues the evaluation all the way to 3204 01:17:18,300 --> 01:17:18,310 continues the evaluation all the way to 3205 01:17:18,310 --> 01:17:21,030 continues the evaluation all the way to the end of this expression however as 3206 01:17:21,030 --> 01:17:21,040 the end of this expression however as 3207 01:17:21,040 --> 01:17:23,700 the end of this expression however as soon as one of these arguments is false 3208 01:17:23,700 --> 01:17:23,710 soon as one of these arguments is false 3209 01:17:23,710 --> 01:17:26,520 soon as one of these arguments is false the evaluation stops let me show you 3210 01:17:26,520 --> 01:17:26,530 the evaluation stops let me show you 3211 01:17:26,530 --> 01:17:28,919 the evaluation stops let me show you what I mean so if I change high-income 3212 01:17:28,919 --> 01:17:28,929 what I mean so if I change high-income 3213 01:17:28,929 --> 01:17:32,250 what I mean so if I change high-income to false when Python interpreter sees 3214 01:17:32,250 --> 01:17:32,260 to false when Python interpreter sees 3215 01:17:32,260 --> 01:17:36,149 to false when Python interpreter sees this expression it starts here it knows 3216 01:17:36,149 --> 01:17:36,159 this expression it starts here it knows 3217 01:17:36,159 --> 01:17:38,280 this expression it starts here it knows that high-income is false so it doesn't 3218 01:17:38,280 --> 01:17:38,290 that high-income is false so it doesn't 3219 01:17:38,290 --> 01:17:41,790 that high-income is false so it doesn't matter what comes after the result of 3220 01:17:41,790 --> 01:17:41,800 matter what comes after the result of 3221 01:17:41,800 --> 01:17:44,129 matter what comes after the result of this entire expression will always be 3222 01:17:44,129 --> 01:17:44,139 this entire expression will always be 3223 01:17:44,139 --> 01:17:46,229 this entire expression will always be false because at least one of the 3224 01:17:46,229 --> 01:17:46,239 false because at least one of the 3225 01:17:46,239 --> 01:17:48,209 false because at least one of the arguments or one of the operands is 3226 01:17:48,209 --> 01:17:48,219 arguments or one of the operands is 3227 01:17:48,219 --> 01:17:50,780 arguments or one of the operands is false this is what we call 3228 01:17:50,780 --> 01:17:50,790 false this is what we call 3229 01:17:50,790 --> 01:17:52,350 false this is what we call short-circuiting just like the 3230 01:17:52,350 --> 01:17:52,360 short-circuiting just like the 3231 01:17:52,360 --> 01:17:54,270 short-circuiting just like the short-circuit concept we have in 3232 01:17:54,270 --> 01:17:54,280 short-circuit concept we have in 3233 01:17:54,280 --> 01:17:57,450 short-circuit concept we have in electronics so the evaluation stops as 3234 01:17:57,450 --> 01:17:57,460 electronics so the evaluation stops as 3235 01:17:57,460 --> 01:18:00,660 electronics so the evaluation stops as soon as one of these arguments evaluates 3236 01:18:00,660 --> 01:18:00,670 soon as one of these arguments evaluates 3237 01:18:00,670 --> 01:18:04,110 soon as one of these arguments evaluates to false we have the same concept with 3238 01:18:04,110 --> 01:18:04,120 to false we have the same concept with 3239 01:18:04,120 --> 01:18:07,560 to false we have the same concept with the or operator so if I change these and 3240 01:18:07,560 --> 01:18:07,570 the or operator so if I change these and 3241 01:18:07,570 --> 01:18:10,610 the or operator so if I change these and operators to or let's see what happens 3242 01:18:10,610 --> 01:18:10,620 operators to or let's see what happens 3243 01:18:10,620 --> 01:18:13,680 operators to or let's see what happens with the or operator we know that at 3244 01:18:13,680 --> 01:18:13,690 with the or operator we know that at 3245 01:18:13,690 --> 01:18:15,450 with the or operator we know that at least one of the arguments should be 3246 01:18:15,450 --> 01:18:15,460 least one of the arguments should be 3247 01:18:15,460 --> 01:18:18,570 least one of the arguments should be true so the evaluation stops as soon as 3248 01:18:18,570 --> 01:18:18,580 true so the evaluation stops as soon as 3249 01:18:18,580 --> 01:18:20,580 true so the evaluation stops as soon as we find an argument that evaluates to 3250 01:18:20,580 --> 01:18:20,590 we find an argument that evaluates to 3251 01:18:20,590 --> 01:18:22,800 we find an argument that evaluates to true in this case when Python 3252 01:18:22,800 --> 01:18:22,810 true in this case when Python 3253 01:18:22,810 --> 01:18:25,470 true in this case when Python interpreter evaluates this expression it 3254 01:18:25,470 --> 01:18:25,480 interpreter evaluates this expression it 3255 01:18:25,480 --> 01:18:27,899 interpreter evaluates this expression it sees that high-income is false so it 3256 01:18:27,899 --> 01:18:27,909 sees that high-income is false so it 3257 01:18:27,909 --> 01:18:30,300 sees that high-income is false so it continues the evaluation hoping that the 3258 01:18:30,300 --> 01:18:30,310 continues the evaluation hoping that the 3259 01:18:30,310 --> 01:18:33,689 continues the evaluation hoping that the next argument will be true here good 3260 01:18:33,689 --> 01:18:33,699 next argument will be true here good 3261 01:18:33,699 --> 01:18:36,600 next argument will be true here good credit is true so evaluation stops and 3262 01:18:36,600 --> 01:18:36,610 credit is true so evaluation stops and 3263 01:18:36,610 --> 01:18:38,910 credit is true so evaluation stops and the result of this entire expression 3264 01:18:38,910 --> 01:18:38,920 the result of this entire expression 3265 01:18:38,920 --> 01:18:43,080 the result of this entire expression will be true so in Python logical 3266 01:18:43,080 --> 01:18:43,090 will be true so in Python logical 3267 01:18:43,090 --> 01:18:51,650 will be true so in Python logical operators are short-circuit 3268 01:18:51,650 --> 01:18:51,660 3269 01:18:51,660 --> 01:18:54,480 in this lecture I'm gonna show you how 3270 01:18:54,480 --> 01:18:54,490 in this lecture I'm gonna show you how 3271 01:18:54,490 --> 01:18:57,270 in this lecture I'm gonna show you how to chain comparison operators this is a 3272 01:18:57,270 --> 01:18:57,280 to chain comparison operators this is a 3273 01:18:57,280 --> 01:18:59,070 to chain comparison operators this is a very powerful technique for writing 3274 01:18:59,070 --> 01:18:59,080 very powerful technique for writing 3275 01:18:59,080 --> 01:19:01,710 very powerful technique for writing clean code here's an example let's say 3276 01:19:01,710 --> 01:19:01,720 clean code here's an example let's say 3277 01:19:01,720 --> 01:19:03,900 clean code here's an example let's say we want to implement a rule that says 3278 01:19:03,900 --> 01:19:03,910 we want to implement a rule that says 3279 01:19:03,910 --> 01:19:09,240 we want to implement a rule that says age should be between 18 and 65 here's 3280 01:19:09,240 --> 01:19:09,250 age should be between 18 and 65 here's 3281 01:19:09,250 --> 01:19:11,400 age should be between 18 and 65 here's how we can implement it so we define a 3282 01:19:11,400 --> 01:19:11,410 how we can implement it so we define a 3283 01:19:11,410 --> 01:19:14,970 how we can implement it so we define a variable like age set it to 22 now 3284 01:19:14,970 --> 01:19:14,980 variable like age set it to 22 now 3285 01:19:14,980 --> 01:19:17,820 variable like age set it to 22 now if age is greater than or equal to 18 3286 01:19:17,820 --> 01:19:17,830 if age is greater than or equal to 18 3287 01:19:17,830 --> 01:19:23,120 if age is greater than or equal to 18 and age is less than 65 then we print 3288 01:19:23,120 --> 01:19:23,130 and age is less than 65 then we print 3289 01:19:23,130 --> 01:19:26,040 and age is less than 65 then we print eligible now here's a question for you 3290 01:19:26,040 --> 01:19:26,050 eligible now here's a question for you 3291 01:19:26,050 --> 01:19:29,010 eligible now here's a question for you how do we write this rule in mass we can 3292 01:19:29,010 --> 01:19:29,020 how do we write this rule in mass we can 3293 01:19:29,020 --> 01:19:32,170 how do we write this rule in mass we can write it like this 3294 01:19:32,170 --> 01:19:32,180 3295 01:19:32,180 --> 01:19:35,260 well more accurately we shall have an 3296 01:19:35,260 --> 01:19:35,270 well more accurately we shall have an 3297 01:19:35,270 --> 01:19:37,830 well more accurately we shall have an equal sign here so age should be between 3298 01:19:37,830 --> 01:19:37,840 equal sign here so age should be between 3299 01:19:37,840 --> 01:19:41,710 equal sign here so age should be between 18 and 65 this is how we write this rule 3300 01:19:41,710 --> 01:19:41,720 18 and 65 this is how we write this rule 3301 01:19:41,720 --> 01:19:44,320 18 and 65 this is how we write this rule in math now I've got some good news for 3302 01:19:44,320 --> 01:19:44,330 in math now I've got some good news for 3303 01:19:44,330 --> 01:19:46,270 in math now I've got some good news for you we can write the exact same 3304 01:19:46,270 --> 01:19:46,280 you we can write the exact same 3305 01:19:46,280 --> 01:19:49,300 you we can write the exact same expression in Python so I'm going to 3306 01:19:49,300 --> 01:19:49,310 expression in Python so I'm going to 3307 01:19:49,310 --> 01:19:53,190 expression in Python so I'm going to move this up put an if statement here 3308 01:19:53,190 --> 01:19:53,200 move this up put an if statement here 3309 01:19:53,200 --> 01:19:57,030 move this up put an if statement here line 4 and line 3 are exactly equivalent 3310 01:19:57,030 --> 01:19:57,040 line 4 and line 3 are exactly equivalent 3311 01:19:57,040 --> 01:20:00,070 line 4 and line 3 are exactly equivalent but as you can see line 4 is cleaner and 3312 01:20:00,070 --> 01:20:00,080 but as you can see line 4 is cleaner and 3313 01:20:00,080 --> 01:20:03,070 but as you can see line 4 is cleaner and easier to read so let's get rid of line 3314 01:20:03,070 --> 01:20:03,080 easier to read so let's get rid of line 3315 01:20:03,080 --> 01:20:04,740 easier to read so let's get rid of line 3 3316 01:20:04,740 --> 01:20:04,750 3 3317 01:20:04,750 --> 01:20:07,860 3 this is what we call chaining comparison 3318 01:20:07,860 --> 01:20:07,870 this is what we call chaining comparison 3319 01:20:07,870 --> 01:20:15,919 this is what we call chaining comparison operators 3320 01:20:15,919 --> 01:20:15,929 3321 01:20:15,929 --> 01:20:18,959 all right here is a little quiz for you 3322 01:20:18,959 --> 01:20:18,969 all right here is a little quiz for you 3323 01:20:18,969 --> 01:20:21,660 all right here is a little quiz for you I want you to pause the video and think 3324 01:20:21,660 --> 01:20:21,670 I want you to pause the video and think 3325 01:20:21,670 --> 01:20:23,760 I want you to pause the video and think about this quiz for 10 to 20 seconds 3326 01:20:23,760 --> 01:20:23,770 about this quiz for 10 to 20 seconds 3327 01:20:23,770 --> 01:20:25,800 about this quiz for 10 to 20 seconds what do you think we'll see on the 3328 01:20:25,800 --> 01:20:25,810 what do you think we'll see on the 3329 01:20:25,810 --> 01:20:28,770 what do you think we'll see on the terminal when we run this program so 3330 01:20:28,770 --> 01:20:28,780 terminal when we run this program so 3331 01:20:28,780 --> 01:20:30,689 terminal when we run this program so pause the video figure out the answer 3332 01:20:30,689 --> 01:20:30,699 pause the video figure out the answer 3333 01:20:30,699 --> 01:20:32,370 pause the video figure out the answer when you're ready come back continue 3334 01:20:32,370 --> 01:20:32,380 when you're ready come back continue 3335 01:20:32,380 --> 01:20:36,220 when you're ready come back continue watching 3336 01:20:36,220 --> 01:20:36,230 3337 01:20:36,230 --> 01:20:37,990 all right let's see what happens when we 3338 01:20:37,990 --> 01:20:38,000 all right let's see what happens when we 3339 01:20:38,000 --> 01:20:40,630 all right let's see what happens when we run this program first we get this if 3340 01:20:40,630 --> 01:20:40,640 run this program first we get this if 3341 01:20:40,640 --> 01:20:42,670 run this program first we get this if statement in this case we're comparing 3342 01:20:42,670 --> 01:20:42,680 statement in this case we're comparing 3343 01:20:42,680 --> 01:20:44,950 statement in this case we're comparing two different objects for equality and 3344 01:20:44,950 --> 01:20:44,960 two different objects for equality and 3345 01:20:44,960 --> 01:20:47,290 two different objects for equality and these objects have different types we 3346 01:20:47,290 --> 01:20:47,300 these objects have different types we 3347 01:20:47,300 --> 01:20:49,530 these objects have different types we have a number compared for this string 3348 01:20:49,530 --> 01:20:49,540 have a number compared for this string 3349 01:20:49,540 --> 01:20:52,960 have a number compared for this string so number 10 and string 10 are not equal 3350 01:20:52,960 --> 01:20:52,970 so number 10 and string 10 are not equal 3351 01:20:52,970 --> 01:20:55,780 so number 10 and string 10 are not equal that is why a will not be printed on the 3352 01:20:55,780 --> 01:20:55,790 that is why a will not be printed on the 3353 01:20:55,790 --> 01:20:58,840 that is why a will not be printed on the terminal so the control moves to the 3354 01:20:58,840 --> 01:20:58,850 terminal so the control moves to the 3355 01:20:58,850 --> 01:21:01,960 terminal so the control moves to the Elif part here we have two boolean 3356 01:21:01,960 --> 01:21:01,970 Elif part here we have two boolean 3357 01:21:01,970 --> 01:21:04,870 Elif part here we have two boolean expressions here's the first one here is 3358 01:21:04,870 --> 01:21:04,880 expressions here's the first one here is 3359 01:21:04,880 --> 01:21:07,750 expressions here's the first one here is a second one and they are combined using 3360 01:21:07,750 --> 01:21:07,760 a second one and they are combined using 3361 01:21:07,760 --> 01:21:10,270 a second one and they are combined using the logical end so if both these 3362 01:21:10,270 --> 01:21:10,280 the logical end so if both these 3363 01:21:10,280 --> 01:21:13,240 the logical end so if both these expressions are evaluated to true then 3364 01:21:13,240 --> 01:21:13,250 expressions are evaluated to true then 3365 01:21:13,250 --> 01:21:15,790 expressions are evaluated to true then this entire expression will be true and 3366 01:21:15,790 --> 01:21:15,800 this entire expression will be true and 3367 01:21:15,800 --> 01:21:18,520 this entire expression will be true and we will see beyond the terminal let's 3368 01:21:18,520 --> 01:21:18,530 we will see beyond the terminal let's 3369 01:21:18,530 --> 01:21:20,229 we will see beyond the terminal let's see if both these expressions are 3370 01:21:20,229 --> 01:21:20,239 see if both these expressions are 3371 01:21:20,239 --> 01:21:22,860 see if both these expressions are evaluated to true here's the first part 3372 01:21:22,860 --> 01:21:22,870 evaluated to true here's the first part 3373 01:21:22,870 --> 01:21:26,170 evaluated to true here's the first part bag is greater than Apple that is true 3374 01:21:26,170 --> 01:21:26,180 bag is greater than Apple that is true 3375 01:21:26,180 --> 01:21:28,810 bag is greater than Apple that is true because when we sort this words bag 3376 01:21:28,810 --> 01:21:28,820 because when we sort this words bag 3377 01:21:28,820 --> 01:21:31,870 because when we sort this words bag comes after Apple but look at the second 3378 01:21:31,870 --> 01:21:31,880 comes after Apple but look at the second 3379 01:21:31,880 --> 01:21:34,690 comes after Apple but look at the second part this expression is evaluated to 3380 01:21:34,690 --> 01:21:34,700 part this expression is evaluated to 3381 01:21:34,700 --> 01:21:36,910 part this expression is evaluated to false because bag is not greater than 3382 01:21:36,910 --> 01:21:36,920 false because bag is not greater than 3383 01:21:36,920 --> 01:21:39,729 false because bag is not greater than cat so when we applied the logical end 3384 01:21:39,729 --> 01:21:39,739 cat so when we applied the logical end 3385 01:21:39,739 --> 01:21:42,970 cat so when we applied the logical end between true and false the result will 3386 01:21:42,970 --> 01:21:42,980 between true and false the result will 3387 01:21:42,980 --> 01:21:46,180 between true and false the result will be false that is why this statement will 3388 01:21:46,180 --> 01:21:46,190 be false that is why this statement will 3389 01:21:46,190 --> 01:21:48,760 be false that is why this statement will not be executed so the control moves to 3390 01:21:48,760 --> 01:21:48,770 not be executed so the control moves to 3391 01:21:48,770 --> 01:21:51,310 not be executed so the control moves to the else part and when we run this 3392 01:21:51,310 --> 01:21:51,320 the else part and when we run this 3393 01:21:51,320 --> 01:21:53,680 the else part and when we run this program the letter C will be printed on 3394 01:21:53,680 --> 01:21:53,690 program the letter C will be printed on 3395 01:21:53,690 --> 01:22:01,600 program the letter C will be printed on the terminal 3396 01:22:01,600 --> 01:22:01,610 3397 01:22:01,610 --> 01:22:03,920 there are times that we may want to 3398 01:22:03,920 --> 01:22:03,930 there are times that we may want to 3399 01:22:03,930 --> 01:22:06,620 there are times that we may want to repeat a task a number of times for 3400 01:22:06,620 --> 01:22:06,630 repeat a task a number of times for 3401 01:22:06,630 --> 01:22:08,870 repeat a task a number of times for example let's say we send a message to a 3402 01:22:08,870 --> 01:22:08,880 example let's say we send a message to a 3403 01:22:08,880 --> 01:22:11,540 example let's say we send a message to a user if that message cannot be delivered 3404 01:22:11,540 --> 01:22:11,550 user if that message cannot be delivered 3405 01:22:11,550 --> 01:22:14,840 user if that message cannot be delivered perhaps we want to retry three times now 3406 01:22:14,840 --> 01:22:14,850 perhaps we want to retry three times now 3407 01:22:14,850 --> 01:22:17,510 perhaps we want to retry three times now for simplicity let's imagine this print 3408 01:22:17,510 --> 01:22:17,520 for simplicity let's imagine this print 3409 01:22:17,520 --> 01:22:20,180 for simplicity let's imagine this print statement is equivalent to sending a 3410 01:22:20,180 --> 01:22:20,190 statement is equivalent to sending a 3411 01:22:20,190 --> 01:22:23,570 statement is equivalent to sending a message in a real-world program to send 3412 01:22:23,570 --> 01:22:23,580 message in a real-world program to send 3413 01:22:23,580 --> 01:22:25,160 message in a real-world program to send a message to a user we have to write 3414 01:22:25,160 --> 01:22:25,170 a message to a user we have to write 3415 01:22:25,170 --> 01:22:26,690 a message to a user we have to write five to ten lines of code 3416 01:22:26,690 --> 01:22:26,700 five to ten lines of code 3417 01:22:26,700 --> 01:22:29,420 five to ten lines of code now if you want to retry three times we 3418 01:22:29,420 --> 01:22:29,430 now if you want to retry three times we 3419 01:22:29,430 --> 01:22:31,160 now if you want to retry three times we don't want to repeat all that code that 3420 01:22:31,160 --> 01:22:31,170 don't want to repeat all that code that 3421 01:22:31,170 --> 01:22:34,370 don't want to repeat all that code that is ugly that's when we use a loop we use 3422 01:22:34,370 --> 01:22:34,380 is ugly that's when we use a loop we use 3423 01:22:34,380 --> 01:22:37,550 is ugly that's when we use a loop we use loops to create repetition so here is 3424 01:22:37,550 --> 01:22:37,560 loops to create repetition so here is 3425 01:22:37,560 --> 01:22:41,120 loops to create repetition so here is how it works we start with four number 3426 01:22:41,120 --> 01:22:41,130 how it works we start with four number 3427 01:22:41,130 --> 01:22:43,940 how it works we start with four number in we have a built-in function called 3428 01:22:43,940 --> 01:22:43,950 in we have a built-in function called 3429 01:22:43,950 --> 01:22:46,820 in we have a built-in function called range now how many times we want to 3430 01:22:46,820 --> 01:22:46,830 range now how many times we want to 3431 01:22:46,830 --> 01:22:49,070 range now how many times we want to repeat this task let's say three times 3432 01:22:49,070 --> 01:22:49,080 repeat this task let's say three times 3433 01:22:49,080 --> 01:22:52,250 repeat this task let's say three times so we call range and pass three as an 3434 01:22:52,250 --> 01:22:52,260 so we call range and pass three as an 3435 01:22:52,260 --> 01:22:54,710 so we call range and pass three as an argument now similar to our if 3436 01:22:54,710 --> 01:22:54,720 argument now similar to our if 3437 01:22:54,720 --> 01:22:57,050 argument now similar to our if statements we need to terminate this 3438 01:22:57,050 --> 01:22:57,060 statements we need to terminate this 3439 01:22:57,060 --> 01:23:00,200 statements we need to terminate this line with a colon enter we get 3440 01:23:00,200 --> 01:23:00,210 line with a colon enter we get 3441 01:23:00,210 --> 01:23:03,110 line with a colon enter we get indentation so in this block we can 3442 01:23:03,110 --> 01:23:03,120 indentation so in this block we can 3443 01:23:03,120 --> 01:23:05,030 indentation so in this block we can write all the statements that should be 3444 01:23:05,030 --> 01:23:05,040 write all the statements that should be 3445 01:23:05,040 --> 01:23:08,390 write all the statements that should be repeated three times let's do a print a 3446 01:23:08,390 --> 01:23:08,400 repeated three times let's do a print a 3447 01:23:08,400 --> 01:23:11,590 repeated three times let's do a print a message like attempt save the changes 3448 01:23:11,590 --> 01:23:11,600 message like attempt save the changes 3449 01:23:11,600 --> 01:23:14,810 message like attempt save the changes run the program so we have attempt 3450 01:23:14,810 --> 01:23:14,820 run the program so we have attempt 3451 01:23:14,820 --> 01:23:17,660 run the program so we have attempt printed three times beautiful now what 3452 01:23:17,660 --> 01:23:17,670 printed three times beautiful now what 3453 01:23:17,670 --> 01:23:21,080 printed three times beautiful now what is this number let's take a look it's a 3454 01:23:21,080 --> 01:23:21,090 is this number let's take a look it's a 3455 01:23:21,090 --> 01:23:24,560 is this number let's take a look it's a variable of type integer so let's pass 3456 01:23:24,560 --> 01:23:24,570 variable of type integer so let's pass 3457 01:23:24,570 --> 01:23:26,840 variable of type integer so let's pass it as the second argument to the print 3458 01:23:26,840 --> 01:23:26,850 it as the second argument to the print 3459 01:23:26,850 --> 01:23:31,130 it as the second argument to the print function number run the program this is 3460 01:23:31,130 --> 01:23:31,140 function number run the program this is 3461 01:23:31,140 --> 01:23:34,910 function number run the program this is what we get zero one two so here we have 3462 01:23:34,910 --> 01:23:34,920 what we get zero one two so here we have 3463 01:23:34,920 --> 01:23:37,580 what we get zero one two so here we have a for loop this for loop is executed 3464 01:23:37,580 --> 01:23:37,590 a for loop this for loop is executed 3465 01:23:37,590 --> 01:23:40,880 a for loop this for loop is executed three times in each iteration number 3466 01:23:40,880 --> 01:23:40,890 three times in each iteration number 3467 01:23:40,890 --> 01:23:43,220 three times in each iteration number will have a different value initially it 3468 01:23:43,220 --> 01:23:43,230 will have a different value initially it 3469 01:23:43,230 --> 01:23:45,500 will have a different value initially it will be zero in the second iteration it 3470 01:23:45,500 --> 01:23:45,510 will be zero in the second iteration it 3471 01:23:45,510 --> 01:23:47,360 will be zero in the second iteration it will be one and finally in the last 3472 01:23:47,360 --> 01:23:47,370 will be one and finally in the last 3473 01:23:47,370 --> 01:23:49,940 will be one and finally in the last iteration it will be two now here we can 3474 01:23:49,940 --> 01:23:49,950 iteration it will be two now here we can 3475 01:23:49,950 --> 01:23:54,370 iteration it will be two now here we can do something fun we can add one to this 3476 01:23:54,370 --> 01:23:54,380 do something fun we can add one to this 3477 01:23:54,380 --> 01:23:57,530 do something fun we can add one to this run the program and now the message is 3478 01:23:57,530 --> 01:23:57,540 run the program and now the message is 3479 01:23:57,540 --> 01:23:58,970 run the program and now the message is that the print are kind of more 3480 01:23:58,970 --> 01:23:58,980 that the print are kind of more 3481 01:23:58,980 --> 01:24:01,550 that the print are kind of more meaningful or more user-friendly like 3482 01:24:01,550 --> 01:24:01,560 meaningful or more user-friendly like 3483 01:24:01,560 --> 01:24:03,500 meaningful or more user-friendly like attempting number one attempting number 3484 01:24:03,500 --> 01:24:03,510 attempting number one attempting number 3485 01:24:03,510 --> 01:24:06,020 attempting number one attempting number two and so on we can take this to the 3486 01:24:06,020 --> 01:24:06,030 two and so on we can take this to the 3487 01:24:06,030 --> 01:24:08,240 two and so on we can take this to the next level so we can pass another 3488 01:24:08,240 --> 01:24:08,250 next level so we can pass another 3489 01:24:08,250 --> 01:24:10,250 next level so we can pass another argument here I'm gonna add an 3490 01:24:10,250 --> 01:24:10,260 argument here I'm gonna add an 3491 01:24:10,260 --> 01:24:12,410 argument here I'm gonna add an expression one more time number 3492 01:24:12,410 --> 01:24:12,420 expression one more time number 3493 01:24:12,420 --> 01:24:15,890 expression one more time number plus one so we'll get one two three now 3494 01:24:15,890 --> 01:24:15,900 plus one so we'll get one two three now 3495 01:24:15,900 --> 01:24:17,270 plus one so we'll get one two three now I want to put this expression in 3496 01:24:17,270 --> 01:24:17,280 I want to put this expression in 3497 01:24:17,280 --> 01:24:21,320 I want to put this expression in parentheses so let's select this put it 3498 01:24:21,320 --> 01:24:21,330 parentheses so let's select this put it 3499 01:24:21,330 --> 01:24:25,130 parentheses so let's select this put it in parentheses and then multiply it by a 3500 01:24:25,130 --> 01:24:25,140 in parentheses and then multiply it by a 3501 01:24:25,140 --> 01:24:28,430 in parentheses and then multiply it by a dot so here we have a string that is 3502 01:24:28,430 --> 01:24:28,440 dot so here we have a string that is 3503 01:24:28,440 --> 01:24:31,250 dot so here we have a string that is multiplied by a number the result will 3504 01:24:31,250 --> 01:24:31,260 multiplied by a number the result will 3505 01:24:31,260 --> 01:24:33,650 multiplied by a number the result will be that string repeated that number of 3506 01:24:33,650 --> 01:24:33,660 be that string repeated that number of 3507 01:24:33,660 --> 01:24:36,320 be that string repeated that number of times let's take a look around the 3508 01:24:36,320 --> 01:24:36,330 times let's take a look around the 3509 01:24:36,330 --> 01:24:39,820 times let's take a look around the program see that's pretty cool isn't it 3510 01:24:39,820 --> 01:24:39,830 program see that's pretty cool isn't it 3511 01:24:39,830 --> 01:24:41,630 program see that's pretty cool isn't it now let me show you one more thing 3512 01:24:41,630 --> 01:24:41,640 now let me show you one more thing 3513 01:24:41,640 --> 01:24:44,240 now let me show you one more thing before we finish this lecture as you saw 3514 01:24:44,240 --> 01:24:44,250 before we finish this lecture as you saw 3515 01:24:44,250 --> 01:24:46,280 before we finish this lecture as you saw this range function generates numbers 3516 01:24:46,280 --> 01:24:46,290 this range function generates numbers 3517 01:24:46,290 --> 01:24:48,800 this range function generates numbers starting from zero all the way up to 3518 01:24:48,800 --> 01:24:48,810 starting from zero all the way up to 3519 01:24:48,810 --> 01:24:50,570 starting from zero all the way up to this number here but it doesn't include 3520 01:24:50,570 --> 01:24:50,580 this number here but it doesn't include 3521 01:24:50,580 --> 01:24:53,000 this number here but it doesn't include this number here we can pass another 3522 01:24:53,000 --> 01:24:53,010 this number here we can pass another 3523 01:24:53,010 --> 01:24:56,600 this number here we can pass another argument say start from 1 and finish 3524 01:24:56,600 --> 01:24:56,610 argument say start from 1 and finish 3525 01:24:56,610 --> 01:25:00,110 argument say start from 1 and finish before 4 with this change we don't need 3526 01:25:00,110 --> 01:25:00,120 before 4 with this change we don't need 3527 01:25:00,120 --> 01:25:03,320 before 4 with this change we don't need to add 1 to number every time because in 3528 01:25:03,320 --> 01:25:03,330 to add 1 to number every time because in 3529 01:25:03,330 --> 01:25:05,540 to add 1 to number every time because in the first iteration this number variable 3530 01:25:05,540 --> 01:25:05,550 the first iteration this number variable 3531 01:25:05,550 --> 01:25:08,479 the first iteration this number variable will be set to 1 so we can simplify our 3532 01:25:08,479 --> 01:25:08,489 will be set to 1 so we can simplify our 3533 01:25:08,489 --> 01:25:11,540 will be set to 1 so we can simplify our code and make it clean air let's run it 3534 01:25:11,540 --> 01:25:11,550 code and make it clean air let's run it 3535 01:25:11,550 --> 01:25:13,640 code and make it clean air let's run it one more time we get the exact same 3536 01:25:13,640 --> 01:25:13,650 one more time we get the exact same 3537 01:25:13,650 --> 01:25:17,419 one more time we get the exact same result we can also pass a third argument 3538 01:25:17,419 --> 01:25:17,429 result we can also pass a third argument 3539 01:25:17,429 --> 01:25:19,669 result we can also pass a third argument as a step so I'm going to change the 3540 01:25:19,669 --> 01:25:19,679 as a step so I'm going to change the 3541 01:25:19,679 --> 01:25:23,209 as a step so I'm going to change the second argument to 10 and pass two as a 3542 01:25:23,209 --> 01:25:23,219 second argument to 10 and pass two as a 3543 01:25:23,219 --> 01:25:27,140 second argument to 10 and pass two as a step look at the result these are the 3544 01:25:27,140 --> 01:25:27,150 step look at the result these are the 3545 01:25:27,150 --> 01:25:30,680 step look at the result these are the numbers we get 1 3 5 and so on so pretty 3546 01:25:30,680 --> 01:25:30,690 numbers we get 1 3 5 and so on so pretty 3547 01:25:30,690 --> 01:25:31,970 numbers we get 1 3 5 and so on so pretty useful you're going to use this function 3548 01:25:31,970 --> 01:25:31,980 useful you're going to use this function 3549 01:25:31,980 --> 01:25:41,540 useful you're going to use this function a lot in real-world applications 3550 01:25:41,540 --> 01:25:41,550 3551 01:25:41,550 --> 01:25:43,500 continuing with the example from the 3552 01:25:43,500 --> 01:25:43,510 continuing with the example from the 3553 01:25:43,510 --> 01:25:45,720 continuing with the example from the last lecture let's imagine the scenario 3554 01:25:45,720 --> 01:25:45,730 last lecture let's imagine the scenario 3555 01:25:45,730 --> 01:25:48,060 last lecture let's imagine the scenario where after the first attempt we can 3556 01:25:48,060 --> 01:25:48,070 where after the first attempt we can 3557 01:25:48,070 --> 01:25:50,520 where after the first attempt we can successfully send the message in that 3558 01:25:50,520 --> 01:25:50,530 successfully send the message in that 3559 01:25:50,530 --> 01:25:52,620 successfully send the message in that case you want to jump out of this loop 3560 01:25:52,620 --> 01:25:52,630 case you want to jump out of this loop 3561 01:25:52,630 --> 01:25:55,740 case you want to jump out of this loop we don't want to repeat this task of 3562 01:25:55,740 --> 01:25:55,750 we don't want to repeat this task of 3563 01:25:55,750 --> 01:25:58,140 we don't want to repeat this task of sending a message three times let me 3564 01:25:58,140 --> 01:25:58,150 sending a message three times let me 3565 01:25:58,150 --> 01:26:00,299 sending a message three times let me show you how to implement this so in 3566 01:26:00,299 --> 01:26:00,309 show you how to implement this so in 3567 01:26:00,309 --> 01:26:02,040 show you how to implement this so in this demo I'm gonna simulate the 3568 01:26:02,040 --> 01:26:02,050 this demo I'm gonna simulate the 3569 01:26:02,050 --> 01:26:04,350 this demo I'm gonna simulate the scenario where we can successfully send 3570 01:26:04,350 --> 01:26:04,360 scenario where we can successfully send 3571 01:26:04,360 --> 01:26:07,459 scenario where we can successfully send a message so we define a variable 3572 01:26:07,459 --> 01:26:07,469 a message so we define a variable 3573 01:26:07,469 --> 01:26:10,580 a message so we define a variable successful and set it to true 3574 01:26:10,580 --> 01:26:10,590 successful and set it to true 3575 01:26:10,590 --> 01:26:13,310 successful and set it to true now here after this print statement 3576 01:26:13,310 --> 01:26:13,320 now here after this print statement 3577 01:26:13,320 --> 01:26:17,990 now here after this print statement we'll have an if statement if successful 3578 01:26:17,990 --> 01:26:18,000 we'll have an if statement if successful 3579 01:26:18,000 --> 01:26:19,169 we'll have an if statement if successful : 3580 01:26:19,169 --> 01:26:19,179 : 3581 01:26:19,179 --> 01:26:24,689 : then perhaps we can print successful now 3582 01:26:24,689 --> 01:26:24,699 then perhaps we can print successful now 3583 01:26:24,699 --> 01:26:26,580 then perhaps we can print successful now here we want to jump out of this loop 3584 01:26:26,580 --> 01:26:26,590 here we want to jump out of this loop 3585 01:26:26,590 --> 01:26:29,029 here we want to jump out of this loop for that we use the break statement 3586 01:26:29,029 --> 01:26:29,039 for that we use the break statement 3587 01:26:29,039 --> 01:26:31,109 for that we use the break statement let's run this program and see what 3588 01:26:31,109 --> 01:26:31,119 let's run this program and see what 3589 01:26:31,119 --> 01:26:31,709 let's run this program and see what happens 3590 01:26:31,709 --> 01:26:31,719 happens 3591 01:26:31,719 --> 01:26:35,459 happens so there you go after the first attempt 3592 01:26:35,459 --> 01:26:35,469 so there you go after the first attempt 3593 01:26:35,469 --> 01:26:38,459 so there you go after the first attempt we are successful and there are no more 3594 01:26:38,459 --> 01:26:38,469 we are successful and there are no more 3595 01:26:38,469 --> 01:26:41,609 we are successful and there are no more attempts so once again I want you to pay 3596 01:26:41,609 --> 01:26:41,619 attempts so once again I want you to pay 3597 01:26:41,619 --> 01:26:43,770 attempts so once again I want you to pay great attention to the indentation here 3598 01:26:43,770 --> 01:26:43,780 great attention to the indentation here 3599 01:26:43,780 --> 01:26:45,689 great attention to the indentation here because that's one of the common issues 3600 01:26:45,689 --> 01:26:45,699 because that's one of the common issues 3601 01:26:45,699 --> 01:26:48,919 because that's one of the common issues amongst beginners so here's our for loop 3602 01:26:48,919 --> 01:26:48,929 amongst beginners so here's our for loop 3603 01:26:48,929 --> 01:26:51,689 amongst beginners so here's our for loop these two lines are indented with four 3604 01:26:51,689 --> 01:26:51,699 these two lines are indented with four 3605 01:26:51,699 --> 01:26:54,270 these two lines are indented with four spaces and they belong to our for loop 3606 01:26:54,270 --> 01:26:54,280 spaces and they belong to our for loop 3607 01:26:54,280 --> 01:26:57,000 spaces and they belong to our for loop in every iteration these two lines will 3608 01:26:57,000 --> 01:26:57,010 in every iteration these two lines will 3609 01:26:57,010 --> 01:27:00,029 in every iteration these two lines will be executed now when we get to line four 3610 01:27:00,029 --> 01:27:00,039 be executed now when we get to line four 3611 01:27:00,039 --> 01:27:04,140 be executed now when we get to line four if this condition is true then these two 3612 01:27:04,140 --> 01:27:04,150 if this condition is true then these two 3613 01:27:04,150 --> 01:27:06,689 if this condition is true then these two lines will be executed because both 3614 01:27:06,689 --> 01:27:06,699 lines will be executed because both 3615 01:27:06,699 --> 01:27:10,049 lines will be executed because both these lines are indented below this if 3616 01:27:10,049 --> 01:27:10,059 these lines are indented below this if 3617 01:27:10,059 --> 01:27:12,660 these lines are indented below this if statement now let's take this program to 3618 01:27:12,660 --> 01:27:12,670 statement now let's take this program to 3619 01:27:12,670 --> 01:27:15,419 statement now let's take this program to the next level what if we attempt three 3620 01:27:15,419 --> 01:27:15,429 the next level what if we attempt three 3621 01:27:15,429 --> 01:27:17,720 the next level what if we attempt three times and we still cannot send an email 3622 01:27:17,720 --> 01:27:17,730 times and we still cannot send an email 3623 01:27:17,730 --> 01:27:19,589 times and we still cannot send an email perhaps we want to display a different 3624 01:27:19,589 --> 01:27:19,599 perhaps we want to display a different 3625 01:27:19,599 --> 01:27:22,200 perhaps we want to display a different message to the user we say hey we tried 3626 01:27:22,200 --> 01:27:22,210 message to the user we say hey we tried 3627 01:27:22,210 --> 01:27:25,259 message to the user we say hey we tried three times but it didn't work so I'm 3628 01:27:25,259 --> 01:27:25,269 three times but it didn't work so I'm 3629 01:27:25,269 --> 01:27:29,790 three times but it didn't work so I'm gonna change successful to false now at 3630 01:27:29,790 --> 01:27:29,800 gonna change successful to false now at 3631 01:27:29,800 --> 01:27:32,370 gonna change successful to false now at the end here we can add an else 3632 01:27:32,370 --> 01:27:32,380 the end here we can add an else 3633 01:27:32,380 --> 01:27:34,770 the end here we can add an else statement this is what we call a for 3634 01:27:34,770 --> 01:27:34,780 statement this is what we call a for 3635 01:27:34,780 --> 01:27:37,589 statement this is what we call a for else statement what we put under this 3636 01:27:37,589 --> 01:27:37,599 else statement what we put under this 3637 01:27:37,599 --> 01:27:40,169 else statement what we put under this else statement will only be executed if 3638 01:27:40,169 --> 01:27:40,179 else statement will only be executed if 3639 01:27:40,179 --> 01:27:42,750 else statement will only be executed if this loop completes without an early 3640 01:27:42,750 --> 01:27:42,760 this loop completes without an early 3641 01:27:42,760 --> 01:27:45,359 this loop completes without an early termination so if we never break out of 3642 01:27:45,359 --> 01:27:45,369 termination so if we never break out of 3643 01:27:45,369 --> 01:27:48,180 termination so if we never break out of this loop then the else statement will 3644 01:27:48,180 --> 01:27:48,190 this loop then the else statement will 3645 01:27:48,190 --> 01:27:50,759 this loop then the else statement will be executed so here we can print a 3646 01:27:50,759 --> 01:27:50,769 be executed so here we can print a 3647 01:27:50,769 --> 01:27:51,730 be executed so here we can print a message like 3648 01:27:51,730 --> 01:27:51,740 message like 3649 01:27:51,740 --> 01:27:57,310 message like attempt at three times and failed so run 3650 01:27:57,310 --> 01:27:57,320 attempt at three times and failed so run 3651 01:27:57,320 --> 01:27:59,989 attempt at three times and failed so run the program 3652 01:27:59,989 --> 01:27:59,999 3653 01:27:59,999 --> 01:28:03,020 see what we get three attempts followed 3654 01:28:03,020 --> 01:28:03,030 see what we get three attempts followed 3655 01:28:03,030 --> 01:28:04,910 see what we get three attempts followed by this message attempted three times 3656 01:28:04,910 --> 01:28:04,920 by this message attempted three times 3657 01:28:04,920 --> 01:28:08,689 by this message attempted three times and failed in contrast if we change 3658 01:28:08,689 --> 01:28:08,699 and failed in contrast if we change 3659 01:28:08,699 --> 01:28:11,689 and failed in contrast if we change successful to true because we terminate 3660 01:28:11,689 --> 01:28:11,699 successful to true because we terminate 3661 01:28:11,699 --> 01:28:13,489 successful to true because we terminate this loop using this break statement 3662 01:28:13,489 --> 01:28:13,499 this loop using this break statement 3663 01:28:13,499 --> 01:28:16,729 this loop using this break statement what we have in the else block will not 3664 01:28:16,729 --> 01:28:16,739 what we have in the else block will not 3665 01:28:16,739 --> 01:28:18,350 what we have in the else block will not be executed take a look 3666 01:28:18,350 --> 01:28:18,360 be executed take a look 3667 01:28:18,360 --> 01:28:21,080 be executed take a look run the program we have one attempt 3668 01:28:21,080 --> 01:28:21,090 run the program we have one attempt 3669 01:28:21,090 --> 01:28:29,850 run the program we have one attempt successful done 3670 01:28:29,850 --> 01:28:29,860 3671 01:28:29,860 --> 01:28:32,350 in programming we have this concept 3672 01:28:32,350 --> 01:28:32,360 in programming we have this concept 3673 01:28:32,360 --> 01:28:34,900 in programming we have this concept called nested loops so we can put one 3674 01:28:34,900 --> 01:28:34,910 called nested loops so we can put one 3675 01:28:34,910 --> 01:28:37,450 called nested loops so we can put one loop inside of another loop and with 3676 01:28:37,450 --> 01:28:37,460 loop inside of another loop and with 3677 01:28:37,460 --> 01:28:39,150 loop inside of another loop and with this we can get some interesting results 3678 01:28:39,150 --> 01:28:39,160 this we can get some interesting results 3679 01:28:39,160 --> 01:28:41,950 this we can get some interesting results let me show you so I'm going to start 3680 01:28:41,950 --> 01:28:41,960 let me show you so I'm going to start 3681 01:28:41,960 --> 01:28:48,460 let me show you so I'm going to start with this loop for X in range 5 : now 3682 01:28:48,460 --> 01:28:48,470 with this loop for X in range 5 : now 3683 01:28:48,470 --> 01:28:50,260 with this loop for X in range 5 : now inside of this loop I'm gonna add 3684 01:28:50,260 --> 01:28:50,270 inside of this loop I'm gonna add 3685 01:28:50,270 --> 01:28:57,040 inside of this loop I'm gonna add another loop so for Y in range 3 : 3686 01:28:57,040 --> 01:28:57,050 another loop so for Y in range 3 : 3687 01:28:57,050 --> 01:28:59,770 another loop so for Y in range 3 : and then in our second loop I'm gonna 3688 01:28:59,770 --> 01:28:59,780 and then in our second loop I'm gonna 3689 01:28:59,780 --> 01:29:02,820 and then in our second loop I'm gonna add a print statement here we can use 3690 01:29:02,820 --> 01:29:02,830 add a print statement here we can use 3691 01:29:02,830 --> 01:29:06,340 add a print statement here we can use formatted strings to display coordinates 3692 01:29:06,340 --> 01:29:06,350 formatted strings to display coordinates 3693 01:29:06,350 --> 01:29:09,100 formatted strings to display coordinates remember formatted string so we have F 3694 01:29:09,100 --> 01:29:09,110 remember formatted string so we have F 3695 01:29:09,110 --> 01:29:12,250 remember formatted string so we have F followed by quotes now here we add 3696 01:29:12,250 --> 01:29:12,260 followed by quotes now here we add 3697 01:29:12,260 --> 01:29:15,190 followed by quotes now here we add parentheses for our coordinate first we 3698 01:29:15,190 --> 01:29:15,200 parentheses for our coordinate first we 3699 01:29:15,200 --> 01:29:17,830 parentheses for our coordinate first we want to display X and then comma 3700 01:29:17,830 --> 01:29:17,840 want to display X and then comma 3701 01:29:17,840 --> 01:29:21,880 want to display X and then comma followed by Y let's run this program and 3702 01:29:21,880 --> 01:29:21,890 followed by Y let's run this program and 3703 01:29:21,890 --> 01:29:25,420 followed by Y let's run this program and see what happens there you go pretty 3704 01:29:25,420 --> 01:29:25,430 see what happens there you go pretty 3705 01:29:25,430 --> 01:29:29,650 see what happens there you go pretty cool isn't it so we get 0 + 0 0 1 0 & 2 3706 01:29:29,650 --> 01:29:29,660 cool isn't it so we get 0 + 0 0 1 0 & 2 3707 01:29:29,660 --> 01:29:33,840 cool isn't it so we get 0 + 0 0 1 0 & 2 then we get 1 & 0 1 & 1 1 & 2 and so on 3708 01:29:33,840 --> 01:29:33,850 then we get 1 & 0 1 & 1 1 & 2 and so on 3709 01:29:33,850 --> 01:29:37,240 then we get 1 & 0 1 & 1 1 & 2 and so on now let me explain how exactly Python 3710 01:29:37,240 --> 01:29:37,250 now let me explain how exactly Python 3711 01:29:37,250 --> 01:29:40,240 now let me explain how exactly Python interpreter executes this code so here 3712 01:29:40,240 --> 01:29:40,250 interpreter executes this code so here 3713 01:29:40,250 --> 01:29:42,310 interpreter executes this code so here we have two loops this is what we call 3714 01:29:42,310 --> 01:29:42,320 we have two loops this is what we call 3715 01:29:42,320 --> 01:29:45,340 we have two loops this is what we call the outer loop and this is the inner 3716 01:29:45,340 --> 01:29:45,350 the outer loop and this is the inner 3717 01:29:45,350 --> 01:29:48,010 the outer loop and this is the inner loop so the execution of our program 3718 01:29:48,010 --> 01:29:48,020 loop so the execution of our program 3719 01:29:48,020 --> 01:29:50,530 loop so the execution of our program starts here in the first iteration of 3720 01:29:50,530 --> 01:29:50,540 starts here in the first iteration of 3721 01:29:50,540 --> 01:29:54,280 starts here in the first iteration of this loop X is 0 now we get to this 3722 01:29:54,280 --> 01:29:54,290 this loop X is 0 now we get to this 3723 01:29:54,290 --> 01:29:57,970 this loop X is 0 now we get to this statement which is a child of this for 3724 01:29:57,970 --> 01:29:57,980 statement which is a child of this for 3725 01:29:57,980 --> 01:30:00,220 statement which is a child of this for statement because it's indented four 3726 01:30:00,220 --> 01:30:00,230 statement because it's indented four 3727 01:30:00,230 --> 01:30:04,120 statement because it's indented four times this statement itself is a loop so 3728 01:30:04,120 --> 01:30:04,130 times this statement itself is a loop so 3729 01:30:04,130 --> 01:30:06,730 times this statement itself is a loop so what we have inside of this loop will be 3730 01:30:06,730 --> 01:30:06,740 what we have inside of this loop will be 3731 01:30:06,740 --> 01:30:10,060 what we have inside of this loop will be executed three times in the first 3732 01:30:10,060 --> 01:30:10,070 executed three times in the first 3733 01:30:10,070 --> 01:30:13,210 executed three times in the first iteration X is 0 because we're still in 3734 01:30:13,210 --> 01:30:13,220 iteration X is 0 because we're still in 3735 01:30:13,220 --> 01:30:15,400 iteration X is 0 because we're still in the first iteration of the outer loop 3736 01:30:15,400 --> 01:30:15,410 the first iteration of the outer loop 3737 01:30:15,410 --> 01:30:18,730 the first iteration of the outer loop and Y is also 0 because we're in the 3738 01:30:18,730 --> 01:30:18,740 and Y is also 0 because we're in the 3739 01:30:18,740 --> 01:30:21,160 and Y is also 0 because we're in the first iteration of the inner loop that 3740 01:30:21,160 --> 01:30:21,170 first iteration of the inner loop that 3741 01:30:21,170 --> 01:30:25,030 first iteration of the inner loop that is why we get 0 and 0 now we go to the 3742 01:30:25,030 --> 01:30:25,040 is why we get 0 and 0 now we go to the 3743 01:30:25,040 --> 01:30:27,610 is why we get 0 and 0 now we go to the second iteration of this inner loop in 3744 01:30:27,610 --> 01:30:27,620 second iteration of this inner loop in 3745 01:30:27,620 --> 01:30:31,030 second iteration of this inner loop in this iteration Y will be 1 whereas X is 3746 01:30:31,030 --> 01:30:31,040 this iteration Y will be 1 whereas X is 3747 01:30:31,040 --> 01:30:34,270 this iteration Y will be 1 whereas X is still 0 that is why we get 0 and 1 and 3748 01:30:34,270 --> 01:30:34,280 still 0 that is why we get 0 and 1 and 3749 01:30:34,280 --> 01:30:36,760 still 0 that is why we get 0 and 1 and similarly in the third iteration of our 3750 01:30:36,760 --> 01:30:36,770 similarly in the third iteration of our 3751 01:30:36,770 --> 01:30:40,620 similarly in the third iteration of our inner loop we'll get 0 and 2 in the turn 3752 01:30:40,620 --> 01:30:40,630 inner loop we'll get 0 and 2 in the turn 3753 01:30:40,630 --> 01:30:43,050 inner loop we'll get 0 and 2 in the turn now we're done with the execution of the 3754 01:30:43,050 --> 01:30:43,060 now we're done with the execution of the 3755 01:30:43,060 --> 01:30:45,870 now we're done with the execution of the inner loop so the control moves back to 3756 01:30:45,870 --> 01:30:45,880 inner loop so the control moves back to 3757 01:30:45,880 --> 01:30:47,910 inner loop so the control moves back to our outer loop here we'll be in the 3758 01:30:47,910 --> 01:30:47,920 our outer loop here we'll be in the 3759 01:30:47,920 --> 01:30:50,400 our outer loop here we'll be in the second iteration so X will be one and 3760 01:30:50,400 --> 01:30:50,410 second iteration so X will be one and 3761 01:30:50,410 --> 01:30:54,060 second iteration so X will be one and then we start here again so we have to 3762 01:30:54,060 --> 01:30:54,070 then we start here again so we have to 3763 01:30:54,070 --> 01:30:56,640 then we start here again so we have to execute this inner loop three times in 3764 01:30:56,640 --> 01:30:56,650 execute this inner loop three times in 3765 01:30:56,650 --> 01:31:00,450 execute this inner loop three times in the first iteration y will be 0 and X is 3766 01:31:00,450 --> 01:31:00,460 the first iteration y will be 0 and X is 3767 01:31:00,460 --> 01:31:03,300 the first iteration y will be 0 and X is 1 so here we have 1 and 0 then we'll get 3768 01:31:03,300 --> 01:31:03,310 1 so here we have 1 and 0 then we'll get 3769 01:31:03,310 --> 01:31:05,640 1 so here we have 1 and 0 then we'll get one on one and one and two you got the 3770 01:31:05,640 --> 01:31:05,650 one on one and one and two you got the 3771 01:31:05,650 --> 01:31:16,140 one on one and one and two you got the point so this is all about nested loops 3772 01:31:16,140 --> 01:31:16,150 3773 01:31:16,150 --> 01:31:18,490 so you have learned how to use four 3774 01:31:18,490 --> 01:31:18,500 so you have learned how to use four 3775 01:31:18,500 --> 01:31:21,220 so you have learned how to use four loops to repeat one or more statements 3776 01:31:21,220 --> 01:31:21,230 loops to repeat one or more statements 3777 01:31:21,230 --> 01:31:23,200 loops to repeat one or more statements in your programs now let's dive deeper 3778 01:31:23,200 --> 01:31:23,210 in your programs now let's dive deeper 3779 01:31:23,210 --> 01:31:26,160 in your programs now let's dive deeper and see what this range function returns 3780 01:31:26,160 --> 01:31:26,170 and see what this range function returns 3781 01:31:26,170 --> 01:31:30,400 and see what this range function returns so earlier you learn about the built in 3782 01:31:30,400 --> 01:31:30,410 so earlier you learn about the built in 3783 01:31:30,410 --> 01:31:33,160 so earlier you learn about the built in type function with this function we can 3784 01:31:33,160 --> 01:31:33,170 type function with this function we can 3785 01:31:33,170 --> 01:31:35,590 type function with this function we can get the type of an object so if I pass 3786 01:31:35,590 --> 01:31:35,600 get the type of an object so if I pass 3787 01:31:35,600 --> 01:31:39,880 get the type of an object so if I pass five here and run this program this is 3788 01:31:39,880 --> 01:31:39,890 five here and run this program this is 3789 01:31:39,890 --> 01:31:41,950 five here and run this program this is what we get so the type of this number 3790 01:31:41,950 --> 01:31:41,960 what we get so the type of this number 3791 01:31:41,960 --> 01:31:46,150 what we get so the type of this number or this object is int or integer now 3792 01:31:46,150 --> 01:31:46,160 or this object is int or integer now 3793 01:31:46,160 --> 01:31:49,000 or this object is int or integer now let's look at the type of the value that 3794 01:31:49,000 --> 01:31:49,010 let's look at the type of the value that 3795 01:31:49,010 --> 01:31:52,270 let's look at the type of the value that we get from the range function so as an 3796 01:31:52,270 --> 01:31:52,280 we get from the range function so as an 3797 01:31:52,280 --> 01:31:56,590 we get from the range function so as an argument we pass range of a number let's 3798 01:31:56,590 --> 01:31:56,600 argument we pass range of a number let's 3799 01:31:56,600 --> 01:31:59,500 argument we pass range of a number let's run this program so this range function 3800 01:31:59,500 --> 01:31:59,510 run this program so this range function 3801 01:31:59,510 --> 01:32:04,150 run this program so this range function returns an object of type range so in 3802 01:32:04,150 --> 01:32:04,160 returns an object of type range so in 3803 01:32:04,160 --> 01:32:06,520 returns an object of type range so in Python we have primitive types like 3804 01:32:06,520 --> 01:32:06,530 Python we have primitive types like 3805 01:32:06,530 --> 01:32:09,670 Python we have primitive types like numbers strings and boolean but we also 3806 01:32:09,670 --> 01:32:09,680 numbers strings and boolean but we also 3807 01:32:09,680 --> 01:32:12,580 numbers strings and boolean but we also have complex types range is an example 3808 01:32:12,580 --> 01:32:12,590 have complex types range is an example 3809 01:32:12,590 --> 01:32:14,890 have complex types range is an example one of those complex types throughout 3810 01:32:14,890 --> 01:32:14,900 one of those complex types throughout 3811 01:32:14,900 --> 01:32:16,150 one of those complex types throughout this course you're going to learn about 3812 01:32:16,150 --> 01:32:16,160 this course you're going to learn about 3813 01:32:16,160 --> 01:32:19,930 this course you're going to learn about a lot of other complex types now what is 3814 01:32:19,930 --> 01:32:19,940 a lot of other complex types now what is 3815 01:32:19,940 --> 01:32:22,000 a lot of other complex types now what is interesting about this range object is 3816 01:32:22,000 --> 01:32:22,010 interesting about this range object is 3817 01:32:22,010 --> 01:32:25,660 interesting about this range object is that it's iterable which means we can 3818 01:32:25,660 --> 01:32:25,670 that it's iterable which means we can 3819 01:32:25,670 --> 01:32:28,500 that it's iterable which means we can iterate over it or use it in a for loop 3820 01:32:28,500 --> 01:32:28,510 iterate over it or use it in a for loop 3821 01:32:28,510 --> 01:32:33,480 iterate over it or use it in a for loop that is why we can write code like this 3822 01:32:33,480 --> 01:32:33,490 that is why we can write code like this 3823 01:32:33,490 --> 01:32:37,150 that is why we can write code like this so this range function returns a range 3824 01:32:37,150 --> 01:32:37,160 so this range function returns a range 3825 01:32:37,160 --> 01:32:39,850 so this range function returns a range object which is interval which means we 3826 01:32:39,850 --> 01:32:39,860 object which is interval which means we 3827 01:32:39,860 --> 01:32:43,150 object which is interval which means we can iterate over it in each iteration X 3828 01:32:43,150 --> 01:32:43,160 can iterate over it in each iteration X 3829 01:32:43,160 --> 01:32:46,570 can iterate over it in each iteration X will have a different value now range 3830 01:32:46,570 --> 01:32:46,580 will have a different value now range 3831 01:32:46,580 --> 01:32:48,580 will have a different value now range objects are not the only iterable 3832 01:32:48,580 --> 01:32:48,590 objects are not the only iterable 3833 01:32:48,590 --> 01:32:50,950 objects are not the only iterable objects in Python strings are also 3834 01:32:50,950 --> 01:32:50,960 objects in Python strings are also 3835 01:32:50,960 --> 01:32:55,200 objects in Python strings are also iterable so here we can add a string 3836 01:32:55,200 --> 01:32:55,210 iterable so here we can add a string 3837 01:32:55,210 --> 01:33:00,220 iterable so here we can add a string like Python now in each iteration X will 3838 01:33:00,220 --> 01:33:00,230 like Python now in each iteration X will 3839 01:33:00,230 --> 01:33:03,400 like Python now in each iteration X will hold one character in this string let me 3840 01:33:03,400 --> 01:33:03,410 hold one character in this string let me 3841 01:33:03,410 --> 01:33:04,480 hold one character in this string let me show you so print 3842 01:33:04,480 --> 01:33:04,490 show you so print 3843 01:33:04,490 --> 01:33:07,810 show you so print Peg's and I'm gonna delete these two 3844 01:33:07,810 --> 01:33:07,820 Peg's and I'm gonna delete these two 3845 01:33:07,820 --> 01:33:12,370 Peg's and I'm gonna delete these two lines here let's run this program so in 3846 01:33:12,370 --> 01:33:12,380 lines here let's run this program so in 3847 01:33:12,380 --> 01:33:14,530 lines here let's run this program so in each iteration we'll get one character 3848 01:33:14,530 --> 01:33:14,540 each iteration we'll get one character 3849 01:33:14,540 --> 01:33:18,100 each iteration we'll get one character and print it we have another complex 3850 01:33:18,100 --> 01:33:18,110 and print it we have another complex 3851 01:33:18,110 --> 01:33:21,160 and print it we have another complex type called list which we use to store a 3852 01:33:21,160 --> 01:33:21,170 type called list which we use to store a 3853 01:33:21,170 --> 01:33:24,040 type called list which we use to store a list of objects so we add square 3854 01:33:24,040 --> 01:33:24,050 list of objects so we add square 3855 01:33:24,050 --> 01:33:26,890 list of objects so we add square brackets this indicates a list 3856 01:33:26,890 --> 01:33:26,900 brackets this indicates a list 3857 01:33:26,900 --> 01:33:28,840 brackets this indicates a list now we can add a list of numbers or a 3858 01:33:28,840 --> 01:33:28,850 now we can add a list of numbers or a 3859 01:33:28,850 --> 01:33:31,570 now we can add a list of numbers or a list of strings like a list of names you 3860 01:33:31,570 --> 01:33:31,580 list of strings like a list of names you 3861 01:33:31,580 --> 01:33:33,100 list of strings like a list of names you will learn about lists later in the 3862 01:33:33,100 --> 01:33:33,110 will learn about lists later in the 3863 01:33:33,110 --> 01:33:36,100 will learn about lists later in the course so let's run this one more time 3864 01:33:36,100 --> 01:33:36,110 course so let's run this one more time 3865 01:33:36,110 --> 01:33:39,520 course so let's run this one more time as we can see we can iterate over lists 3866 01:33:39,520 --> 01:33:39,530 as we can see we can iterate over lists 3867 01:33:39,530 --> 01:33:42,490 as we can see we can iterate over lists in each iteration we'll get one object 3868 01:33:42,490 --> 01:33:42,500 in each iteration we'll get one object 3869 01:33:42,500 --> 01:33:45,400 in each iteration we'll get one object in this list now later in the course I 3870 01:33:45,400 --> 01:33:45,410 in this list now later in the course I 3871 01:33:45,410 --> 01:33:47,200 in this list now later in the course I will show you how to create your own 3872 01:33:47,200 --> 01:33:47,210 will show you how to create your own 3873 01:33:47,210 --> 01:33:50,590 will show you how to create your own custom objects that are eatable for 3874 01:33:50,590 --> 01:33:50,600 custom objects that are eatable for 3875 01:33:50,600 --> 01:33:52,210 custom objects that are eatable for example you will learn how to write code 3876 01:33:52,210 --> 01:33:52,220 example you will learn how to write code 3877 01:33:52,220 --> 01:33:57,600 example you will learn how to write code like this for item in shopping cart 3878 01:33:57,600 --> 01:33:57,610 like this for item in shopping cart 3879 01:33:57,610 --> 01:34:01,600 like this for item in shopping cart print item so shopping cart is going to 3880 01:34:01,600 --> 01:34:01,610 print item so shopping cart is going to 3881 01:34:01,610 --> 01:34:03,280 print item so shopping cart is going to be custom object that you will create 3882 01:34:03,280 --> 01:34:03,290 be custom object that you will create 3883 01:34:03,290 --> 01:34:05,470 be custom object that you will create it's not going to be an integer or a 3884 01:34:05,470 --> 01:34:05,480 it's not going to be an integer or a 3885 01:34:05,480 --> 01:34:07,930 it's not going to be an integer or a string or boolean it's a custom object 3886 01:34:07,930 --> 01:34:07,940 string or boolean it's a custom object 3887 01:34:07,940 --> 01:34:10,600 string or boolean it's a custom object it has a different structure and we'll 3888 01:34:10,600 --> 01:34:10,610 it has a different structure and we'll 3889 01:34:10,610 --> 01:34:13,030 it has a different structure and we'll make it eatable so we can use it in a 3890 01:34:13,030 --> 01:34:13,040 make it eatable so we can use it in a 3891 01:34:13,040 --> 01:34:15,220 make it eatable so we can use it in a for loop and in each iteration we can 3892 01:34:15,220 --> 01:34:15,230 for loop and in each iteration we can 3893 01:34:15,230 --> 01:34:17,320 for loop and in each iteration we can get one item in the shopping cart and 3894 01:34:17,320 --> 01:34:17,330 get one item in the shopping cart and 3895 01:34:17,330 --> 01:34:26,190 get one item in the shopping cart and print it on a terminal 3896 01:34:26,190 --> 01:34:26,200 3897 01:34:26,200 --> 01:34:28,420 so you have learned that we use for 3898 01:34:28,420 --> 01:34:28,430 so you have learned that we use for 3899 01:34:28,430 --> 01:34:31,390 so you have learned that we use for loops to iterate over each ruble objects 3900 01:34:31,390 --> 01:34:31,400 loops to iterate over each ruble objects 3901 01:34:31,400 --> 01:34:34,030 loops to iterate over each ruble objects in Python we have another kind of loop 3902 01:34:34,030 --> 01:34:34,040 in Python we have another kind of loop 3903 01:34:34,040 --> 01:34:36,580 in Python we have another kind of loop that is a while loop and we use that to 3904 01:34:36,580 --> 01:34:36,590 that is a while loop and we use that to 3905 01:34:36,590 --> 01:34:38,770 that is a while loop and we use that to repeat something as long as a condition 3906 01:34:38,770 --> 01:34:38,780 repeat something as long as a condition 3907 01:34:38,780 --> 01:34:41,590 repeat something as long as a condition is true here's an example so let's 3908 01:34:41,590 --> 01:34:41,600 is true here's an example so let's 3909 01:34:41,600 --> 01:34:44,920 is true here's an example so let's define a variable number and set it to a 3910 01:34:44,920 --> 01:34:44,930 define a variable number and set it to a 3911 01:34:44,930 --> 01:34:48,520 define a variable number and set it to a hundred now we use while and here we add 3912 01:34:48,520 --> 01:34:48,530 hundred now we use while and here we add 3913 01:34:48,530 --> 01:34:51,940 hundred now we use while and here we add a condition as long as number is greater 3914 01:34:51,940 --> 01:34:51,950 a condition as long as number is greater 3915 01:34:51,950 --> 01:34:55,630 a condition as long as number is greater than zero we add a colon once again we 3916 01:34:55,630 --> 01:34:55,640 than zero we add a colon once again we 3917 01:34:55,640 --> 01:34:58,720 than zero we add a colon once again we have indentation so we can repeat one or 3918 01:34:58,720 --> 01:34:58,730 have indentation so we can repeat one or 3919 01:34:58,730 --> 01:35:01,660 have indentation so we can repeat one or more statements we can print this number 3920 01:35:01,660 --> 01:35:01,670 more statements we can print this number 3921 01:35:01,670 --> 01:35:05,500 more statements we can print this number and then we can divide it by half so 3922 01:35:05,500 --> 01:35:05,510 and then we can divide it by half so 3923 01:35:05,510 --> 01:35:09,880 and then we can divide it by half so number equals number use the integer 3924 01:35:09,880 --> 01:35:09,890 number equals number use the integer 3925 01:35:09,890 --> 01:35:13,420 number equals number use the integer division to divide it by two or we can 3926 01:35:13,420 --> 01:35:13,430 division to divide it by two or we can 3927 01:35:13,430 --> 01:35:15,700 division to divide it by two or we can use the augment and assignment operator 3928 01:35:15,700 --> 01:35:15,710 use the augment and assignment operator 3929 01:35:15,710 --> 01:35:21,670 use the augment and assignment operator to shorten this code like this now let's 3930 01:35:21,670 --> 01:35:21,680 to shorten this code like this now let's 3931 01:35:21,680 --> 01:35:24,610 to shorten this code like this now let's run this program so here is what we get 3932 01:35:24,610 --> 01:35:24,620 run this program so here is what we get 3933 01:35:24,620 --> 01:35:27,400 run this program so here is what we get initially our number is a hundred we 3934 01:35:27,400 --> 01:35:27,410 initially our number is a hundred we 3935 01:35:27,410 --> 01:35:30,670 initially our number is a hundred we divide it by half we get 50 then 25 and 3936 01:35:30,670 --> 01:35:30,680 divide it by half we get 50 then 25 and 3937 01:35:30,680 --> 01:35:33,580 divide it by half we get 50 then 25 and so on so as you can see in this example 3938 01:35:33,580 --> 01:35:33,590 so on so as you can see in this example 3939 01:35:33,590 --> 01:35:36,310 so on so as you can see in this example we are not iterating over an iterable 3940 01:35:36,310 --> 01:35:36,320 we are not iterating over an iterable 3941 01:35:36,320 --> 01:35:38,860 we are not iterating over an iterable like a range object or a string or a 3942 01:35:38,860 --> 01:35:38,870 like a range object or a string or a 3943 01:35:38,870 --> 01:35:41,680 like a range object or a string or a list we are evaluating a condition and 3944 01:35:41,680 --> 01:35:41,690 list we are evaluating a condition and 3945 01:35:41,690 --> 01:35:45,850 list we are evaluating a condition and repeating a task let me show you a real 3946 01:35:45,850 --> 01:35:45,860 repeating a task let me show you a real 3947 01:35:45,860 --> 01:35:48,220 repeating a task let me show you a real world example of a while loop in this 3948 01:35:48,220 --> 01:35:48,230 world example of a while loop in this 3949 01:35:48,230 --> 01:35:50,800 world example of a while loop in this interactive shell Python is waiting for 3950 01:35:50,800 --> 01:35:50,810 interactive shell Python is waiting for 3951 01:35:50,810 --> 01:35:52,750 interactive shell Python is waiting for an input we can type something like 2 3952 01:35:52,750 --> 01:35:52,760 an input we can type something like 2 3953 01:35:52,760 --> 01:35:55,630 an input we can type something like 2 plus 2 it will evaluate it and ask for 3954 01:35:55,630 --> 01:35:55,640 plus 2 it will evaluate it and ask for 3955 01:35:55,640 --> 01:35:57,790 plus 2 it will evaluate it and ask for the next input we can add another 3956 01:35:57,790 --> 01:35:57,800 the next input we can add another 3957 01:35:57,800 --> 01:36:00,940 the next input we can add another expression like 10 is greater than 2 so 3958 01:36:00,940 --> 01:36:00,950 expression like 10 is greater than 2 so 3959 01:36:00,950 --> 01:36:04,350 expression like 10 is greater than 2 so these steps will continue until we press 3960 01:36:04,350 --> 01:36:04,360 these steps will continue until we press 3961 01:36:04,360 --> 01:36:07,780 these steps will continue until we press control-d so behind the scene we have a 3962 01:36:07,780 --> 01:36:07,790 control-d so behind the scene we have a 3963 01:36:07,790 --> 01:36:10,120 control-d so behind the scene we have a while loop that continuous execution 3964 01:36:10,120 --> 01:36:10,130 while loop that continuous execution 3965 01:36:10,130 --> 01:36:12,640 while loop that continuous execution until we press control-d 3966 01:36:12,640 --> 01:36:12,650 until we press control-d 3967 01:36:12,650 --> 01:36:15,070 until we press control-d that is the condition that causes the 3968 01:36:15,070 --> 01:36:15,080 that is the condition that causes the 3969 01:36:15,080 --> 01:36:17,350 that is the condition that causes the while loop to terminate let me show you 3970 01:36:17,350 --> 01:36:17,360 while loop to terminate let me show you 3971 01:36:17,360 --> 01:36:18,820 while loop to terminate let me show you how to build something like this in 3972 01:36:18,820 --> 01:36:18,830 how to build something like this in 3973 01:36:18,830 --> 01:36:23,400 how to build something like this in Python so let's define a variable 3974 01:36:23,400 --> 01:36:23,410 Python so let's define a variable 3975 01:36:23,410 --> 01:36:27,270 Python so let's define a variable and set it to an empty string now here 3976 01:36:27,270 --> 01:36:27,280 and set it to an empty string now here 3977 01:36:27,280 --> 01:36:29,610 and set it to an empty string now here we need a while loop we want this while 3978 01:36:29,610 --> 01:36:29,620 we need a while loop we want this while 3979 01:36:29,620 --> 01:36:32,400 we need a while loop we want this while loop to execute as long as command does 3980 01:36:32,400 --> 01:36:32,410 loop to execute as long as command does 3981 01:36:32,410 --> 01:36:36,360 loop to execute as long as command does not equal to quit so command does not 3982 01:36:36,360 --> 01:36:36,370 not equal to quit so command does not 3983 01:36:36,370 --> 01:36:41,610 not equal to quit so command does not equal to quit : in this loop we want to 3984 01:36:41,610 --> 01:36:41,620 equal to quit : in this loop we want to 3985 01:36:41,620 --> 01:36:44,670 equal to quit : in this loop we want to continuously get input from the user so 3986 01:36:44,670 --> 01:36:44,680 continuously get input from the user so 3987 01:36:44,680 --> 01:36:47,910 continuously get input from the user so we use the built-in input function we 3988 01:36:47,910 --> 01:36:47,920 we use the built-in input function we 3989 01:36:47,920 --> 01:36:51,390 we use the built-in input function we add a label like this get the result and 3990 01:36:51,390 --> 01:36:51,400 add a label like this get the result and 3991 01:36:51,400 --> 01:36:55,650 add a label like this get the result and store it in the command variable now at 3992 01:36:55,650 --> 01:36:55,660 store it in the command variable now at 3993 01:36:55,660 --> 01:36:57,660 store it in the command variable now at this point python interactive shell will 3994 01:36:57,660 --> 01:36:57,670 this point python interactive shell will 3995 01:36:57,670 --> 01:36:59,850 this point python interactive shell will evaluate this command we are not going 3996 01:36:59,850 --> 01:36:59,860 evaluate this command we are not going 3997 01:36:59,860 --> 01:37:01,050 evaluate this command we are not going to do that in this lecture because 3998 01:37:01,050 --> 01:37:01,060 to do that in this lecture because 3999 01:37:01,060 --> 01:37:03,870 to do that in this lecture because that's way too complex for simplicity we 4000 01:37:03,870 --> 01:37:03,880 that's way too complex for simplicity we 4001 01:37:03,880 --> 01:37:06,450 that's way too complex for simplicity we can just echo back what the user entered 4002 01:37:06,450 --> 01:37:06,460 can just echo back what the user entered 4003 01:37:06,460 --> 01:37:11,070 can just echo back what the user entered so print echo and as the second argument 4004 01:37:11,070 --> 01:37:11,080 so print echo and as the second argument 4005 01:37:11,080 --> 01:37:14,730 so print echo and as the second argument we pass this command so this is our 4006 01:37:14,730 --> 01:37:14,740 we pass this command so this is our 4007 01:37:14,740 --> 01:37:17,700 we pass this command so this is our while loop it will execute until we type 4008 01:37:17,700 --> 01:37:17,710 while loop it will execute until we type 4009 01:37:17,710 --> 01:37:21,090 while loop it will execute until we type quit now as I told you before don't run 4010 01:37:21,090 --> 01:37:21,100 quit now as I told you before don't run 4011 01:37:21,100 --> 01:37:22,680 quit now as I told you before don't run this program using the code runner 4012 01:37:22,680 --> 01:37:22,690 this program using the code runner 4013 01:37:22,690 --> 01:37:25,140 this program using the code runner extension because by default it will run 4014 01:37:25,140 --> 01:37:25,150 extension because by default it will run 4015 01:37:25,150 --> 01:37:27,030 extension because by default it will run your program in the output window which 4016 01:37:27,030 --> 01:37:27,040 your program in the output window which 4017 01:37:27,040 --> 01:37:29,940 your program in the output window which is read-only so open up a terminal using 4018 01:37:29,940 --> 01:37:29,950 is read-only so open up a terminal using 4019 01:37:29,950 --> 01:37:33,810 is read-only so open up a terminal using ctrl + back take and run Python or 4020 01:37:33,810 --> 01:37:33,820 ctrl + back take and run Python or 4021 01:37:33,820 --> 01:37:37,770 ctrl + back take and run Python or Python 3 AB dot pi so here's our command 4022 01:37:37,770 --> 01:37:37,780 Python 3 AB dot pi so here's our command 4023 01:37:37,780 --> 01:37:41,210 Python 3 AB dot pi so here's our command prompt let's type 2 + 2 it it goes back 4024 01:37:41,210 --> 01:37:41,220 prompt let's type 2 + 2 it it goes back 4025 01:37:41,220 --> 01:37:45,900 prompt let's type 2 + 2 it it goes back let's type 3 times 2 there you go if we 4026 01:37:45,900 --> 01:37:45,910 let's type 3 times 2 there you go if we 4027 01:37:45,910 --> 01:37:49,170 let's type 3 times 2 there you go if we type quit our program terminates now 4028 01:37:49,170 --> 01:37:49,180 type quit our program terminates now 4029 01:37:49,180 --> 01:37:51,690 type quit our program terminates now let's try it one more time what if we 4030 01:37:51,690 --> 01:37:51,700 let's try it one more time what if we 4031 01:37:51,700 --> 01:37:55,200 let's try it one more time what if we type quit an upper case the program 4032 01:37:55,200 --> 01:37:55,210 type quit an upper case the program 4033 01:37:55,210 --> 01:37:57,180 type quit an upper case the program doesn't terminate because as you learned 4034 01:37:57,180 --> 01:37:57,190 doesn't terminate because as you learned 4035 01:37:57,190 --> 01:37:59,160 doesn't terminate because as you learned before lower case and upper case 4036 01:37:59,160 --> 01:37:59,170 before lower case and upper case 4037 01:37:59,170 --> 01:38:01,110 before lower case and upper case characters have different numeric 4038 01:38:01,110 --> 01:38:01,120 characters have different numeric 4039 01:38:01,120 --> 01:38:04,200 characters have different numeric representations so quit in lower case is 4040 01:38:04,200 --> 01:38:04,210 representations so quit in lower case is 4041 01:38:04,210 --> 01:38:07,980 representations so quit in lower case is different from quit in upper case now to 4042 01:38:07,980 --> 01:38:07,990 different from quit in upper case now to 4043 01:38:07,990 --> 01:38:09,000 different from quit in upper case now to solve this problem 4044 01:38:09,000 --> 01:38:09,010 solve this problem 4045 01:38:09,010 --> 01:38:11,370 solve this problem an amateur programmer may do something 4046 01:38:11,370 --> 01:38:11,380 an amateur programmer may do something 4047 01:38:11,380 --> 01:38:16,880 an amateur programmer may do something like this and command does not equal to 4048 01:38:16,880 --> 01:38:16,890 like this and command does not equal to 4049 01:38:16,890 --> 01:38:20,910 like this and command does not equal to capital quit so while command does not 4050 01:38:20,910 --> 01:38:20,920 capital quit so while command does not 4051 01:38:20,920 --> 01:38:24,660 capital quit so while command does not equal quit in lower case and quit in 4052 01:38:24,660 --> 01:38:24,670 equal quit in lower case and quit in 4053 01:38:24,670 --> 01:38:26,730 equal quit in lower case and quit in upper case continue getting input from 4054 01:38:26,730 --> 01:38:26,740 upper case continue getting input from 4055 01:38:26,740 --> 01:38:27,330 upper case continue getting input from the user 4056 01:38:27,330 --> 01:38:27,340 the user 4057 01:38:27,340 --> 01:38:29,730 the user let's run this program in terminal and 4058 01:38:29,730 --> 01:38:29,740 let's run this program in terminal and 4059 01:38:29,740 --> 01:38:32,430 let's run this program in terminal and see what happens so one more time 4060 01:38:32,430 --> 01:38:32,440 see what happens so one more time 4061 01:38:32,440 --> 01:38:36,150 see what happens so one more time Python after pie which I've quit 4062 01:38:36,150 --> 01:38:36,160 Python after pie which I've quit 4063 01:38:36,160 --> 01:38:37,390 Python after pie which I've quit beautiful it 4064 01:38:37,390 --> 01:38:37,400 beautiful it 4065 01:38:37,400 --> 01:38:39,880 beautiful it works we type quit an uppercase that 4066 01:38:39,880 --> 01:38:39,890 works we type quit an uppercase that 4067 01:38:39,890 --> 01:38:42,580 works we type quit an uppercase that would work too but what if I type quit 4068 01:38:42,580 --> 01:38:42,590 would work too but what if I type quit 4069 01:38:42,590 --> 01:38:46,290 would work too but what if I type quit with an uppercase Q and lowercase uit 4070 01:38:46,290 --> 01:38:46,300 with an uppercase Q and lowercase uit 4071 01:38:46,300 --> 01:38:49,990 with an uppercase Q and lowercase uit our program doesn't terminate so this is 4072 01:38:49,990 --> 01:38:50,000 our program doesn't terminate so this is 4073 01:38:50,000 --> 01:38:52,479 our program doesn't terminate so this is a poor way of checking for the quit 4074 01:38:52,479 --> 01:38:52,489 a poor way of checking for the quit 4075 01:38:52,489 --> 01:38:55,300 a poor way of checking for the quit command what is a better way let me show 4076 01:38:55,300 --> 01:38:55,310 command what is a better way let me show 4077 01:38:55,310 --> 01:38:58,479 command what is a better way let me show you so we don't need this and operator 4078 01:38:58,479 --> 01:38:58,489 you so we don't need this and operator 4079 01:38:58,489 --> 01:39:02,290 you so we don't need this and operator here instead because command is a string 4080 01:39:02,290 --> 01:39:02,300 here instead because command is a string 4081 01:39:02,300 --> 01:39:06,700 here instead because command is a string we can call the lower method so whatever 4082 01:39:06,700 --> 01:39:06,710 we can call the lower method so whatever 4083 01:39:06,710 --> 01:39:09,189 we can call the lower method so whatever the user types in first we'll convert it 4084 01:39:09,189 --> 01:39:09,199 the user types in first we'll convert it 4085 01:39:09,199 --> 01:39:11,919 the user types in first we'll convert it to lowercase and then compare it with 4086 01:39:11,919 --> 01:39:11,929 to lowercase and then compare it with 4087 01:39:11,929 --> 01:39:15,220 to lowercase and then compare it with quit in lower case with this change it 4088 01:39:15,220 --> 01:39:15,230 quit in lower case with this change it 4089 01:39:15,230 --> 01:39:17,410 quit in lower case with this change it doesn't matter how the user types the 4090 01:39:17,410 --> 01:39:17,420 doesn't matter how the user types the 4091 01:39:17,420 --> 01:39:19,660 doesn't matter how the user types the word quit will always terminate the 4092 01:39:19,660 --> 01:39:19,670 word quit will always terminate the 4093 01:39:19,670 --> 01:39:27,229 word quit will always terminate the program 4094 01:39:27,229 --> 01:39:27,239 4095 01:39:27,239 --> 01:39:29,520 now the last thing I want to discuss in 4096 01:39:29,520 --> 01:39:29,530 now the last thing I want to discuss in 4097 01:39:29,530 --> 01:39:31,830 now the last thing I want to discuss in this section is the concept of infinite 4098 01:39:31,830 --> 01:39:31,840 this section is the concept of infinite 4099 01:39:31,840 --> 01:39:34,739 this section is the concept of infinite loops an infinite loop is a loop that 4100 01:39:34,739 --> 01:39:34,749 loops an infinite loop is a loop that 4101 01:39:34,749 --> 01:39:38,310 loops an infinite loop is a loop that runs forever so if I change this 4102 01:39:38,310 --> 01:39:38,320 runs forever so if I change this 4103 01:39:38,320 --> 01:39:42,120 runs forever so if I change this condition to true because true is always 4104 01:39:42,120 --> 01:39:42,130 condition to true because true is always 4105 01:39:42,130 --> 01:39:45,810 condition to true because true is always true this while loop will run forever so 4106 01:39:45,810 --> 01:39:45,820 true this while loop will run forever so 4107 01:39:45,820 --> 01:39:47,640 true this while loop will run forever so to jump out of this we need a break 4108 01:39:47,640 --> 01:39:47,650 to jump out of this we need a break 4109 01:39:47,650 --> 01:39:50,250 to jump out of this we need a break statement so after we get the input from 4110 01:39:50,250 --> 01:39:50,260 statement so after we get the input from 4111 01:39:50,260 --> 01:39:54,390 statement so after we get the input from the user we can get the command convert 4112 01:39:54,390 --> 01:39:54,400 the user we can get the command convert 4113 01:39:54,400 --> 01:39:57,629 the user we can get the command convert it to lowercase and see if it equals to 4114 01:39:57,629 --> 01:39:57,639 it to lowercase and see if it equals to 4115 01:39:57,639 --> 01:40:01,459 it to lowercase and see if it equals to quit if that's the case we want to break 4116 01:40:01,459 --> 01:40:01,469 quit if that's the case we want to break 4117 01:40:01,469 --> 01:40:04,080 quit if that's the case we want to break now with this change we no longer need 4118 01:40:04,080 --> 01:40:04,090 now with this change we no longer need 4119 01:40:04,090 --> 01:40:06,649 now with this change we no longer need to initialize command to an empty string 4120 01:40:06,649 --> 01:40:06,659 to initialize command to an empty string 4121 01:40:06,659 --> 01:40:09,390 to initialize command to an empty string previously we needed this because we had 4122 01:40:09,390 --> 01:40:09,400 previously we needed this because we had 4123 01:40:09,400 --> 01:40:12,660 previously we needed this because we had a wild statement like this while command 4124 01:40:12,660 --> 01:40:12,670 a wild statement like this while command 4125 01:40:12,670 --> 01:40:17,009 a wild statement like this while command does not equal quit so we had to define 4126 01:40:17,009 --> 01:40:17,019 does not equal quit so we had to define 4127 01:40:17,019 --> 01:40:19,290 does not equal quit so we had to define this command variable and that's why we 4128 01:40:19,290 --> 01:40:19,300 this command variable and that's why we 4129 01:40:19,300 --> 01:40:21,540 this command variable and that's why we have set it to an empty string without 4130 01:40:21,540 --> 01:40:21,550 have set it to an empty string without 4131 01:40:21,550 --> 01:40:23,969 have set it to an empty string without this line when Python interpreter 4132 01:40:23,969 --> 01:40:23,979 this line when Python interpreter 4133 01:40:23,979 --> 01:40:25,919 this line when Python interpreter tries to execute this code it doesn't 4134 01:40:25,919 --> 01:40:25,929 tries to execute this code it doesn't 4135 01:40:25,929 --> 01:40:29,399 tries to execute this code it doesn't know what command is so now that we have 4136 01:40:29,399 --> 01:40:29,409 know what command is so now that we have 4137 01:40:29,409 --> 01:40:31,500 know what command is so now that we have an infinite loop we no longer need to 4138 01:40:31,500 --> 01:40:31,510 an infinite loop we no longer need to 4139 01:40:31,510 --> 01:40:33,509 an infinite loop we no longer need to define command and set it to an empty 4140 01:40:33,509 --> 01:40:33,519 define command and set it to an empty 4141 01:40:33,519 --> 01:40:36,450 define command and set it to an empty string so in terms of functionality this 4142 01:40:36,450 --> 01:40:36,460 string so in terms of functionality this 4143 01:40:36,460 --> 01:40:38,279 string so in terms of functionality this program is exactly the same as the 4144 01:40:38,279 --> 01:40:38,289 program is exactly the same as the 4145 01:40:38,289 --> 01:40:39,930 program is exactly the same as the program we wrote in the last lecture 4146 01:40:39,930 --> 01:40:39,940 program we wrote in the last lecture 4147 01:40:39,940 --> 01:40:42,479 program we wrote in the last lecture just be aware of these infinite loops 4148 01:40:42,479 --> 01:40:42,489 just be aware of these infinite loops 4149 01:40:42,489 --> 01:40:44,640 just be aware of these infinite loops because they run forever you should 4150 01:40:44,640 --> 01:40:44,650 because they run forever you should 4151 01:40:44,650 --> 01:40:48,120 because they run forever you should always have a way to jump out of them 4152 01:40:48,120 --> 01:40:48,130 always have a way to jump out of them 4153 01:40:48,130 --> 01:40:50,160 always have a way to jump out of them otherwise your program will run forever 4154 01:40:50,160 --> 01:40:50,170 otherwise your program will run forever 4155 01:40:50,170 --> 01:40:52,500 otherwise your program will run forever and this can sometimes cause issues 4156 01:40:52,500 --> 01:40:52,510 and this can sometimes cause issues 4157 01:40:52,510 --> 01:40:54,750 and this can sometimes cause issues because if you're executing operations 4158 01:40:54,750 --> 01:40:54,760 because if you're executing operations 4159 01:40:54,760 --> 01:40:57,120 because if you're executing operations that consume memory at some point your 4160 01:40:57,120 --> 01:40:57,130 that consume memory at some point your 4161 01:40:57,130 --> 01:41:05,640 that consume memory at some point your program may run out of memory and crash 4162 01:41:05,640 --> 01:41:05,650 4163 01:41:05,650 --> 01:41:07,369 [Music] 4164 01:41:07,369 --> 01:41:07,379 [Music] 4165 01:41:07,379 --> 01:41:10,500 [Music] alright time for an exercise I want you 4166 01:41:10,500 --> 01:41:10,510 alright time for an exercise I want you 4167 01:41:10,510 --> 01:41:13,079 alright time for an exercise I want you to write a program to display the even 4168 01:41:13,079 --> 01:41:13,089 to write a program to display the even 4169 01:41:13,089 --> 01:41:16,259 to write a program to display the even numbers between 1 to 10 so when you run 4170 01:41:16,259 --> 01:41:16,269 numbers between 1 to 10 so when you run 4171 01:41:16,269 --> 01:41:19,049 numbers between 1 to 10 so when you run this program you should see 2 4 6 and 8 4172 01:41:19,049 --> 01:41:19,059 this program you should see 2 4 6 and 8 4173 01:41:19,059 --> 01:41:21,540 this program you should see 2 4 6 and 8 and after these I want you to print this 4174 01:41:21,540 --> 01:41:21,550 and after these I want you to print this 4175 01:41:21,550 --> 01:41:25,859 and after these I want you to print this message we have 4 even numbers now here 4176 01:41:25,859 --> 01:41:25,869 message we have 4 even numbers now here 4177 01:41:25,869 --> 01:41:27,569 message we have 4 even numbers now here is a quick hint before you get started 4178 01:41:27,569 --> 01:41:27,579 is a quick hint before you get started 4179 01:41:27,579 --> 01:41:30,089 is a quick hint before you get started you should call the range function with 4180 01:41:30,089 --> 01:41:30,099 you should call the range function with 4181 01:41:30,099 --> 01:41:32,729 you should call the range function with 1 and 10 do not use this third argument 4182 01:41:32,729 --> 01:41:32,739 1 and 10 do not use this third argument 4183 01:41:32,739 --> 01:41:35,669 1 and 10 do not use this third argument which is called step so basically I want 4184 01:41:35,669 --> 01:41:35,679 which is called step so basically I want 4185 01:41:35,679 --> 01:41:37,859 which is called step so basically I want you to iterate over all the numbers we 4186 01:41:37,859 --> 01:41:37,869 you to iterate over all the numbers we 4187 01:41:37,869 --> 01:41:40,529 you to iterate over all the numbers we can want to tab check if each number is 4188 01:41:40,529 --> 01:41:40,539 can want to tab check if each number is 4189 01:41:40,539 --> 01:41:42,959 can want to tab check if each number is an even number and then print it on the 4190 01:41:42,959 --> 01:41:42,969 an even number and then print it on the 4191 01:41:42,969 --> 01:41:46,169 an even number and then print it on the terminal so pause the video spend two 4192 01:41:46,169 --> 01:41:46,179 terminal so pause the video spend two 4193 01:41:46,179 --> 01:41:47,579 terminal so pause the video spend two minutes on this exercise when you're 4194 01:41:47,579 --> 01:41:47,589 minutes on this exercise when you're 4195 01:41:47,589 --> 01:41:52,770 minutes on this exercise when you're done come back continue watching 4196 01:41:52,770 --> 01:41:52,780 4197 01:41:52,780 --> 01:41:55,419 so it started with a four loop for a 4198 01:41:55,419 --> 01:41:55,429 so it started with a four loop for a 4199 01:41:55,429 --> 01:42:01,209 so it started with a four loop for a number in range one to ten : we check to 4200 01:42:01,209 --> 01:42:01,219 number in range one to ten : we check to 4201 01:42:01,219 --> 01:42:03,669 number in range one to ten : we check to see if the remainder of division of this 4202 01:42:03,669 --> 01:42:03,679 see if the remainder of division of this 4203 01:42:03,679 --> 01:42:05,649 see if the remainder of division of this number by two equals zero 4204 01:42:05,649 --> 01:42:05,659 number by two equals zero 4205 01:42:05,659 --> 01:42:09,490 number by two equals zero so if number modulus two equals zero 4206 01:42:09,490 --> 01:42:09,500 so if number modulus two equals zero 4207 01:42:09,500 --> 01:42:15,009 so if number modulus two equals zero then we print this number 4208 01:42:15,009 --> 01:42:15,019 then we print this number 4209 01:42:15,019 --> 01:42:18,970 then we print this number now let's run this program so we get two 4210 01:42:18,970 --> 01:42:18,980 now let's run this program so we get two 4211 01:42:18,980 --> 01:42:21,580 now let's run this program so we get two four six eight beautiful now to count 4212 01:42:21,580 --> 01:42:21,590 four six eight beautiful now to count 4213 01:42:21,590 --> 01:42:24,279 four six eight beautiful now to count the even numbers we need a separate 4214 01:42:24,279 --> 01:42:24,289 the even numbers we need a separate 4215 01:42:24,289 --> 01:42:26,549 the even numbers we need a separate variable so let's call that count 4216 01:42:26,549 --> 01:42:26,559 variable so let's call that count 4217 01:42:26,559 --> 01:42:29,649 variable so let's call that count initially we set it to zero now in this 4218 01:42:29,649 --> 01:42:29,659 initially we set it to zero now in this 4219 01:42:29,659 --> 01:42:31,660 initially we set it to zero now in this if block every time we find an even 4220 01:42:31,660 --> 01:42:31,670 if block every time we find an even 4221 01:42:31,670 --> 01:42:35,020 if block every time we find an even number we need to increment count so we 4222 01:42:35,020 --> 01:42:35,030 number we need to increment count so we 4223 01:42:35,030 --> 01:42:39,399 number we need to increment count so we set count plus equals one and finally 4224 01:42:39,399 --> 01:42:39,409 set count plus equals one and finally 4225 01:42:39,409 --> 01:42:42,239 set count plus equals one and finally after our for loop we can print a 4226 01:42:42,239 --> 01:42:42,249 after our for loop we can print a 4227 01:42:42,249 --> 01:42:47,529 after our for loop we can print a formatted string we have count even 4228 01:42:47,529 --> 01:42:47,539 formatted string we have count even 4229 01:42:47,539 --> 01:42:52,000 formatted string we have count even numbers let's run the program and here's 4230 01:42:52,000 --> 01:42:52,010 numbers let's run the program and here's 4231 01:42:52,010 --> 01:42:54,729 numbers let's run the program and here's the result so that brings us to the end 4232 01:42:54,729 --> 01:42:54,739 the result so that brings us to the end 4233 01:42:54,739 --> 01:42:56,529 the result so that brings us to the end of this section in the next section 4234 01:42:56,529 --> 01:42:56,539 of this section in the next section 4235 01:42:56,539 --> 01:42:58,270 of this section in the next section you're going to learn how to create your 4236 01:42:58,270 --> 01:42:58,280 you're going to learn how to create your 4237 01:42:58,280 --> 01:43:00,459 you're going to learn how to create your own functions I hope you enjoyed the 4238 01:43:00,459 --> 01:43:00,469 own functions I hope you enjoyed the 4239 01:43:00,469 --> 01:43:02,150 own functions I hope you enjoyed the section and thank you for watching 4240 01:43:02,150 --> 01:43:02,160 section and thank you for watching 4241 01:43:02,160 --> 01:43:14,420 section and thank you for watching [Music] 4242 01:43:14,420 --> 01:43:14,430 4243 01:43:14,430 --> 01:43:17,340 so far you have learned how to use some 4244 01:43:17,340 --> 01:43:17,350 so far you have learned how to use some 4245 01:43:17,350 --> 01:43:19,560 so far you have learned how to use some of the built-in functions in Python such 4246 01:43:19,560 --> 01:43:19,570 of the built-in functions in Python such 4247 01:43:19,570 --> 01:43:23,310 of the built-in functions in Python such as print round and so on in this section 4248 01:43:23,310 --> 01:43:23,320 as print round and so on in this section 4249 01:43:23,320 --> 01:43:25,140 as print round and so on in this section you're gonna learn how to write your own 4250 01:43:25,140 --> 01:43:25,150 you're gonna learn how to write your own 4251 01:43:25,150 --> 01:43:27,900 you're gonna learn how to write your own functions now you might ask but why do 4252 01:43:27,900 --> 01:43:27,910 functions now you might ask but why do 4253 01:43:27,910 --> 01:43:29,400 functions now you might ask but why do you even need to write our own functions 4254 01:43:29,400 --> 01:43:29,410 you even need to write our own functions 4255 01:43:29,410 --> 01:43:32,940 you even need to write our own functions well when you build a real program that 4256 01:43:32,940 --> 01:43:32,950 well when you build a real program that 4257 01:43:32,950 --> 01:43:35,640 well when you build a real program that program is going to consist hundreds or 4258 01:43:35,640 --> 01:43:35,650 program is going to consist hundreds or 4259 01:43:35,650 --> 01:43:38,130 program is going to consist hundreds or thousands of lines of code you shouldn't 4260 01:43:38,130 --> 01:43:38,140 thousands of lines of code you shouldn't 4261 01:43:38,140 --> 01:43:40,200 thousands of lines of code you shouldn't write all that code in one file like we 4262 01:43:40,200 --> 01:43:40,210 write all that code in one file like we 4263 01:43:40,210 --> 01:43:42,330 write all that code in one file like we have done so far you should break that 4264 01:43:42,330 --> 01:43:42,340 have done so far you should break that 4265 01:43:42,340 --> 01:43:45,150 have done so far you should break that code into smaller more maintainable and 4266 01:43:45,150 --> 01:43:45,160 code into smaller more maintainable and 4267 01:43:45,160 --> 01:43:48,420 code into smaller more maintainable and potentially more reusable chunks we 4268 01:43:48,420 --> 01:43:48,430 potentially more reusable chunks we 4269 01:43:48,430 --> 01:43:51,090 potentially more reusable chunks we refer to these chunks as functions so 4270 01:43:51,090 --> 01:43:51,100 refer to these chunks as functions so 4271 01:43:51,100 --> 01:43:52,800 refer to these chunks as functions so let me show you how to create your own 4272 01:43:52,800 --> 01:43:52,810 let me show you how to create your own 4273 01:43:52,810 --> 01:43:56,310 let me show you how to create your own custom functions we start with the DEF 4274 01:43:56,310 --> 01:43:56,320 custom functions we start with the DEF 4275 01:43:56,320 --> 01:43:59,580 custom functions we start with the DEF keyword which is short for define next 4276 01:43:59,580 --> 01:43:59,590 keyword which is short for define next 4277 01:43:59,590 --> 01:44:02,160 keyword which is short for define next we need to give our function and name so 4278 01:44:02,160 --> 01:44:02,170 we need to give our function and name so 4279 01:44:02,170 --> 01:44:04,470 we need to give our function and name so let's call this greet all the best 4280 01:44:04,470 --> 01:44:04,480 let's call this greet all the best 4281 01:44:04,480 --> 01:44:06,120 let's call this greet all the best practices you'll learn about naming your 4282 01:44:06,120 --> 01:44:06,130 practices you'll learn about naming your 4283 01:44:06,130 --> 01:44:08,340 practices you'll learn about naming your variables also apply to naming your 4284 01:44:08,340 --> 01:44:08,350 variables also apply to naming your 4285 01:44:08,350 --> 01:44:10,290 variables also apply to naming your functions so make sure your function 4286 01:44:10,290 --> 01:44:10,300 functions so make sure your function 4287 01:44:10,300 --> 01:44:13,590 functions so make sure your function names are meaningful descriptive use 4288 01:44:13,590 --> 01:44:13,600 names are meaningful descriptive use 4289 01:44:13,600 --> 01:44:15,630 names are meaningful descriptive use lowercase letters to name your functions 4290 01:44:15,630 --> 01:44:15,640 lowercase letters to name your functions 4291 01:44:15,640 --> 01:44:18,690 lowercase letters to name your functions and an underscore to separate multiple 4292 01:44:18,690 --> 01:44:18,700 and an underscore to separate multiple 4293 01:44:18,700 --> 01:44:21,780 and an underscore to separate multiple words now after the name we need to add 4294 01:44:21,780 --> 01:44:21,790 words now after the name we need to add 4295 01:44:21,790 --> 01:44:24,570 words now after the name we need to add parentheses you will see why shortly and 4296 01:44:24,570 --> 01:44:24,580 parentheses you will see why shortly and 4297 01:44:24,580 --> 01:44:28,260 parentheses you will see why shortly and then we'll add a colon now what is going 4298 01:44:28,260 --> 01:44:28,270 then we'll add a colon now what is going 4299 01:44:28,270 --> 01:44:30,750 then we'll add a colon now what is going to happen you know it you're gonna get 4300 01:44:30,750 --> 01:44:30,760 to happen you know it you're gonna get 4301 01:44:30,760 --> 01:44:33,000 to happen you know it you're gonna get indentation which means the following 4302 01:44:33,000 --> 01:44:33,010 indentation which means the following 4303 01:44:33,010 --> 01:44:35,040 indentation which means the following statements will belong to this function 4304 01:44:35,040 --> 01:44:35,050 statements will belong to this function 4305 01:44:35,050 --> 01:44:39,720 statements will belong to this function so here I'm gonna add two statements hi 4306 01:44:39,720 --> 01:44:39,730 so here I'm gonna add two statements hi 4307 01:44:39,730 --> 01:44:45,720 so here I'm gonna add two statements hi there and welcome aboard both designs 4308 01:44:45,720 --> 01:44:45,730 there and welcome aboard both designs 4309 01:44:45,730 --> 01:44:47,370 there and welcome aboard both designs belong to this function because they're 4310 01:44:47,370 --> 01:44:47,380 belong to this function because they're 4311 01:44:47,380 --> 01:44:50,130 belong to this function because they're indented now we're done with this 4312 01:44:50,130 --> 01:44:50,140 indented now we're done with this 4313 01:44:50,140 --> 01:44:53,160 indented now we're done with this function we need to call it so we remove 4314 01:44:53,160 --> 01:44:53,170 function we need to call it so we remove 4315 01:44:53,170 --> 01:44:56,070 function we need to call it so we remove the indentation and we add two line 4316 01:44:56,070 --> 01:44:56,080 the indentation and we add two line 4317 01:44:56,080 --> 01:44:58,620 the indentation and we add two line breaks after this function this is what 4318 01:44:58,620 --> 01:44:58,630 breaks after this function this is what 4319 01:44:58,630 --> 01:45:01,230 breaks after this function this is what Papp 8 recommends to keep our code clean 4320 01:45:01,230 --> 01:45:01,240 Papp 8 recommends to keep our code clean 4321 01:45:01,240 --> 01:45:03,480 Papp 8 recommends to keep our code clean and maintainable now if you forget to 4322 01:45:03,480 --> 01:45:03,490 and maintainable now if you forget to 4323 01:45:03,490 --> 01:45:05,520 and maintainable now if you forget to add two line breaks don't worry as soon 4324 01:45:05,520 --> 01:45:05,530 add two line breaks don't worry as soon 4325 01:45:05,530 --> 01:45:07,530 add two line breaks don't worry as soon as you save the changes auto-pay of 4326 01:45:07,530 --> 01:45:07,540 as you save the changes auto-pay of 4327 01:45:07,540 --> 01:45:09,540 as you save the changes auto-pay of eight will automatically add these line 4328 01:45:09,540 --> 01:45:09,550 eight will automatically add these line 4329 01:45:09,550 --> 01:45:11,580 eight will automatically add these line breaks for you let me show you so I'm 4330 01:45:11,580 --> 01:45:11,590 breaks for you let me show you so I'm 4331 01:45:11,590 --> 01:45:14,970 breaks for you let me show you so I'm gonna remove these line breaks and call 4332 01:45:14,970 --> 01:45:14,980 gonna remove these line breaks and call 4333 01:45:14,980 --> 01:45:17,310 gonna remove these line breaks and call this function create with parentheses 4334 01:45:17,310 --> 01:45:17,320 this function create with parentheses 4335 01:45:17,320 --> 01:45:19,500 this function create with parentheses just like how we call the built-in 4336 01:45:19,500 --> 01:45:19,510 just like how we call the built-in 4337 01:45:19,510 --> 01:45:23,190 just like how we call the built-in functions now save the changes there you 4338 01:45:23,190 --> 01:45:23,200 functions now save the changes there you 4339 01:45:23,200 --> 01:45:23,580 functions now save the changes there you go 4340 01:45:23,580 --> 01:45:23,590 go 4341 01:45:23,590 --> 01:45:24,600 go so we 4342 01:45:24,600 --> 01:45:24,610 so we 4343 01:45:24,610 --> 01:45:27,540 so we two line breaks after our function now 4344 01:45:27,540 --> 01:45:27,550 two line breaks after our function now 4345 01:45:27,550 --> 01:45:31,410 two line breaks after our function now let's run this program so we get these 4346 01:45:31,410 --> 01:45:31,420 let's run this program so we get these 4347 01:45:31,420 --> 01:45:40,490 let's run this program so we get these two messages on a terminal 4348 01:45:40,490 --> 01:45:40,500 4349 01:45:40,500 --> 01:45:43,229 now here's a question for you what is 4350 01:45:43,229 --> 01:45:43,239 now here's a question for you what is 4351 01:45:43,239 --> 01:45:45,439 now here's a question for you what is the difference between the greed and 4352 01:45:45,439 --> 01:45:45,449 the difference between the greed and 4353 01:45:45,449 --> 01:45:49,200 the difference between the greed and trent functions the difference is that 4354 01:45:49,200 --> 01:45:49,210 trent functions the difference is that 4355 01:45:49,210 --> 01:45:51,089 trent functions the difference is that this print function takes an input 4356 01:45:51,089 --> 01:45:51,099 this print function takes an input 4357 01:45:51,099 --> 01:45:54,330 this print function takes an input whereas our greet function doesn't take 4358 01:45:54,330 --> 01:45:54,340 whereas our greet function doesn't take 4359 01:45:54,340 --> 01:45:56,459 whereas our greet function doesn't take any inputs so let me show you how to 4360 01:45:56,459 --> 01:45:56,469 any inputs so let me show you how to 4361 01:45:56,469 --> 01:45:58,620 any inputs so let me show you how to pass inputs like first name and last 4362 01:45:58,620 --> 01:45:58,630 pass inputs like first name and last 4363 01:45:58,630 --> 01:46:01,560 pass inputs like first name and last name to this function when defining a 4364 01:46:01,560 --> 01:46:01,570 name to this function when defining a 4365 01:46:01,570 --> 01:46:03,959 name to this function when defining a function in between parentheses will 4366 01:46:03,959 --> 01:46:03,969 function in between parentheses will 4367 01:46:03,969 --> 01:46:07,049 function in between parentheses will list our parameters so here we add two 4368 01:46:07,049 --> 01:46:07,059 list our parameters so here we add two 4369 01:46:07,059 --> 01:46:10,080 list our parameters so here we add two parameters like first underline name and 4370 01:46:10,080 --> 01:46:10,090 parameters like first underline name and 4371 01:46:10,090 --> 01:46:13,890 parameters like first underline name and last underline name now when calling 4372 01:46:13,890 --> 01:46:13,900 last underline name now when calling 4373 01:46:13,900 --> 01:46:15,959 last underline name now when calling this function we need to supply two 4374 01:46:15,959 --> 01:46:15,969 this function we need to supply two 4375 01:46:15,969 --> 01:46:18,959 this function we need to supply two values for those parameters we refer to 4376 01:46:18,959 --> 01:46:18,969 values for those parameters we refer to 4377 01:46:18,969 --> 01:46:24,689 values for those parameters we refer to them as arguments so maash Madani these 4378 01:46:24,689 --> 01:46:24,699 them as arguments so maash Madani these 4379 01:46:24,699 --> 01:46:26,609 them as arguments so maash Madani these are the arguments to the greet function 4380 01:46:26,609 --> 01:46:26,619 are the arguments to the greet function 4381 01:46:26,619 --> 01:46:28,770 are the arguments to the greet function that's one of the terms that a lot of 4382 01:46:28,770 --> 01:46:28,780 that's one of the terms that a lot of 4383 01:46:28,780 --> 01:46:30,540 that's one of the terms that a lot of developers out there don't know they 4384 01:46:30,540 --> 01:46:30,550 developers out there don't know they 4385 01:46:30,550 --> 01:46:31,370 developers out there don't know they don't know the difference between 4386 01:46:31,370 --> 01:46:31,380 don't know the difference between 4387 01:46:31,380 --> 01:46:34,950 don't know the difference between parameters and arguments a parameter is 4388 01:46:34,950 --> 01:46:34,960 parameters and arguments a parameter is 4389 01:46:34,960 --> 01:46:36,810 parameters and arguments a parameter is the input that you define for your 4390 01:46:36,810 --> 01:46:36,820 the input that you define for your 4391 01:46:36,820 --> 01:46:39,600 the input that you define for your function where as an argument is the 4392 01:46:39,600 --> 01:46:39,610 function where as an argument is the 4393 01:46:39,610 --> 01:46:42,750 function where as an argument is the actual value for a given parameter okay 4394 01:46:42,750 --> 01:46:42,760 actual value for a given parameter okay 4395 01:46:42,760 --> 01:46:46,290 actual value for a given parameter okay now let's change line two and instead of 4396 01:46:46,290 --> 01:46:46,300 now let's change line two and instead of 4397 01:46:46,300 --> 01:46:48,479 now let's change line two and instead of saying hi there we can greet a person by 4398 01:46:48,479 --> 01:46:48,489 saying hi there we can greet a person by 4399 01:46:48,489 --> 01:46:50,790 saying hi there we can greet a person by their full name so we can convert this 4400 01:46:50,790 --> 01:46:50,800 their full name so we can convert this 4401 01:46:50,800 --> 01:46:54,510 their full name so we can convert this to a formatted string and pass two 4402 01:46:54,510 --> 01:46:54,520 to a formatted string and pass two 4403 01:46:54,520 --> 01:46:57,959 to a formatted string and pass two fields here first name as well as last 4404 01:46:57,959 --> 01:46:57,969 fields here first name as well as last 4405 01:46:57,969 --> 01:47:01,709 fields here first name as well as last name save the changes run the program 4406 01:47:01,709 --> 01:47:01,719 name save the changes run the program 4407 01:47:01,719 --> 01:47:05,069 name save the changes run the program and this is what we get in terminal now 4408 01:47:05,069 --> 01:47:05,079 and this is what we get in terminal now 4409 01:47:05,079 --> 01:47:06,839 and this is what we get in terminal now this function is more useful we can 4410 01:47:06,839 --> 01:47:06,849 this function is more useful we can 4411 01:47:06,849 --> 01:47:08,790 this function is more useful we can reuse it and call it with different 4412 01:47:08,790 --> 01:47:08,800 reuse it and call it with different 4413 01:47:08,800 --> 01:47:13,649 reuse it and call it with different arguments so let's create John Smith as 4414 01:47:13,649 --> 01:47:13,659 arguments so let's create John Smith as 4415 01:47:13,659 --> 01:47:17,189 arguments so let's create John Smith as well run the program so we get hi 4416 01:47:17,189 --> 01:47:17,199 well run the program so we get hi 4417 01:47:17,199 --> 01:47:20,760 well run the program so we get hi Muhammad on e and hi John Smith now note 4418 01:47:20,760 --> 01:47:20,770 Muhammad on e and hi John Smith now note 4419 01:47:20,770 --> 01:47:22,950 Muhammad on e and hi John Smith now note that by default all the parameters that 4420 01:47:22,950 --> 01:47:22,960 that by default all the parameters that 4421 01:47:22,960 --> 01:47:25,319 that by default all the parameters that you define for a function are required 4422 01:47:25,319 --> 01:47:25,329 you define for a function are required 4423 01:47:25,329 --> 01:47:27,959 you define for a function are required so here our greet function takes two 4424 01:47:27,959 --> 01:47:27,969 so here our greet function takes two 4425 01:47:27,969 --> 01:47:31,140 so here our greet function takes two parameters if I exclude one of these 4426 01:47:31,140 --> 01:47:31,150 parameters if I exclude one of these 4427 01:47:31,150 --> 01:47:34,319 parameters if I exclude one of these arguments and save the changes you can 4428 01:47:34,319 --> 01:47:34,329 arguments and save the changes you can 4429 01:47:34,329 --> 01:47:37,200 arguments and save the changes you can see we have this red underline so pilant 4430 01:47:37,200 --> 01:47:37,210 see we have this red underline so pilant 4431 01:47:37,210 --> 01:47:38,970 see we have this red underline so pilant is complaining and saying there is no 4432 01:47:38,970 --> 01:47:38,980 is complaining and saying there is no 4433 01:47:38,980 --> 01:47:42,299 is complaining and saying there is no value for argument last name also if we 4434 01:47:42,299 --> 01:47:42,309 value for argument last name also if we 4435 01:47:42,309 --> 01:47:44,189 value for argument last name also if we run the program we get this type error 4436 01:47:44,189 --> 01:47:44,199 run the program we get this type error 4437 01:47:44,199 --> 01:47:47,910 run the program we get this type error greet missing one required positional 4438 01:47:47,910 --> 01:47:47,920 greet missing one required positional 4439 01:47:47,920 --> 01:47:49,800 greet missing one required positional argument 4440 01:47:49,800 --> 01:47:49,810 argument 4441 01:47:49,810 --> 01:47:52,980 argument so let's put this back now later I will 4442 01:47:52,980 --> 01:47:52,990 so let's put this back now later I will 4443 01:47:52,990 --> 01:47:55,020 so let's put this back now later I will show you how to define optional 4444 01:47:55,020 --> 01:47:55,030 show you how to define optional 4445 01:47:55,030 --> 01:48:02,839 show you how to define optional parameters 4446 01:48:02,839 --> 01:48:02,849 4447 01:48:02,849 --> 01:48:05,490 so this is the simplified version of 4448 01:48:05,490 --> 01:48:05,500 so this is the simplified version of 4449 01:48:05,500 --> 01:48:07,370 so this is the simplified version of this greet function we created earlier 4450 01:48:07,370 --> 01:48:07,380 this greet function we created earlier 4451 01:48:07,380 --> 01:48:10,649 this greet function we created earlier now in programming we have two types of 4452 01:48:10,649 --> 01:48:10,659 now in programming we have two types of 4453 01:48:10,659 --> 01:48:13,890 now in programming we have two types of functions functions that perform a task 4454 01:48:13,890 --> 01:48:13,900 functions functions that perform a task 4455 01:48:13,900 --> 01:48:18,149 functions functions that perform a task and functions that calculate and return 4456 01:48:18,149 --> 01:48:18,159 and functions that calculate and return 4457 01:48:18,159 --> 01:48:21,959 and functions that calculate and return a value here are some examples both the 4458 01:48:21,959 --> 01:48:21,969 a value here are some examples both the 4459 01:48:21,969 --> 01:48:24,839 a value here are some examples both the print and greet functions are examples 4460 01:48:24,839 --> 01:48:24,849 print and greet functions are examples 4461 01:48:24,849 --> 01:48:27,959 print and greet functions are examples of type 1 the performing a task which is 4462 01:48:27,959 --> 01:48:27,969 of type 1 the performing a task which is 4463 01:48:27,969 --> 01:48:30,089 of type 1 the performing a task which is printing something on the terminal 4464 01:48:30,089 --> 01:48:30,099 printing something on the terminal 4465 01:48:30,099 --> 01:48:34,709 printing something on the terminal in contrast the brown function is an 4466 01:48:34,709 --> 01:48:34,719 in contrast the brown function is an 4467 01:48:34,719 --> 01:48:36,419 in contrast the brown function is an example of a function that calculates 4468 01:48:36,419 --> 01:48:36,429 example of a function that calculates 4469 01:48:36,429 --> 01:48:39,839 example of a function that calculates and returns a value so the functions 4470 01:48:39,839 --> 01:48:39,849 and returns a value so the functions 4471 01:48:39,849 --> 01:48:41,700 and returns a value so the functions that you create fall into these two 4472 01:48:41,700 --> 01:48:41,710 that you create fall into these two 4473 01:48:41,710 --> 01:48:44,220 that you create fall into these two categories now let me show you how to 4474 01:48:44,220 --> 01:48:44,230 categories now let me show you how to 4475 01:48:44,230 --> 01:48:46,680 categories now let me show you how to rewrite this greet function but in the 4476 01:48:46,680 --> 01:48:46,690 rewrite this greet function but in the 4477 01:48:46,690 --> 01:48:49,080 rewrite this greet function but in the second form so instead of printing this 4478 01:48:49,080 --> 01:48:49,090 second form so instead of printing this 4479 01:48:49,090 --> 01:48:52,260 second form so instead of printing this string on the terminal we simply return 4480 01:48:52,260 --> 01:48:52,270 string on the terminal we simply return 4481 01:48:52,270 --> 01:48:54,810 string on the terminal we simply return it let me show you so I'm going to 4482 01:48:54,810 --> 01:48:54,820 it let me show you so I'm going to 4483 01:48:54,820 --> 01:48:58,020 it let me show you so I'm going to delete all this code define a new 4484 01:48:58,020 --> 01:48:58,030 delete all this code define a new 4485 01:48:58,030 --> 01:49:01,010 delete all this code define a new function but call it get underline 4486 01:49:01,010 --> 01:49:01,020 function but call it get underline 4487 01:49:01,020 --> 01:49:04,490 function but call it get underline greeting we add the name parameter and 4488 01:49:04,490 --> 01:49:04,500 greeting we add the name parameter and 4489 01:49:04,500 --> 01:49:08,359 greeting we add the name parameter and simply return this formatted string high 4490 01:49:08,359 --> 01:49:08,369 simply return this formatted string high 4491 01:49:08,369 --> 01:49:12,209 simply return this formatted string high name that's all we have to do so we use 4492 01:49:12,209 --> 01:49:12,219 name that's all we have to do so we use 4493 01:49:12,219 --> 01:49:14,370 name that's all we have to do so we use the return statement to return a value 4494 01:49:14,370 --> 01:49:14,380 the return statement to return a value 4495 01:49:14,380 --> 01:49:16,890 the return statement to return a value from this function now we can call this 4496 01:49:16,890 --> 01:49:16,900 from this function now we can call this 4497 01:49:16,900 --> 01:49:21,149 from this function now we can call this function get underlined greeting has a 4498 01:49:21,149 --> 01:49:21,159 function get underlined greeting has a 4499 01:49:21,159 --> 01:49:25,109 function get underlined greeting has a name like Maj because it returns a value 4500 01:49:25,109 --> 01:49:25,119 name like Maj because it returns a value 4501 01:49:25,119 --> 01:49:27,930 name like Maj because it returns a value we can store that value in a separate 4502 01:49:27,930 --> 01:49:27,940 we can store that value in a separate 4503 01:49:27,940 --> 01:49:30,930 we can store that value in a separate variable like message now you might be 4504 01:49:30,930 --> 01:49:30,940 variable like message now you might be 4505 01:49:30,940 --> 01:49:33,299 variable like message now you might be curious which form of these greeting 4506 01:49:33,299 --> 01:49:33,309 curious which form of these greeting 4507 01:49:33,309 --> 01:49:36,240 curious which form of these greeting functions is better well with this first 4508 01:49:36,240 --> 01:49:36,250 functions is better well with this first 4509 01:49:36,250 --> 01:49:38,669 functions is better well with this first implementation we are locked to printing 4510 01:49:38,669 --> 01:49:38,679 implementation we are locked to printing 4511 01:49:38,679 --> 01:49:40,919 implementation we are locked to printing something in the terminal in the future 4512 01:49:40,919 --> 01:49:40,929 something in the terminal in the future 4513 01:49:40,929 --> 01:49:42,930 something in the terminal in the future if you want to write that message in a 4514 01:49:42,930 --> 01:49:42,940 if you want to write that message in a 4515 01:49:42,940 --> 01:49:45,510 if you want to write that message in a file or send it in an email you have to 4516 01:49:45,510 --> 01:49:45,520 file or send it in an email you have to 4517 01:49:45,520 --> 01:49:48,120 file or send it in an email you have to create another function so we cannot 4518 01:49:48,120 --> 01:49:48,130 create another function so we cannot 4519 01:49:48,130 --> 01:49:50,370 create another function so we cannot reuse this greet function in other 4520 01:49:50,370 --> 01:49:50,380 reuse this greet function in other 4521 01:49:50,380 --> 01:49:54,209 reuse this greet function in other scenarios in contrast this second form 4522 01:49:54,209 --> 01:49:54,219 scenarios in contrast this second form 4523 01:49:54,219 --> 01:49:56,879 scenarios in contrast this second form is not tied to printing something on the 4524 01:49:56,879 --> 01:49:56,889 is not tied to printing something on the 4525 01:49:56,889 --> 01:50:00,149 is not tied to printing something on the terminal it simply returns a value now 4526 01:50:00,149 --> 01:50:00,159 terminal it simply returns a value now 4527 01:50:00,159 --> 01:50:01,890 terminal it simply returns a value now we get this value and we can do whatever 4528 01:50:01,890 --> 01:50:01,900 we get this value and we can do whatever 4529 01:50:01,900 --> 01:50:04,859 we get this value and we can do whatever we want with it we can print it on the 4530 01:50:04,859 --> 01:50:04,869 we want with it we can print it on the 4531 01:50:04,869 --> 01:50:09,000 we want with it we can print it on the terminal or we can use the built-in open 4532 01:50:09,000 --> 01:50:09,010 terminal or we can use the built-in open 4533 01:50:09,010 --> 01:50:11,879 terminal or we can use the built-in open function to write this message to a file 4534 01:50:11,879 --> 01:50:11,889 function to write this message to a file 4535 01:50:11,889 --> 01:50:13,820 function to write this message to a file so we can create a 4536 01:50:13,820 --> 01:50:13,830 so we can create a 4537 01:50:13,830 --> 01:50:18,200 so we can create a like content txt openings for writing 4538 01:50:18,200 --> 01:50:18,210 like content txt openings for writing 4539 01:50:18,210 --> 01:50:20,930 like content txt openings for writing this returns a file object and then we 4540 01:50:20,930 --> 01:50:20,940 this returns a file object and then we 4541 01:50:20,940 --> 01:50:24,530 this returns a file object and then we can call file the right message now 4542 01:50:24,530 --> 01:50:24,540 can call file the right message now 4543 01:50:24,540 --> 01:50:26,600 can call file the right message now don't worry about these two lines later 4544 01:50:26,600 --> 01:50:26,610 don't worry about these two lines later 4545 01:50:26,610 --> 01:50:28,040 don't worry about these two lines later in the course I'm gonna talk about 4546 01:50:28,040 --> 01:50:28,050 in the course I'm gonna talk about 4547 01:50:28,050 --> 01:50:30,500 in the course I'm gonna talk about working with files but what I want you 4548 01:50:30,500 --> 01:50:30,510 working with files but what I want you 4549 01:50:30,510 --> 01:50:32,510 working with files but what I want you to take away here is that we have this 4550 01:50:32,510 --> 01:50:32,520 to take away here is that we have this 4551 01:50:32,520 --> 01:50:34,310 to take away here is that we have this message variable and we can do whatever 4552 01:50:34,310 --> 01:50:34,320 message variable and we can do whatever 4553 01:50:34,320 --> 01:50:36,470 message variable and we can do whatever we want with it we can print it on the 4554 01:50:36,470 --> 01:50:36,480 we want with it we can print it on the 4555 01:50:36,480 --> 01:50:39,110 we want with it we can print it on the terminal write it to a file send it in 4556 01:50:39,110 --> 01:50:39,120 terminal write it to a file send it in 4557 01:50:39,120 --> 01:50:40,160 terminal write it to a file send it in an email and so on 4558 01:50:40,160 --> 01:50:40,170 an email and so on 4559 01:50:40,170 --> 01:50:42,650 an email and so on and one more thing before we finish this 4560 01:50:42,650 --> 01:50:42,660 and one more thing before we finish this 4561 01:50:42,660 --> 01:50:44,870 and one more thing before we finish this lecture so here's our greet function and 4562 01:50:44,870 --> 01:50:44,880 lecture so here's our greet function and 4563 01:50:44,880 --> 01:50:47,210 lecture so here's our greet function and as you can see we're simply printing a 4564 01:50:47,210 --> 01:50:47,220 as you can see we're simply printing a 4565 01:50:47,220 --> 01:50:51,950 as you can see we're simply printing a string now if we call greet give it a 4566 01:50:51,950 --> 01:50:51,960 string now if we call greet give it a 4567 01:50:51,960 --> 01:50:54,680 string now if we call greet give it a name run the program we get this message 4568 01:50:54,680 --> 01:50:54,690 name run the program we get this message 4569 01:50:54,690 --> 01:50:58,580 name run the program we get this message hi Maj but what if we put this inside of 4570 01:50:58,580 --> 01:50:58,590 hi Maj but what if we put this inside of 4571 01:50:58,590 --> 01:51:02,420 hi Maj but what if we put this inside of a call to the print function let's see 4572 01:51:02,420 --> 01:51:02,430 a call to the print function let's see 4573 01:51:02,430 --> 01:51:05,690 a call to the print function let's see what we get we get high Marsh followed 4574 01:51:05,690 --> 01:51:05,700 what we get we get high Marsh followed 4575 01:51:05,700 --> 01:51:09,200 what we get we get high Marsh followed by not what is this none is the return 4576 01:51:09,200 --> 01:51:09,210 by not what is this none is the return 4577 01:51:09,210 --> 01:51:12,200 by not what is this none is the return value of the greet function so in Python 4578 01:51:12,200 --> 01:51:12,210 value of the greet function so in Python 4579 01:51:12,210 --> 01:51:15,620 value of the greet function so in Python all functions by default return the non 4580 01:51:15,620 --> 01:51:15,630 all functions by default return the non 4581 01:51:15,630 --> 01:51:17,780 all functions by default return the non value non is an object that represents 4582 01:51:17,780 --> 01:51:17,790 value non is an object that represents 4583 01:51:17,790 --> 01:51:20,720 value non is an object that represents the absence of a value later in the 4584 01:51:20,720 --> 01:51:20,730 the absence of a value later in the 4585 01:51:20,730 --> 01:51:22,220 the absence of a value later in the course you're gonna learn more about not 4586 01:51:22,220 --> 01:51:22,230 course you're gonna learn more about not 4587 01:51:22,230 --> 01:51:25,040 course you're gonna learn more about not what matters now is that all functions 4588 01:51:25,040 --> 01:51:25,050 what matters now is that all functions 4589 01:51:25,050 --> 01:51:27,740 what matters now is that all functions return non by default unless you 4590 01:51:27,740 --> 01:51:27,750 return non by default unless you 4591 01:51:27,750 --> 01:51:31,460 return non by default unless you specifically return a value so here if 4592 01:51:31,460 --> 01:51:31,470 specifically return a value so here if 4593 01:51:31,470 --> 01:51:35,500 specifically return a value so here if we return some string 4594 01:51:35,500 --> 01:51:35,510 we return some string 4595 01:51:35,510 --> 01:51:38,690 we return some string none will no longer be returned now I 4596 01:51:38,690 --> 01:51:38,700 none will no longer be returned now I 4597 01:51:38,700 --> 01:51:40,700 none will no longer be returned now I just want to clarify something earlier I 4598 01:51:40,700 --> 01:51:40,710 just want to clarify something earlier I 4599 01:51:40,710 --> 01:51:42,170 just want to clarify something earlier I told you that we have two types of 4600 01:51:42,170 --> 01:51:42,180 told you that we have two types of 4601 01:51:42,180 --> 01:51:44,390 told you that we have two types of functions in programming functions that 4602 01:51:44,390 --> 01:51:44,400 functions in programming functions that 4603 01:51:44,400 --> 01:51:46,730 functions in programming functions that carry out the tasks or functions that 4604 01:51:46,730 --> 01:51:46,740 carry out the tasks or functions that 4605 01:51:46,740 --> 01:51:49,760 carry out the tasks or functions that calculate and return a value so back to 4606 01:51:49,760 --> 01:51:49,770 calculate and return a value so back to 4607 01:51:49,770 --> 01:51:53,270 calculate and return a value so back to the code we previously had so even 4608 01:51:53,270 --> 01:51:53,280 the code we previously had so even 4609 01:51:53,280 --> 01:51:55,250 the code we previously had so even though this function returns none by 4610 01:51:55,250 --> 01:51:55,260 though this function returns none by 4611 01:51:55,260 --> 01:51:57,590 though this function returns none by default it is still classified as a 4612 01:51:57,590 --> 01:51:57,600 default it is still classified as a 4613 01:51:57,600 --> 01:52:07,310 default it is still classified as a function that carries out a task 4614 01:52:07,310 --> 01:52:07,320 4615 01:52:07,320 --> 01:52:11,160 let's create another function we call it 4616 01:52:11,160 --> 01:52:11,170 let's create another function we call it 4617 01:52:11,170 --> 01:52:13,500 let's create another function we call it increment you want to use this function 4618 01:52:13,500 --> 01:52:13,510 increment you want to use this function 4619 01:52:13,510 --> 01:52:17,480 increment you want to use this function to increment a number by a given value 4620 01:52:17,480 --> 01:52:17,490 to increment a number by a given value 4621 01:52:17,490 --> 01:52:22,820 to increment a number by a given value so here we simply return number plus by 4622 01:52:22,820 --> 01:52:22,830 so here we simply return number plus by 4623 01:52:22,830 --> 01:52:25,860 so here we simply return number plus by now we can call this function like this 4624 01:52:25,860 --> 01:52:25,870 now we can call this function like this 4625 01:52:25,870 --> 01:52:29,370 now we can call this function like this increment two and one this returns a 4626 01:52:29,370 --> 01:52:29,380 increment two and one this returns a 4627 01:52:29,380 --> 01:52:31,970 increment two and one this returns a value so we can store it in a variable 4628 01:52:31,970 --> 01:52:31,980 value so we can store it in a variable 4629 01:52:31,980 --> 01:52:35,130 value so we can store it in a variable like result and then print it on the 4630 01:52:35,130 --> 01:52:35,140 like result and then print it on the 4631 01:52:35,140 --> 01:52:38,130 like result and then print it on the terminal let's run the program we get 4632 01:52:38,130 --> 01:52:38,140 terminal let's run the program we get 4633 01:52:38,140 --> 01:52:40,890 terminal let's run the program we get three beautiful now we can simplify this 4634 01:52:40,890 --> 01:52:40,900 three beautiful now we can simplify this 4635 01:52:40,900 --> 01:52:43,560 three beautiful now we can simplify this code we have used this result variable 4636 01:52:43,560 --> 01:52:43,570 code we have used this result variable 4637 01:52:43,570 --> 01:52:46,950 code we have used this result variable only in a single place that is line six 4638 01:52:46,950 --> 01:52:46,960 only in a single place that is line six 4639 01:52:46,960 --> 01:52:49,920 only in a single place that is line six so we don't really need it so on line 4640 01:52:49,920 --> 01:52:49,930 so we don't really need it so on line 4641 01:52:49,930 --> 01:52:53,730 so we don't really need it so on line six we can replace result with a call to 4642 01:52:53,730 --> 01:52:53,740 six we can replace result with a call to 4643 01:52:53,740 --> 01:52:57,870 six we can replace result with a call to increment function like this so when 4644 01:52:57,870 --> 01:52:57,880 increment function like this so when 4645 01:52:57,880 --> 01:53:00,000 increment function like this so when python interpreter executes this code 4646 01:53:00,000 --> 01:53:00,010 python interpreter executes this code 4647 01:53:00,010 --> 01:53:02,640 python interpreter executes this code first it will call the increment 4648 01:53:02,640 --> 01:53:02,650 first it will call the increment 4649 01:53:02,650 --> 01:53:04,710 first it will call the increment function it will get the result and 4650 01:53:04,710 --> 01:53:04,720 function it will get the result and 4651 01:53:04,720 --> 01:53:07,050 function it will get the result and temporary store it in a variable for us 4652 01:53:07,050 --> 01:53:07,060 temporary store it in a variable for us 4653 01:53:07,060 --> 01:53:09,240 temporary store it in a variable for us we don't see that variable and then it 4654 01:53:09,240 --> 01:53:09,250 we don't see that variable and then it 4655 01:53:09,250 --> 01:53:10,920 we don't see that variable and then it will pass that variable as an argument 4656 01:53:10,920 --> 01:53:10,930 will pass that variable as an argument 4657 01:53:10,930 --> 01:53:15,030 will pass that variable as an argument to the print function now if we run this 4658 01:53:15,030 --> 01:53:15,040 to the print function now if we run this 4659 01:53:15,040 --> 01:53:17,400 to the print function now if we run this program we get the exact same result 4660 01:53:17,400 --> 01:53:17,410 program we get the exact same result 4661 01:53:17,410 --> 01:53:20,250 program we get the exact same result beautiful now we can make this code more 4662 01:53:20,250 --> 01:53:20,260 beautiful now we can make this code more 4663 01:53:20,260 --> 01:53:22,740 beautiful now we can make this code more readable if someone else looks at line 4664 01:53:22,740 --> 01:53:22,750 readable if someone else looks at line 4665 01:53:22,750 --> 01:53:25,430 readable if someone else looks at line five they may not know exactly what 4666 01:53:25,430 --> 01:53:25,440 five they may not know exactly what 4667 01:53:25,440 --> 01:53:28,800 five they may not know exactly what these arguments are for we can use a 4668 01:53:28,800 --> 01:53:28,810 these arguments are for we can use a 4669 01:53:28,810 --> 01:53:31,440 these arguments are for we can use a keyword argument to make this code more 4670 01:53:31,440 --> 01:53:31,450 keyword argument to make this code more 4671 01:53:31,450 --> 01:53:35,010 keyword argument to make this code more readable so this one here is the value 4672 01:53:35,010 --> 01:53:35,020 readable so this one here is the value 4673 01:53:35,020 --> 01:53:38,700 readable so this one here is the value of this by parameter we can prefix it 4674 01:53:38,700 --> 01:53:38,710 of this by parameter we can prefix it 4675 01:53:38,710 --> 01:53:41,840 of this by parameter we can prefix it with the name of the parameter like this 4676 01:53:41,840 --> 01:53:41,850 with the name of the parameter like this 4677 01:53:41,850 --> 01:53:44,850 with the name of the parameter like this now we can read this code almost like 4678 01:53:44,850 --> 01:53:44,860 now we can read this code almost like 4679 01:53:44,860 --> 01:53:48,720 now we can read this code almost like playing English increment two by one so 4680 01:53:48,720 --> 01:53:48,730 playing English increment two by one so 4681 01:53:48,730 --> 01:53:50,250 playing English increment two by one so if you're calling a function with 4682 01:53:50,250 --> 01:53:50,260 if you're calling a function with 4683 01:53:50,260 --> 01:53:52,500 if you're calling a function with multiple arguments and it's not quite 4684 01:53:52,500 --> 01:53:52,510 multiple arguments and it's not quite 4685 01:53:52,510 --> 01:53:55,230 multiple arguments and it's not quite clear what is arguments are for you can 4686 01:53:55,230 --> 01:53:55,240 clear what is arguments are for you can 4687 01:53:55,240 --> 01:53:57,450 clear what is arguments are for you can make your code more readable by using 4688 01:53:57,450 --> 01:53:57,460 make your code more readable by using 4689 01:53:57,460 --> 01:54:00,990 make your code more readable by using keyword arguments so here y equals one 4690 01:54:00,990 --> 01:54:01,000 keyword arguments so here y equals one 4691 01:54:01,000 --> 01:54:09,960 keyword arguments so here y equals one is a keyword argument 4692 01:54:09,960 --> 01:54:09,970 4693 01:54:09,970 --> 01:54:12,250 earlier I told you that all the 4694 01:54:12,250 --> 01:54:12,260 earlier I told you that all the 4695 01:54:12,260 --> 01:54:13,750 earlier I told you that all the parameters that you define for a 4696 01:54:13,750 --> 01:54:13,760 parameters that you define for a 4697 01:54:13,760 --> 01:54:16,960 parameters that you define for a function are required by default in this 4698 01:54:16,960 --> 01:54:16,970 function are required by default in this 4699 01:54:16,970 --> 01:54:18,910 function are required by default in this lecture I'm gonna show you how to make 4700 01:54:18,910 --> 01:54:18,920 lecture I'm gonna show you how to make 4701 01:54:18,920 --> 01:54:22,600 lecture I'm gonna show you how to make the by parameter optional so let's say 4702 01:54:22,600 --> 01:54:22,610 the by parameter optional so let's say 4703 01:54:22,610 --> 01:54:25,660 the by parameter optional so let's say we don't want to explicitly pass y 4704 01:54:25,660 --> 01:54:25,670 we don't want to explicitly pass y 4705 01:54:25,670 --> 01:54:28,360 we don't want to explicitly pass y equals 1 every time we want to call this 4706 01:54:28,360 --> 01:54:28,370 equals 1 every time we want to call this 4707 01:54:28,370 --> 01:54:30,520 equals 1 every time we want to call this increment function we want to use this 4708 01:54:30,520 --> 01:54:30,530 increment function we want to use this 4709 01:54:30,530 --> 01:54:34,810 increment function we want to use this function to increment a value by 1 so we 4710 01:54:34,810 --> 01:54:34,820 function to increment a value by 1 so we 4711 01:54:34,820 --> 01:54:37,150 function to increment a value by 1 so we remove the second argument now we need 4712 01:54:37,150 --> 01:54:37,160 remove the second argument now we need 4713 01:54:37,160 --> 01:54:39,340 remove the second argument now we need to give this parameter a default value 4714 01:54:39,340 --> 01:54:39,350 to give this parameter a default value 4715 01:54:39,350 --> 01:54:42,940 to give this parameter a default value so we set it to 1 now if we call this 4716 01:54:42,940 --> 01:54:42,950 so we set it to 1 now if we call this 4717 01:54:42,950 --> 01:54:45,430 so we set it to 1 now if we call this function and don't supply the second 4718 01:54:45,430 --> 01:54:45,440 function and don't supply the second 4719 01:54:45,440 --> 01:54:47,680 function and don't supply the second argument this default value will be used 4720 01:54:47,680 --> 01:54:47,690 argument this default value will be used 4721 01:54:47,690 --> 01:54:50,350 argument this default value will be used otherwise the value that we specify here 4722 01:54:50,350 --> 01:54:50,360 otherwise the value that we specify here 4723 01:54:50,360 --> 01:54:53,080 otherwise the value that we specify here will be used let me show you so we've 4724 01:54:53,080 --> 01:54:53,090 will be used let me show you so we've 4725 01:54:53,090 --> 01:54:57,070 will be used let me show you so we've run this program the result is 3 but if 4726 01:54:57,070 --> 01:54:57,080 run this program the result is 3 but if 4727 01:54:57,080 --> 01:55:00,490 run this program the result is 3 but if we pass the second argument here we'll 4728 01:55:00,490 --> 01:55:00,500 we pass the second argument here we'll 4729 01:55:00,500 --> 01:55:05,050 we pass the second argument here we'll increment 2 by 5 so we'll get 7 so you 4730 01:55:05,050 --> 01:55:05,060 increment 2 by 5 so we'll get 7 so you 4731 01:55:05,060 --> 01:55:06,790 increment 2 by 5 so we'll get 7 so you can see it's pretty easy to make a 4732 01:55:06,790 --> 01:55:06,800 can see it's pretty easy to make a 4733 01:55:06,800 --> 01:55:09,490 can see it's pretty easy to make a parameter optional just be aware that 4734 01:55:09,490 --> 01:55:09,500 parameter optional just be aware that 4735 01:55:09,500 --> 01:55:11,860 parameter optional just be aware that all these optional parameters should 4736 01:55:11,860 --> 01:55:11,870 all these optional parameters should 4737 01:55:11,870 --> 01:55:15,700 all these optional parameters should come after the required parameters in 4738 01:55:15,700 --> 01:55:15,710 come after the required parameters in 4739 01:55:15,710 --> 01:55:18,460 come after the required parameters in other words I cannot add another 4740 01:55:18,460 --> 01:55:18,470 other words I cannot add another 4741 01:55:18,470 --> 01:55:21,250 other words I cannot add another required parameter here let's call that 4742 01:55:21,250 --> 01:55:21,260 required parameter here let's call that 4743 01:55:21,260 --> 01:55:24,550 required parameter here let's call that another I cannot add that here if I save 4744 01:55:24,550 --> 01:55:24,560 another I cannot add that here if I save 4745 01:55:24,560 --> 01:55:27,190 another I cannot add that here if I save the changes you can see we get a red 4746 01:55:27,190 --> 01:55:27,200 the changes you can see we get a red 4747 01:55:27,200 --> 01:55:29,980 the changes you can see we get a red underline here so all the optional 4748 01:55:29,980 --> 01:55:29,990 underline here so all the optional 4749 01:55:29,990 --> 01:55:33,160 underline here so all the optional parameters should come after the 4750 01:55:33,160 --> 01:55:33,170 parameters should come after the 4751 01:55:33,170 --> 01:55:35,830 parameters should come after the required parameters now obviously in 4752 01:55:35,830 --> 01:55:35,840 required parameters now obviously in 4753 01:55:35,840 --> 01:55:37,510 required parameters now obviously in this case we don't need the second 4754 01:55:37,510 --> 01:55:37,520 this case we don't need the second 4755 01:55:37,520 --> 01:55:46,840 this case we don't need the second parameter so let's delete it 4756 01:55:46,840 --> 01:55:46,850 4757 01:55:46,850 --> 01:55:49,070 there are times that you may want to 4758 01:55:49,070 --> 01:55:49,080 there are times that you may want to 4759 01:55:49,080 --> 01:55:51,350 there are times that you may want to create a function that takes a variable 4760 01:55:51,350 --> 01:55:51,360 create a function that takes a variable 4761 01:55:51,360 --> 01:55:53,750 create a function that takes a variable number of arguments here is an example 4762 01:55:53,750 --> 01:55:53,760 number of arguments here is an example 4763 01:55:53,760 --> 01:55:56,590 number of arguments here is an example let's define this function multiplied 4764 01:55:56,590 --> 01:55:56,600 let's define this function multiplied 4765 01:55:56,600 --> 01:56:00,410 let's define this function multiplied that takes two parameters x and y and 4766 01:56:00,410 --> 01:56:00,420 that takes two parameters x and y and 4767 01:56:00,420 --> 01:56:05,570 that takes two parameters x and y and simply returns x times y now we can call 4768 01:56:05,570 --> 01:56:05,580 simply returns x times y now we can call 4769 01:56:05,580 --> 01:56:09,470 simply returns x times y now we can call this function like this 4770 01:56:09,470 --> 01:56:09,480 4771 01:56:09,480 --> 01:56:11,600 so far so good but what if you want to 4772 01:56:11,600 --> 01:56:11,610 so far so good but what if you want to 4773 01:56:11,610 --> 01:56:15,500 so far so good but what if you want to pass one or two more arguments here that 4774 01:56:15,500 --> 01:56:15,510 pass one or two more arguments here that 4775 01:56:15,510 --> 01:56:17,240 pass one or two more arguments here that doesn't work because our multiply 4776 01:56:17,240 --> 01:56:17,250 doesn't work because our multiply 4777 01:56:17,250 --> 01:56:19,400 doesn't work because our multiply function takes only two parameters to 4778 01:56:19,400 --> 01:56:19,410 function takes only two parameters to 4779 01:56:19,410 --> 01:56:22,220 function takes only two parameters to solve this problem we need to replace 4780 01:56:22,220 --> 01:56:22,230 solve this problem we need to replace 4781 01:56:22,230 --> 01:56:24,680 solve this problem we need to replace these two parameters with a single 4782 01:56:24,680 --> 01:56:24,690 these two parameters with a single 4783 01:56:24,690 --> 01:56:27,680 these two parameters with a single parameter we use a plural name here to 4784 01:56:27,680 --> 01:56:27,690 parameter we use a plural name here to 4785 01:56:27,690 --> 01:56:29,930 parameter we use a plural name here to indicate that this is a collection of 4786 01:56:29,930 --> 01:56:29,940 indicate that this is a collection of 4787 01:56:29,940 --> 01:56:32,960 indicate that this is a collection of arguments and then we prefix it with an 4788 01:56:32,960 --> 01:56:32,970 arguments and then we prefix it with an 4789 01:56:32,970 --> 01:56:35,960 arguments and then we prefix it with an asterisk this is the magical part let me 4790 01:56:35,960 --> 01:56:35,970 asterisk this is the magical part let me 4791 01:56:35,970 --> 01:56:38,060 asterisk this is the magical part let me show you what happens when you use an 4792 01:56:38,060 --> 01:56:38,070 show you what happens when you use an 4793 01:56:38,070 --> 01:56:41,210 show you what happens when you use an asterisk here so temporarily let's 4794 01:56:41,210 --> 01:56:41,220 asterisk here so temporarily let's 4795 01:56:41,220 --> 01:56:43,030 asterisk here so temporarily let's delete this line and simply print 4796 01:56:43,030 --> 01:56:43,040 delete this line and simply print 4797 01:56:43,040 --> 01:56:46,550 delete this line and simply print numbers let's see what we get here so 4798 01:56:46,550 --> 01:56:46,560 numbers let's see what we get here so 4799 01:56:46,560 --> 01:56:49,190 numbers let's see what we get here so run the program you can see all our 4800 01:56:49,190 --> 01:56:49,200 run the program you can see all our 4801 01:56:49,200 --> 01:56:51,740 run the program you can see all our arguments and they're packed in 4802 01:56:51,740 --> 01:56:51,750 arguments and they're packed in 4803 01:56:51,750 --> 01:56:55,670 arguments and they're packed in parentheses what is this well earlier 4804 01:56:55,670 --> 01:56:55,680 parentheses what is this well earlier 4805 01:56:55,680 --> 01:56:58,280 parentheses what is this well earlier you learned about lists I briefly 4806 01:56:58,280 --> 01:56:58,290 you learned about lists I briefly 4807 01:56:58,290 --> 01:57:00,260 you learned about lists I briefly mentioned that you can use square 4808 01:57:00,260 --> 01:57:00,270 mentioned that you can use square 4809 01:57:00,270 --> 01:57:02,570 mentioned that you can use square brackets to create a list of objects 4810 01:57:02,570 --> 01:57:02,580 brackets to create a list of objects 4811 01:57:02,580 --> 01:57:05,870 brackets to create a list of objects like 2 3 4 5 now later in the course we 4812 01:57:05,870 --> 01:57:05,880 like 2 3 4 5 now later in the course we 4813 01:57:05,880 --> 01:57:07,850 like 2 3 4 5 now later in the course we have a comprehensive section about lists 4814 01:57:07,850 --> 01:57:07,860 have a comprehensive section about lists 4815 01:57:07,860 --> 01:57:09,800 have a comprehensive section about lists so don't worry about the details of 4816 01:57:09,800 --> 01:57:09,810 so don't worry about the details of 4817 01:57:09,810 --> 01:57:12,500 so don't worry about the details of lists and how they work but what I want 4818 01:57:12,500 --> 01:57:12,510 lists and how they work but what I want 4819 01:57:12,510 --> 01:57:14,390 lists and how they work but what I want you to note here is that the only 4820 01:57:14,390 --> 01:57:14,400 you to note here is that the only 4821 01:57:14,400 --> 01:57:17,150 you to note here is that the only difference between this list and what we 4822 01:57:17,150 --> 01:57:17,160 difference between this list and what we 4823 01:57:17,160 --> 01:57:20,390 difference between this list and what we have here is in the notation so use 4824 01:57:20,390 --> 01:57:20,400 have here is in the notation so use 4825 01:57:20,400 --> 01:57:22,780 have here is in the notation so use square brackets to create lists and 4826 01:57:22,780 --> 01:57:22,790 square brackets to create lists and 4827 01:57:22,790 --> 01:57:26,000 square brackets to create lists and parentheses to create tuples some people 4828 01:57:26,000 --> 01:57:26,010 parentheses to create tuples some people 4829 01:57:26,010 --> 01:57:28,640 parentheses to create tuples some people call it two poles or two poles so a top 4830 01:57:28,640 --> 01:57:28,650 call it two poles or two poles so a top 4831 01:57:28,650 --> 01:57:30,950 call it two poles or two poles so a top pole is similar to a list in that it's a 4832 01:57:30,950 --> 01:57:30,960 pole is similar to a list in that it's a 4833 01:57:30,960 --> 01:57:33,500 pole is similar to a list in that it's a collection of objects the difference is 4834 01:57:33,500 --> 01:57:33,510 collection of objects the difference is 4835 01:57:33,510 --> 01:57:35,870 collection of objects the difference is that we cannot modify this collection we 4836 01:57:35,870 --> 01:57:35,880 that we cannot modify this collection we 4837 01:57:35,880 --> 01:57:38,180 that we cannot modify this collection we cannot add a new object to this topple 4838 01:57:38,180 --> 01:57:38,190 cannot add a new object to this topple 4839 01:57:38,190 --> 01:57:40,370 cannot add a new object to this topple once again later in the course we're 4840 01:57:40,370 --> 01:57:40,380 once again later in the course we're 4841 01:57:40,380 --> 01:57:42,110 once again later in the course we're going to have a comprehensive section 4842 01:57:42,110 --> 01:57:42,120 going to have a comprehensive section 4843 01:57:42,120 --> 01:57:44,930 going to have a comprehensive section about lists tuples and other data 4844 01:57:44,930 --> 01:57:44,940 about lists tuples and other data 4845 01:57:44,940 --> 01:57:47,660 about lists tuples and other data structures what matters now is that 4846 01:57:47,660 --> 01:57:47,670 structures what matters now is that 4847 01:57:47,670 --> 01:57:48,770 structures what matters now is that these topples 4848 01:57:48,770 --> 01:57:48,780 these topples 4849 01:57:48,780 --> 01:57:51,920 these topples just like lists are iterable so we can 4850 01:57:51,920 --> 01:57:51,930 just like lists are iterable so we can 4851 01:57:51,930 --> 01:57:53,840 just like lists are iterable so we can each raid over them which means we can 4852 01:57:53,840 --> 01:57:53,850 each raid over them which means we can 4853 01:57:53,850 --> 01:57:57,400 each raid over them which means we can use them in loops let me show you so 4854 01:57:57,400 --> 01:57:57,410 use them in loops let me show you so 4855 01:57:57,410 --> 01:57:58,820 use them in loops let me show you so that's right 4856 01:57:58,820 --> 01:57:58,830 that's right 4857 01:57:58,830 --> 01:58:04,190 that's right for number in numbers : let's just print 4858 01:58:04,190 --> 01:58:04,200 for number in numbers : let's just print 4859 01:58:04,200 --> 01:58:07,729 for number in numbers : let's just print one number at a time actually we don't 4860 01:58:07,729 --> 01:58:07,739 one number at a time actually we don't 4861 01:58:07,739 --> 01:58:10,850 one number at a time actually we don't need this line so delete and run the 4862 01:58:10,850 --> 01:58:10,860 need this line so delete and run the 4863 01:58:10,860 --> 01:58:14,000 need this line so delete and run the program so we iterate over this topple 4864 01:58:14,000 --> 01:58:14,010 program so we iterate over this topple 4865 01:58:14,010 --> 01:58:16,250 program so we iterate over this topple and in each iteration we get one number 4866 01:58:16,250 --> 01:58:16,260 and in each iteration we get one number 4867 01:58:16,260 --> 01:58:19,040 and in each iteration we get one number and print it on the terminal so now with 4868 01:58:19,040 --> 01:58:19,050 and print it on the terminal so now with 4869 01:58:19,050 --> 01:58:21,140 and print it on the terminal so now with a simple change we can calculate the 4870 01:58:21,140 --> 01:58:21,150 a simple change we can calculate the 4871 01:58:21,150 --> 01:58:23,030 a simple change we can calculate the product of all these numbers 4872 01:58:23,030 --> 01:58:23,040 product of all these numbers 4873 01:58:23,040 --> 01:58:25,970 product of all these numbers all we have to do is to define a 4874 01:58:25,970 --> 01:58:25,980 all we have to do is to define a 4875 01:58:25,980 --> 01:58:28,820 all we have to do is to define a variable like total initially we set it 4876 01:58:28,820 --> 01:58:28,830 variable like total initially we set it 4877 01:58:28,830 --> 01:58:32,780 variable like total initially we set it to one and then in each iteration we get 4878 01:58:32,780 --> 01:58:32,790 to one and then in each iteration we get 4879 01:58:32,790 --> 01:58:36,350 to one and then in each iteration we get total and multiplied by the current 4880 01:58:36,350 --> 01:58:36,360 total and multiplied by the current 4881 01:58:36,360 --> 01:58:38,950 total and multiplied by the current number or we can rewrite this statement 4882 01:58:38,950 --> 01:58:38,960 number or we can rewrite this statement 4883 01:58:38,960 --> 01:58:42,530 number or we can rewrite this statement using an Augmented assignment operator 4884 01:58:42,530 --> 01:58:42,540 using an Augmented assignment operator 4885 01:58:42,540 --> 01:58:47,720 using an Augmented assignment operator so total times equal number line five 4886 01:58:47,720 --> 01:58:47,730 so total times equal number line five 4887 01:58:47,730 --> 01:58:51,080 so total times equal number line five and four are exactly identical so I'm 4888 01:58:51,080 --> 01:58:51,090 and four are exactly identical so I'm 4889 01:58:51,090 --> 01:58:53,000 and four are exactly identical so I'm gonna use line five because it's shorter 4890 01:58:53,000 --> 01:58:53,010 gonna use line five because it's shorter 4891 01:58:53,010 --> 01:58:56,540 gonna use line five because it's shorter and cleaner delete and finally we'll 4892 01:58:56,540 --> 01:58:56,550 and cleaner delete and finally we'll 4893 01:58:56,550 --> 01:59:00,170 and cleaner delete and finally we'll return the total now one of the issues I 4894 01:59:00,170 --> 01:59:00,180 return the total now one of the issues I 4895 01:59:00,180 --> 01:59:03,260 return the total now one of the issues I see often in beginners code is that they 4896 01:59:03,260 --> 01:59:03,270 see often in beginners code is that they 4897 01:59:03,270 --> 01:59:06,140 see often in beginners code is that they don't use this indentation properly so 4898 01:59:06,140 --> 01:59:06,150 don't use this indentation properly so 4899 01:59:06,150 --> 01:59:08,090 don't use this indentation properly so they put the return statement here and 4900 01:59:08,090 --> 01:59:08,100 they put the return statement here and 4901 01:59:08,100 --> 01:59:10,280 they put the return statement here and then they wonder why their function 4902 01:59:10,280 --> 01:59:10,290 then they wonder why their function 4903 01:59:10,290 --> 01:59:12,470 then they wonder why their function doesn't work properly if you put the 4904 01:59:12,470 --> 01:59:12,480 doesn't work properly if you put the 4905 01:59:12,480 --> 01:59:14,720 doesn't work properly if you put the return statement here it will be part of 4906 01:59:14,720 --> 01:59:14,730 return statement here it will be part of 4907 01:59:14,730 --> 01:59:17,840 return statement here it will be part of the for loop so it will be executed in 4908 01:59:17,840 --> 01:59:17,850 the for loop so it will be executed in 4909 01:59:17,850 --> 01:59:20,690 the for loop so it will be executed in each iteration in this case after the 4910 01:59:20,690 --> 01:59:20,700 each iteration in this case after the 4911 01:59:20,700 --> 01:59:23,150 each iteration in this case after the first iteration because of this return 4912 01:59:23,150 --> 01:59:23,160 first iteration because of this return 4913 01:59:23,160 --> 01:59:25,040 first iteration because of this return statement we'll return from this 4914 01:59:25,040 --> 01:59:25,050 statement we'll return from this 4915 01:59:25,050 --> 01:59:27,680 statement we'll return from this multiply function so the total will not 4916 01:59:27,680 --> 01:59:27,690 multiply function so the total will not 4917 01:59:27,690 --> 01:59:30,320 multiply function so the total will not be calculated properly we need to put 4918 01:59:30,320 --> 01:59:30,330 be calculated properly we need to put 4919 01:59:30,330 --> 01:59:33,530 be calculated properly we need to put this at the same level of indentation as 4920 01:59:33,530 --> 01:59:33,540 this at the same level of indentation as 4921 01:59:33,540 --> 01:59:35,660 this at the same level of indentation as other statements in this function so 4922 01:59:35,660 --> 01:59:35,670 other statements in this function so 4923 01:59:35,670 --> 01:59:38,450 other statements in this function so here we have our for statement we loop 4924 01:59:38,450 --> 01:59:38,460 here we have our for statement we loop 4925 01:59:38,460 --> 01:59:41,210 here we have our for statement we loop over all the numbers we calculate the 4926 01:59:41,210 --> 01:59:41,220 over all the numbers we calculate the 4927 01:59:41,220 --> 01:59:45,500 over all the numbers we calculate the total and then finally return it so with 4928 01:59:45,500 --> 01:59:45,510 total and then finally return it so with 4929 01:59:45,510 --> 01:59:47,330 total and then finally return it so with this implementation we can get the 4930 01:59:47,330 --> 01:59:47,340 this implementation we can get the 4931 01:59:47,340 --> 01:59:50,840 this implementation we can get the result and printed on the terminal let's 4932 01:59:50,840 --> 01:59:50,850 result and printed on the terminal let's 4933 01:59:50,850 --> 01:59:53,990 result and printed on the terminal let's run the program and you can see the 4934 01:59:53,990 --> 01:59:54,000 run the program and you can see the 4935 01:59:54,000 --> 02:00:03,819 run the program and you can see the product of these numbers is 120 4936 02:00:03,819 --> 02:00:03,829 4937 02:00:03,829 --> 02:00:06,379 so in the last lecture you learned the 4938 02:00:06,379 --> 02:00:06,389 so in the last lecture you learned the 4939 02:00:06,389 --> 02:00:09,109 so in the last lecture you learned the syntax to pass a variable number of 4940 02:00:09,109 --> 02:00:09,119 syntax to pass a variable number of 4941 02:00:09,119 --> 02:00:11,450 syntax to pass a variable number of arguments to a function we have a 4942 02:00:11,450 --> 02:00:11,460 arguments to a function we have a 4943 02:00:11,460 --> 02:00:14,299 arguments to a function we have a variation of this syntax with double 4944 02:00:14,299 --> 02:00:14,309 variation of this syntax with double 4945 02:00:14,309 --> 02:00:16,250 variation of this syntax with double asterisk and that's what I'm gonna show 4946 02:00:16,250 --> 02:00:16,260 asterisk and that's what I'm gonna show 4947 02:00:16,260 --> 02:00:19,069 asterisk and that's what I'm gonna show you in this lecture so for this demo 4948 02:00:19,069 --> 02:00:19,079 you in this lecture so for this demo 4949 02:00:19,079 --> 02:00:21,009 you in this lecture so for this demo let's rename this function to save 4950 02:00:21,009 --> 02:00:21,019 let's rename this function to save 4951 02:00:21,019 --> 02:00:25,399 let's rename this function to save underline user and rename the argument 4952 02:00:25,399 --> 02:00:25,409 underline user and rename the argument 4953 02:00:25,409 --> 02:00:28,580 underline user and rename the argument to user so let's imagine we're gonna use 4954 02:00:28,580 --> 02:00:28,590 to user so let's imagine we're gonna use 4955 02:00:28,590 --> 02:00:31,009 to user so let's imagine we're gonna use this function to save information about 4956 02:00:31,009 --> 02:00:31,019 this function to save information about 4957 02:00:31,019 --> 02:00:35,029 this function to save information about a user now in this function let's just 4958 02:00:35,029 --> 02:00:35,039 a user now in this function let's just 4959 02:00:35,039 --> 02:00:38,479 a user now in this function let's just print this user argument we're done with 4960 02:00:38,479 --> 02:00:38,489 print this user argument we're done with 4961 02:00:38,489 --> 02:00:40,580 print this user argument we're done with our function let's call it save 4962 02:00:40,580 --> 02:00:40,590 our function let's call it save 4963 02:00:40,590 --> 02:00:43,580 our function let's call it save underline user now instead of passing 4964 02:00:43,580 --> 02:00:43,590 underline user now instead of passing 4965 02:00:43,590 --> 02:00:46,189 underline user now instead of passing arbitrary arguments here we can pass 4966 02:00:46,189 --> 02:00:46,199 arbitrary arguments here we can pass 4967 02:00:46,199 --> 02:00:49,250 arbitrary arguments here we can pass arbitrary keyword arguments remember 4968 02:00:49,250 --> 02:00:49,260 arbitrary keyword arguments remember 4969 02:00:49,260 --> 02:00:52,219 arbitrary keyword arguments remember keyword arguments so we have name equals 4970 02:00:52,219 --> 02:00:52,229 keyword arguments so we have name equals 4971 02:00:52,229 --> 02:00:54,560 keyword arguments so we have name equals value so here we can add multiple 4972 02:00:54,560 --> 02:00:54,570 value so here we can add multiple 4973 02:00:54,570 --> 02:00:58,819 value so here we can add multiple keyword arguments like ID equals 1 name 4974 02:00:58,819 --> 02:00:58,829 keyword arguments like ID equals 1 name 4975 02:00:58,829 --> 02:01:03,979 keyword arguments like ID equals 1 name equals John age equals 22 and so on so 4976 02:01:03,979 --> 02:01:03,989 equals John age equals 22 and so on so 4977 02:01:03,989 --> 02:01:06,200 equals John age equals 22 and so on so we are passing 3 keyword arguments to 4978 02:01:06,200 --> 02:01:06,210 we are passing 3 keyword arguments to 4979 02:01:06,210 --> 02:01:08,649 we are passing 3 keyword arguments to this function now let's run this program 4980 02:01:08,649 --> 02:01:08,659 this function now let's run this program 4981 02:01:08,659 --> 02:01:11,569 this function now let's run this program this is what we get look at the syntax 4982 02:01:11,569 --> 02:01:11,579 this is what we get look at the syntax 4983 02:01:11,579 --> 02:01:14,540 this is what we get look at the syntax we have these curly braces and in 4984 02:01:14,540 --> 02:01:14,550 we have these curly braces and in 4985 02:01:14,550 --> 02:01:17,839 we have these curly braces and in between them we have multiple key value 4986 02:01:17,839 --> 02:01:17,849 between them we have multiple key value 4987 02:01:17,849 --> 02:01:20,750 between them we have multiple key value pairs so key colon value comma 4988 02:01:20,750 --> 02:01:20,760 pairs so key colon value comma 4989 02:01:20,760 --> 02:01:23,810 pairs so key colon value comma here's another key value pair and here 4990 02:01:23,810 --> 02:01:23,820 here's another key value pair and here 4991 02:01:23,820 --> 02:01:27,109 here's another key value pair and here is the last one this object you see here 4992 02:01:27,109 --> 02:01:27,119 is the last one this object you see here 4993 02:01:27,119 --> 02:01:28,729 is the last one this object you see here is called a dictionary 4994 02:01:28,729 --> 02:01:28,739 is called a dictionary 4995 02:01:28,739 --> 02:01:31,160 is called a dictionary it's another complex type or a data 4996 02:01:31,160 --> 02:01:31,170 it's another complex type or a data 4997 02:01:31,170 --> 02:01:33,109 it's another complex type or a data structure in Python and I'm going to 4998 02:01:33,109 --> 02:01:33,119 structure in Python and I'm going to 4999 02:01:33,119 --> 02:01:35,029 structure in Python and I'm going to talk about that in detail later in the 5000 02:01:35,029 --> 02:01:35,039 talk about that in detail later in the 5001 02:01:35,039 --> 02:01:37,279 talk about that in detail later in the course for now all I want you to take 5002 02:01:37,279 --> 02:01:37,289 course for now all I want you to take 5003 02:01:37,289 --> 02:01:40,250 course for now all I want you to take away is that when we use double asterisk 5004 02:01:40,250 --> 02:01:40,260 away is that when we use double asterisk 5005 02:01:40,260 --> 02:01:43,100 away is that when we use double asterisk here we can pass multiple key value 5006 02:01:43,100 --> 02:01:43,110 here we can pass multiple key value 5007 02:01:43,110 --> 02:01:45,469 here we can pass multiple key value pairs or multiple keyword arguments to a 5008 02:01:45,469 --> 02:01:45,479 pairs or multiple keyword arguments to a 5009 02:01:45,479 --> 02:01:47,899 pairs or multiple keyword arguments to a function and Python will automatically 5010 02:01:47,899 --> 02:01:47,909 function and Python will automatically 5011 02:01:47,909 --> 02:01:51,080 function and Python will automatically package them into a dictionary so this 5012 02:01:51,080 --> 02:01:51,090 package them into a dictionary so this 5013 02:01:51,090 --> 02:01:53,750 package them into a dictionary so this user object here is a dictionary now 5014 02:01:53,750 --> 02:01:53,760 user object here is a dictionary now 5015 02:01:53,760 --> 02:01:56,330 user object here is a dictionary now using the bracket notation we can get 5016 02:01:56,330 --> 02:01:56,340 using the bracket notation we can get 5017 02:01:56,340 --> 02:01:58,520 using the bracket notation we can get the value of various keys in this 5018 02:01:58,520 --> 02:01:58,530 the value of various keys in this 5019 02:01:58,530 --> 02:02:01,939 the value of various keys in this dictionary so we can print user square 5020 02:02:01,939 --> 02:02:01,949 dictionary so we can print user square 5021 02:02:01,949 --> 02:02:04,819 dictionary so we can print user square brackets we pass a string and this is 5022 02:02:04,819 --> 02:02:04,829 brackets we pass a string and this is 5023 02:02:04,829 --> 02:02:07,250 brackets we pass a string and this is the name of our key like ID let's run 5024 02:02:07,250 --> 02:02:07,260 the name of our key like ID let's run 5025 02:02:07,260 --> 02:02:10,549 the name of our key like ID let's run the program we get 1 or we can access 5026 02:02:10,549 --> 02:02:10,559 the program we get 1 or we can access 5027 02:02:10,559 --> 02:02:14,450 the program we get 1 or we can access the value of name key run 5028 02:02:14,450 --> 02:02:14,460 the value of name key run 5029 02:02:14,460 --> 02:02:17,420 the value of name key run program so name is John so this is how 5030 02:02:17,420 --> 02:02:17,430 program so name is John so this is how 5031 02:02:17,430 --> 02:02:25,380 program so name is John so this is how deeksha Mary's work 5032 02:02:25,380 --> 02:02:25,390 5033 02:02:25,390 --> 02:02:28,660 in programming we have a very important 5034 02:02:28,660 --> 02:02:28,670 in programming we have a very important 5035 02:02:28,670 --> 02:02:31,780 in programming we have a very important concept called scope which refers to the 5036 02:02:31,780 --> 02:02:31,790 concept called scope which refers to the 5037 02:02:31,790 --> 02:02:34,180 concept called scope which refers to the region of the code where a variable is 5038 02:02:34,180 --> 02:02:34,190 region of the code where a variable is 5039 02:02:34,190 --> 02:02:36,790 region of the code where a variable is defined so in this example we have this 5040 02:02:36,790 --> 02:02:36,800 defined so in this example we have this 5041 02:02:36,800 --> 02:02:39,310 defined so in this example we have this message variable the scope of this 5042 02:02:39,310 --> 02:02:39,320 message variable the scope of this 5043 02:02:39,320 --> 02:02:41,920 message variable the scope of this variable is the greet function it only 5044 02:02:41,920 --> 02:02:41,930 variable is the greet function it only 5045 02:02:41,930 --> 02:02:45,250 variable is the greet function it only exists inside of this function so if we 5046 02:02:45,250 --> 02:02:45,260 exists inside of this function so if we 5047 02:02:45,260 --> 02:02:47,800 exists inside of this function so if we go outside of this function and try to 5048 02:02:47,800 --> 02:02:47,810 go outside of this function and try to 5049 02:02:47,810 --> 02:02:51,340 go outside of this function and try to print message see what happens as soon 5050 02:02:51,340 --> 02:02:51,350 print message see what happens as soon 5051 02:02:51,350 --> 02:02:53,410 print message see what happens as soon as I save the change as we get this red 5052 02:02:53,410 --> 02:02:53,420 as I save the change as we get this red 5053 02:02:53,420 --> 02:02:56,110 as I save the change as we get this red underlined undefined variable message 5054 02:02:56,110 --> 02:02:56,120 underlined undefined variable message 5055 02:02:56,120 --> 02:03:00,550 underlined undefined variable message and if we run our program we get this 5056 02:03:00,550 --> 02:03:00,560 and if we run our program we get this 5057 02:03:00,560 --> 02:03:04,050 and if we run our program we get this name error named message is not defined 5058 02:03:04,050 --> 02:03:04,060 name error named message is not defined 5059 02:03:04,060 --> 02:03:06,820 name error named message is not defined the same rule applies to the parameters 5060 02:03:06,820 --> 02:03:06,830 the same rule applies to the parameters 5061 02:03:06,830 --> 02:03:09,130 the same rule applies to the parameters of our functions so if we add a name 5062 02:03:09,130 --> 02:03:09,140 of our functions so if we add a name 5063 02:03:09,140 --> 02:03:12,280 of our functions so if we add a name parameter here and then try to print it 5064 02:03:12,280 --> 02:03:12,290 parameter here and then try to print it 5065 02:03:12,290 --> 02:03:15,160 parameter here and then try to print it outside of the greet function we get the 5066 02:03:15,160 --> 02:03:15,170 outside of the greet function we get the 5067 02:03:15,170 --> 02:03:18,160 outside of the greet function we get the same error so the scope of the name and 5068 02:03:18,160 --> 02:03:18,170 same error so the scope of the name and 5069 02:03:18,170 --> 02:03:20,110 same error so the scope of the name and message variables are the greet function 5070 02:03:20,110 --> 02:03:20,120 message variables are the greet function 5071 02:03:20,120 --> 02:03:23,290 message variables are the greet function and we refer to these variables as local 5072 02:03:23,290 --> 02:03:23,300 and we refer to these variables as local 5073 02:03:23,300 --> 02:03:25,840 and we refer to these variables as local variables in this function they're local 5074 02:03:25,840 --> 02:03:25,850 variables in this function they're local 5075 02:03:25,850 --> 02:03:27,640 variables in this function they're local in this function which means they don't 5076 02:03:27,640 --> 02:03:27,650 in this function which means they don't 5077 02:03:27,650 --> 02:03:31,270 in this function which means they don't exist anywhere else and that means we 5078 02:03:31,270 --> 02:03:31,280 exist anywhere else and that means we 5079 02:03:31,280 --> 02:03:34,390 exist anywhere else and that means we can have another function let's say send 5080 02:03:34,390 --> 02:03:34,400 can have another function let's say send 5081 02:03:34,400 --> 02:03:37,480 can have another function let's say send email with a parameter with the same 5082 02:03:37,480 --> 02:03:37,490 email with a parameter with the same 5083 02:03:37,490 --> 02:03:40,890 email with a parameter with the same name here we can have a message variable 5084 02:03:40,890 --> 02:03:40,900 name here we can have a message variable 5085 02:03:40,900 --> 02:03:43,840 name here we can have a message variable but this message variable is completely 5086 02:03:43,840 --> 02:03:43,850 but this message variable is completely 5087 02:03:43,850 --> 02:03:45,970 but this message variable is completely different from the message variable we 5088 02:03:45,970 --> 02:03:45,980 different from the message variable we 5089 02:03:45,980 --> 02:03:48,250 different from the message variable we have in the greet function and of course 5090 02:03:48,250 --> 02:03:48,260 have in the greet function and of course 5091 02:03:48,260 --> 02:03:50,170 have in the greet function and of course the same rule applies to the named 5092 02:03:50,170 --> 02:03:50,180 the same rule applies to the named 5093 02:03:50,180 --> 02:03:52,300 the same rule applies to the named parameters in these functions they're 5094 02:03:52,300 --> 02:03:52,310 parameters in these functions they're 5095 02:03:52,310 --> 02:03:54,850 parameters in these functions they're completely separate these local 5096 02:03:54,850 --> 02:03:54,860 completely separate these local 5097 02:03:54,860 --> 02:03:56,680 completely separate these local variables have a short lifetime 5098 02:03:56,680 --> 02:03:56,690 variables have a short lifetime 5099 02:03:56,690 --> 02:04:00,460 variables have a short lifetime so when we call let's say the greet 5100 02:04:00,460 --> 02:04:00,470 so when we call let's say the greet 5101 02:04:00,470 --> 02:04:03,220 so when we call let's say the greet function and pass a name Python 5102 02:04:03,220 --> 02:04:03,230 function and pass a name Python 5103 02:04:03,230 --> 02:04:03,910 function and pass a name Python interpreter 5104 02:04:03,910 --> 02:04:03,920 interpreter 5105 02:04:03,920 --> 02:04:06,490 interpreter will allocate some memory and have the 5106 02:04:06,490 --> 02:04:06,500 will allocate some memory and have the 5107 02:04:06,500 --> 02:04:09,190 will allocate some memory and have the name and message variables reference 5108 02:04:09,190 --> 02:04:09,200 name and message variables reference 5109 02:04:09,200 --> 02:04:12,070 name and message variables reference those memory locations when we finish 5110 02:04:12,070 --> 02:04:12,080 those memory locations when we finish 5111 02:04:12,080 --> 02:04:14,260 those memory locations when we finish executing the greet function because 5112 02:04:14,260 --> 02:04:14,270 executing the greet function because 5113 02:04:14,270 --> 02:04:16,090 executing the greet function because these variables are not referenced or 5114 02:04:16,090 --> 02:04:16,100 these variables are not referenced or 5115 02:04:16,100 --> 02:04:18,370 these variables are not referenced or used anywhere else eventually they get 5116 02:04:18,370 --> 02:04:18,380 used anywhere else eventually they get 5117 02:04:18,380 --> 02:04:21,070 used anywhere else eventually they get garbage collector which means Python 5118 02:04:21,070 --> 02:04:21,080 garbage collector which means Python 5119 02:04:21,080 --> 02:04:23,470 garbage collector which means Python interpreter will release the memory that 5120 02:04:23,470 --> 02:04:23,480 interpreter will release the memory that 5121 02:04:23,480 --> 02:04:26,260 interpreter will release the memory that allocated for these variables so these 5122 02:04:26,260 --> 02:04:26,270 allocated for these variables so these 5123 02:04:26,270 --> 02:04:28,840 allocated for these variables so these are the local variables in contrast to 5124 02:04:28,840 --> 02:04:28,850 are the local variables in contrast to 5125 02:04:28,850 --> 02:04:31,330 are the local variables in contrast to local variables we have global variables 5126 02:04:31,330 --> 02:04:31,340 local variables we have global variables 5127 02:04:31,340 --> 02:04:34,060 local variables we have global variables so if we move this message variable 5128 02:04:34,060 --> 02:04:34,070 so if we move this message variable 5129 02:04:34,070 --> 02:04:35,980 so if we move this message variable outside of the 5130 02:04:35,980 --> 02:04:35,990 outside of the 5131 02:04:35,990 --> 02:04:37,960 outside of the great function now it's a global 5132 02:04:37,960 --> 02:04:37,970 great function now it's a global 5133 02:04:37,970 --> 02:04:40,180 great function now it's a global variable which means it's accessible 5134 02:04:40,180 --> 02:04:40,190 variable which means it's accessible 5135 02:04:40,190 --> 02:04:42,940 variable which means it's accessible anywhere in this file so the scope of 5136 02:04:42,940 --> 02:04:42,950 anywhere in this file so the scope of 5137 02:04:42,950 --> 02:04:45,400 anywhere in this file so the scope of this variable is this file we can use it 5138 02:04:45,400 --> 02:04:45,410 this variable is this file we can use it 5139 02:04:45,410 --> 02:04:47,260 this variable is this file we can use it anywhere in this file in any functions 5140 02:04:47,260 --> 02:04:47,270 anywhere in this file in any functions 5141 02:04:47,270 --> 02:04:49,750 anywhere in this file in any functions or outside of a function now for this 5142 02:04:49,750 --> 02:04:49,760 or outside of a function now for this 5143 02:04:49,760 --> 02:04:52,540 or outside of a function now for this reason global variables stay in memory 5144 02:04:52,540 --> 02:04:52,550 reason global variables stay in memory 5145 02:04:52,550 --> 02:04:54,610 reason global variables stay in memory for a longer period of time until they 5146 02:04:54,610 --> 02:04:54,620 for a longer period of time until they 5147 02:04:54,620 --> 02:04:56,830 for a longer period of time until they are garbage collected and you should not 5148 02:04:56,830 --> 02:04:56,840 are garbage collected and you should not 5149 02:04:56,840 --> 02:04:57,940 are garbage collected and you should not use them that often 5150 02:04:57,940 --> 02:04:57,950 use them that often 5151 02:04:57,950 --> 02:05:00,580 use them that often in fact global variables are really evil 5152 02:05:00,580 --> 02:05:00,590 in fact global variables are really evil 5153 02:05:00,590 --> 02:05:03,550 in fact global variables are really evil so as a best practice create functions 5154 02:05:03,550 --> 02:05:03,560 so as a best practice create functions 5155 02:05:03,560 --> 02:05:05,830 so as a best practice create functions with parameters and local variables 5156 02:05:05,830 --> 02:05:05,840 with parameters and local variables 5157 02:05:05,840 --> 02:05:08,850 with parameters and local variables now what if here in the greet function 5158 02:05:08,850 --> 02:05:08,860 now what if here in the greet function 5159 02:05:08,860 --> 02:05:13,600 now what if here in the greet function we set message to let's say B now let's 5160 02:05:13,600 --> 02:05:13,610 we set message to let's say B now let's 5161 02:05:13,610 --> 02:05:14,890 we set message to let's say B now let's delete this second function we don't 5162 02:05:14,890 --> 02:05:14,900 delete this second function we don't 5163 02:05:14,900 --> 02:05:17,140 delete this second function we don't really need it for now so we call the 5164 02:05:17,140 --> 02:05:17,150 really need it for now so we call the 5165 02:05:17,150 --> 02:05:19,150 really need it for now so we call the greet function in this function we 5166 02:05:19,150 --> 02:05:19,160 greet function in this function we 5167 02:05:19,160 --> 02:05:20,860 greet function in this function we assign a new value to the message 5168 02:05:20,860 --> 02:05:20,870 assign a new value to the message 5169 02:05:20,870 --> 02:05:24,640 assign a new value to the message variable now let's print this message 5170 02:05:24,640 --> 02:05:24,650 variable now let's print this message 5171 02:05:24,650 --> 02:05:27,550 variable now let's print this message and see what we get what do you think 5172 02:05:27,550 --> 02:05:27,560 and see what we get what do you think 5173 02:05:27,560 --> 02:05:29,940 and see what we get what do you think we're gonna get well let's take a look 5174 02:05:29,940 --> 02:05:29,950 we're gonna get well let's take a look 5175 02:05:29,950 --> 02:05:33,610 we're gonna get well let's take a look we get a but didn't we change the value 5176 02:05:33,610 --> 02:05:33,620 we get a but didn't we change the value 5177 02:05:33,620 --> 02:05:36,550 we get a but didn't we change the value of message variable to be not really 5178 02:05:36,550 --> 02:05:36,560 of message variable to be not really 5179 02:05:36,560 --> 02:05:39,220 of message variable to be not really because by default python interpreter 5180 02:05:39,220 --> 02:05:39,230 because by default python interpreter 5181 02:05:39,230 --> 02:05:41,710 because by default python interpreter treats this message variable as a local 5182 02:05:41,710 --> 02:05:41,720 treats this message variable as a local 5183 02:05:41,720 --> 02:05:43,720 treats this message variable as a local variable in the greet function even 5184 02:05:43,720 --> 02:05:43,730 variable in the greet function even 5185 02:05:43,730 --> 02:05:46,300 variable in the greet function even though it has the same name as the 5186 02:05:46,300 --> 02:05:46,310 though it has the same name as the 5187 02:05:46,310 --> 02:05:48,730 though it has the same name as the global variable that we have on line one 5188 02:05:48,730 --> 02:05:48,740 global variable that we have on line one 5189 02:05:48,740 --> 02:05:51,910 global variable that we have on line one so these two variables are separate now 5190 02:05:51,910 --> 02:05:51,920 so these two variables are separate now 5191 02:05:51,920 --> 02:05:53,770 so these two variables are separate now I've seen some tutorials or even books 5192 02:05:53,770 --> 02:05:53,780 I've seen some tutorials or even books 5193 02:05:53,780 --> 02:05:56,800 I've seen some tutorials or even books teaching you bad practices for example 5194 02:05:56,800 --> 02:05:56,810 teaching you bad practices for example 5195 02:05:56,810 --> 02:05:59,410 teaching you bad practices for example they show you how to modify the value of 5196 02:05:59,410 --> 02:05:59,420 they show you how to modify the value of 5197 02:05:59,420 --> 02:06:02,530 they show you how to modify the value of this global message variable inside of a 5198 02:06:02,530 --> 02:06:02,540 this global message variable inside of a 5199 02:06:02,540 --> 02:06:04,450 this global message variable inside of a function let me show you how to do that 5200 02:06:04,450 --> 02:06:04,460 function let me show you how to do that 5201 02:06:04,460 --> 02:06:07,300 function let me show you how to do that but remember this is a bad practice and 5202 02:06:07,300 --> 02:06:07,310 but remember this is a bad practice and 5203 02:06:07,310 --> 02:06:09,760 but remember this is a bad practice and you should avoid it at all times I will 5204 02:06:09,760 --> 02:06:09,770 you should avoid it at all times I will 5205 02:06:09,770 --> 02:06:12,250 you should avoid it at all times I will explain the reason in a second so these 5206 02:06:12,250 --> 02:06:12,260 explain the reason in a second so these 5207 02:06:12,260 --> 02:06:14,860 explain the reason in a second so these tutorials or books teach you to use the 5208 02:06:14,860 --> 02:06:14,870 tutorials or books teach you to use the 5209 02:06:14,870 --> 02:06:18,790 tutorials or books teach you to use the global keyword here and reference the 5210 02:06:18,790 --> 02:06:18,800 global keyword here and reference the 5211 02:06:18,800 --> 02:06:21,430 global keyword here and reference the message variable when python interpreter 5212 02:06:21,430 --> 02:06:21,440 message variable when python interpreter 5213 02:06:21,440 --> 02:06:24,100 message variable when python interpreter sees this line it will realize that in 5214 02:06:24,100 --> 02:06:24,110 sees this line it will realize that in 5215 02:06:24,110 --> 02:06:26,170 sees this line it will realize that in this function we want to use the global 5216 02:06:26,170 --> 02:06:26,180 this function we want to use the global 5217 02:06:26,180 --> 02:06:29,200 this function we want to use the global message variable so it will not define a 5218 02:06:29,200 --> 02:06:29,210 message variable so it will not define a 5219 02:06:29,210 --> 02:06:32,230 message variable so it will not define a local variable in this function now with 5220 02:06:32,230 --> 02:06:32,240 local variable in this function now with 5221 02:06:32,240 --> 02:06:35,800 local variable in this function now with this change if we run our program you 5222 02:06:35,800 --> 02:06:35,810 this change if we run our program you 5223 02:06:35,810 --> 02:06:37,810 this change if we run our program you can see we get beyond the terminal 5224 02:06:37,810 --> 02:06:37,820 can see we get beyond the terminal 5225 02:06:37,820 --> 02:06:39,390 can see we get beyond the terminal because in this function we are 5226 02:06:39,390 --> 02:06:39,400 because in this function we are 5227 02:06:39,400 --> 02:06:42,010 because in this function we are modifying the value of the global 5228 02:06:42,010 --> 02:06:42,020 modifying the value of the global 5229 02:06:42,020 --> 02:06:45,160 modifying the value of the global message variable why is this bad because 5230 02:06:45,160 --> 02:06:45,170 message variable why is this bad because 5231 02:06:45,170 --> 02:06:46,630 message variable why is this bad because it is possible that you might have 5232 02:06:46,630 --> 02:06:46,640 it is possible that you might have 5233 02:06:46,640 --> 02:06:49,630 it is possible that you might have multiple functions that rely on the 5234 02:06:49,630 --> 02:06:49,640 multiple functions that rely on the 5235 02:06:49,640 --> 02:06:51,940 multiple functions that rely on the of this global variable if you're 5236 02:06:51,940 --> 02:06:51,950 of this global variable if you're 5237 02:06:51,950 --> 02:06:54,850 of this global variable if you're accidentally or deliberately change the 5238 02:06:54,850 --> 02:06:54,860 accidentally or deliberately change the 5239 02:06:54,860 --> 02:06:56,950 accidentally or deliberately change the value of this global variable in one 5240 02:06:56,950 --> 02:06:56,960 value of this global variable in one 5241 02:06:56,960 --> 02:06:59,560 value of this global variable in one function this might have a side effect 5242 02:06:59,560 --> 02:06:59,570 function this might have a side effect 5243 02:06:59,570 --> 02:07:02,260 function this might have a side effect in other functions those functions may 5244 02:07:02,260 --> 02:07:02,270 in other functions those functions may 5245 02:07:02,270 --> 02:07:04,930 in other functions those functions may not behave properly and this way we can 5246 02:07:04,930 --> 02:07:04,940 not behave properly and this way we can 5247 02:07:04,940 --> 02:07:08,380 not behave properly and this way we can create a bug in our program so global 5248 02:07:08,380 --> 02:07:08,390 create a bug in our program so global 5249 02:07:08,390 --> 02:07:10,720 create a bug in our program so global variables have always been bad this is 5250 02:07:10,720 --> 02:07:10,730 variables have always been bad this is 5251 02:07:10,730 --> 02:07:12,730 variables have always been bad this is not a Python thing this is a discussion 5252 02:07:12,730 --> 02:07:12,740 not a Python thing this is a discussion 5253 02:07:12,740 --> 02:07:15,130 not a Python thing this is a discussion that's been going on for decades avoid 5254 02:07:15,130 --> 02:07:15,140 that's been going on for decades avoid 5255 02:07:15,140 --> 02:07:17,290 that's been going on for decades avoid them as much as you can or if there are 5256 02:07:17,290 --> 02:07:17,300 them as much as you can or if there are 5257 02:07:17,300 --> 02:07:18,850 them as much as you can or if there are situations that you really need to 5258 02:07:18,850 --> 02:07:18,860 situations that you really need to 5259 02:07:18,860 --> 02:07:20,920 situations that you really need to define a variable globally in a file 5260 02:07:20,920 --> 02:07:20,930 define a variable globally in a file 5261 02:07:20,930 --> 02:07:23,680 define a variable globally in a file that's okay but do not modify it in a 5262 02:07:23,680 --> 02:07:23,690 that's okay but do not modify it in a 5263 02:07:23,690 --> 02:07:25,240 that's okay but do not modify it in a function as you see here this is a 5264 02:07:25,240 --> 02:07:25,250 function as you see here this is a 5265 02:07:25,250 --> 02:07:28,330 function as you see here this is a really bad practice so that's all about 5266 02:07:28,330 --> 02:07:28,340 really bad practice so that's all about 5267 02:07:28,340 --> 02:07:37,060 really bad practice so that's all about local and global variables 5268 02:07:37,060 --> 02:07:37,070 5269 02:07:37,070 --> 02:07:39,710 in this lecture I'm going to show you 5270 02:07:39,710 --> 02:07:39,720 in this lecture I'm going to show you 5271 02:07:39,720 --> 02:07:42,290 in this lecture I'm going to show you how to find and fix bugs in your 5272 02:07:42,290 --> 02:07:42,300 how to find and fix bugs in your 5273 02:07:42,300 --> 02:07:44,480 how to find and fix bugs in your programs so here's the multiply function 5274 02:07:44,480 --> 02:07:44,490 programs so here's the multiply function 5275 02:07:44,490 --> 02:07:47,870 programs so here's the multiply function we wrote earlier let's add a couple of 5276 02:07:47,870 --> 02:07:47,880 we wrote earlier let's add a couple of 5277 02:07:47,880 --> 02:07:51,040 we wrote earlier let's add a couple of statements after this function so print 5278 02:07:51,040 --> 02:07:51,050 statements after this function so print 5279 02:07:51,050 --> 02:07:55,190 statements after this function so print start and then we'll call the multiply 5280 02:07:55,190 --> 02:07:55,200 start and then we'll call the multiply 5281 02:07:55,200 --> 02:07:59,030 start and then we'll call the multiply function give it three arguments one two 5282 02:07:59,030 --> 02:07:59,040 function give it three arguments one two 5283 02:07:59,040 --> 02:08:02,000 function give it three arguments one two and three so the result should be six 5284 02:08:02,000 --> 02:08:02,010 and three so the result should be six 5285 02:08:02,010 --> 02:08:04,490 and three so the result should be six and here we print the result 5286 02:08:04,490 --> 02:08:04,500 and here we print the result 5287 02:08:04,500 --> 02:08:07,460 and here we print the result on the terminal now to create a bug in 5288 02:08:07,460 --> 02:08:07,470 on the terminal now to create a bug in 5289 02:08:07,470 --> 02:08:09,520 on the terminal now to create a bug in this program I'm going to deliberately 5290 02:08:09,520 --> 02:08:09,530 this program I'm going to deliberately 5291 02:08:09,530 --> 02:08:13,190 this program I'm going to deliberately indent this return statement so now when 5292 02:08:13,190 --> 02:08:13,200 indent this return statement so now when 5293 02:08:13,200 --> 02:08:16,070 indent this return statement so now when we run this program instead of six we 5294 02:08:16,070 --> 02:08:16,080 we run this program instead of six we 5295 02:08:16,080 --> 02:08:19,490 we run this program instead of six we get one so we're gonna use a technique 5296 02:08:19,490 --> 02:08:19,500 get one so we're gonna use a technique 5297 02:08:19,500 --> 02:08:22,070 get one so we're gonna use a technique called debugging to find and fix this 5298 02:08:22,070 --> 02:08:22,080 called debugging to find and fix this 5299 02:08:22,080 --> 02:08:25,130 called debugging to find and fix this bug alright first we need to open the 5300 02:08:25,130 --> 02:08:25,140 bug alright first we need to open the 5301 02:08:25,140 --> 02:08:27,750 bug alright first we need to open the debugging panel 5302 02:08:27,750 --> 02:08:27,760 debugging panel 5303 02:08:27,760 --> 02:08:29,490 debugging panel the first time you want to use debugging 5304 02:08:29,490 --> 02:08:29,500 the first time you want to use debugging 5305 02:08:29,500 --> 02:08:31,800 the first time you want to use debugging in a Python project you need to click 5306 02:08:31,800 --> 02:08:31,810 in a Python project you need to click 5307 02:08:31,810 --> 02:08:35,190 in a Python project you need to click this icon this would generate a new file 5308 02:08:35,190 --> 02:08:35,200 this icon this would generate a new file 5309 02:08:35,200 --> 02:08:38,370 this icon this would generate a new file called launch the JSON in this file we 5310 02:08:38,370 --> 02:08:38,380 called launch the JSON in this file we 5311 02:08:38,380 --> 02:08:40,200 called launch the JSON in this file we have a bunch of debugging configuration 5312 02:08:40,200 --> 02:08:40,210 have a bunch of debugging configuration 5313 02:08:40,210 --> 02:08:42,570 have a bunch of debugging configuration you never have to touch any of this so 5314 02:08:42,570 --> 02:08:42,580 you never have to touch any of this so 5315 02:08:42,580 --> 02:08:45,090 you never have to touch any of this so don't worry about it close it you can 5316 02:08:45,090 --> 02:08:45,100 don't worry about it close it you can 5317 02:08:45,100 --> 02:08:47,790 don't worry about it close it you can see this file is placed inside of this 5318 02:08:47,790 --> 02:08:47,800 see this file is placed inside of this 5319 02:08:47,800 --> 02:08:50,250 see this file is placed inside of this vs code folder it's right here 5320 02:08:50,250 --> 02:08:50,260 vs code folder it's right here 5321 02:08:50,260 --> 02:08:53,040 vs code folder it's right here launched a JSON now when we have this 5322 02:08:53,040 --> 02:08:53,050 launched a JSON now when we have this 5323 02:08:53,050 --> 02:08:55,530 launched a JSON now when we have this file we can go to the debugging panel 5324 02:08:55,530 --> 02:08:55,540 file we can go to the debugging panel 5325 02:08:55,540 --> 02:08:59,400 file we can go to the debugging panel and from this list we can select a debug 5326 02:08:59,400 --> 02:08:59,410 and from this list we can select a debug 5327 02:08:59,410 --> 02:09:01,590 and from this list we can select a debug in configuration some of these 5328 02:09:01,590 --> 02:09:01,600 in configuration some of these 5329 02:09:01,600 --> 02:09:03,690 in configuration some of these configurations are useful for more 5330 02:09:03,690 --> 02:09:03,700 configurations are useful for more 5331 02:09:03,700 --> 02:09:06,210 configurations are useful for more complex applications for example we use 5332 02:09:06,210 --> 02:09:06,220 complex applications for example we use 5333 02:09:06,220 --> 02:09:09,180 complex applications for example we use Python Django to debug a web application 5334 02:09:09,180 --> 02:09:09,190 Python Django to debug a web application 5335 02:09:09,190 --> 02:09:12,240 Python Django to debug a web application built with Python for this course we're 5336 02:09:12,240 --> 02:09:12,250 built with Python for this course we're 5337 02:09:12,250 --> 02:09:15,060 built with Python for this course we're going to use Python current file with 5338 02:09:15,060 --> 02:09:15,070 going to use Python current file with 5339 02:09:15,070 --> 02:09:19,140 going to use Python current file with integrated terminal so select this now 5340 02:09:19,140 --> 02:09:19,150 integrated terminal so select this now 5341 02:09:19,150 --> 02:09:21,390 integrated terminal so select this now to start debugging first we need to add 5342 02:09:21,390 --> 02:09:21,400 to start debugging first we need to add 5343 02:09:21,400 --> 02:09:23,340 to start debugging first we need to add a breakpoint on one of these statements 5344 02:09:23,340 --> 02:09:23,350 a breakpoint on one of these statements 5345 02:09:23,350 --> 02:09:26,220 a breakpoint on one of these statements so I'm going to put the cursor on line 8 5346 02:09:26,220 --> 02:09:26,230 so I'm going to put the cursor on line 8 5347 02:09:26,230 --> 02:09:30,050 so I'm going to put the cursor on line 8 and insert a breakpoint by pressing f9 5348 02:09:30,050 --> 02:09:30,060 and insert a breakpoint by pressing f9 5349 02:09:30,060 --> 02:09:33,030 and insert a breakpoint by pressing f9 so this is a breakpoint we can press f9 5350 02:09:33,030 --> 02:09:33,040 so this is a breakpoint we can press f9 5351 02:09:33,040 --> 02:09:35,850 so this is a breakpoint we can press f9 one more time to remove it if you're on 5352 02:09:35,850 --> 02:09:35,860 one more time to remove it if you're on 5353 02:09:35,860 --> 02:09:37,770 one more time to remove it if you're on a Mac keyboard you should press the 5354 02:09:37,770 --> 02:09:37,780 a Mac keyboard you should press the 5355 02:09:37,780 --> 02:09:39,690 a Mac keyboard you should press the function key which is on the bottom left 5356 02:09:39,690 --> 02:09:39,700 function key which is on the bottom left 5357 02:09:39,700 --> 02:09:41,550 function key which is on the bottom left corner of your keyboard and then press 5358 02:09:41,550 --> 02:09:41,560 corner of your keyboard and then press 5359 02:09:41,560 --> 02:09:45,510 corner of your keyboard and then press f9 so here we have a breakpoint now we 5360 02:09:45,510 --> 02:09:45,520 f9 so here we have a breakpoint now we 5361 02:09:45,520 --> 02:09:48,960 f9 so here we have a breakpoint now we can press f5 to run the application up 5362 02:09:48,960 --> 02:09:48,970 can press f5 to run the application up 5363 02:09:48,970 --> 02:09:54,420 can press f5 to run the application up to this point so f5 so this 5364 02:09:54,420 --> 02:09:54,430 to this point so f5 so this 5365 02:09:54,430 --> 02:09:56,550 to this point so f5 so this automatically opens the integrated 5366 02:09:56,550 --> 02:09:56,560 automatically opens the integrated 5367 02:09:56,560 --> 02:09:58,620 automatically opens the integrated terminal here don't worry about this I'm 5368 02:09:58,620 --> 02:09:58,630 terminal here don't worry about this I'm 5369 02:09:58,630 --> 02:10:00,399 terminal here don't worry about this I'm going to close it 5370 02:10:00,399 --> 02:10:00,409 going to close it 5371 02:10:00,409 --> 02:10:02,800 going to close it so you can see our program is running up 5372 02:10:02,800 --> 02:10:02,810 so you can see our program is running up 5373 02:10:02,810 --> 02:10:05,169 so you can see our program is running up to this point this line is highlighted 5374 02:10:05,169 --> 02:10:05,179 to this point this line is highlighted 5375 02:10:05,179 --> 02:10:08,260 to this point this line is highlighted now we can execute this program line by 5376 02:10:08,260 --> 02:10:08,270 now we can execute this program line by 5377 02:10:08,270 --> 02:10:10,629 now we can execute this program line by line and see exactly what happens at 5378 02:10:10,629 --> 02:10:10,639 line and see exactly what happens at 5379 02:10:10,639 --> 02:10:14,169 line and see exactly what happens at runtime so to execute one statement at a 5380 02:10:14,169 --> 02:10:14,179 runtime so to execute one statement at a 5381 02:10:14,179 --> 02:10:19,300 runtime so to execute one statement at a time press f10 okay we are done now we 5382 02:10:19,300 --> 02:10:19,310 time press f10 okay we are done now we 5383 02:10:19,310 --> 02:10:20,560 time press f10 okay we are done now we are on line 9 5384 02:10:20,560 --> 02:10:20,570 are on line 9 5385 02:10:20,570 --> 02:10:23,439 are on line 9 however on line 9 you are calling the 5386 02:10:23,439 --> 02:10:23,449 however on line 9 you are calling the 5387 02:10:23,449 --> 02:10:26,649 however on line 9 you are calling the multiply function if we press f10 again 5388 02:10:26,649 --> 02:10:26,659 multiply function if we press f10 again 5389 02:10:26,659 --> 02:10:29,800 multiply function if we press f10 again the execution stops so we couldn't 5390 02:10:29,800 --> 02:10:29,810 the execution stops so we couldn't 5391 02:10:29,810 --> 02:10:32,709 the execution stops so we couldn't figure out why we got one as the result 5392 02:10:32,709 --> 02:10:32,719 figure out why we got one as the result 5393 02:10:32,719 --> 02:10:35,680 figure out why we got one as the result of multiplying these numbers so let's 5394 02:10:35,680 --> 02:10:35,690 of multiplying these numbers so let's 5395 02:10:35,690 --> 02:10:37,750 of multiplying these numbers so let's start debugging one more time we press 5396 02:10:37,750 --> 02:10:37,760 start debugging one more time we press 5397 02:10:37,760 --> 02:10:41,620 start debugging one more time we press f5 so once again we are on line 8 let's 5398 02:10:41,620 --> 02:10:41,630 f5 so once again we are on line 8 let's 5399 02:10:41,630 --> 02:10:45,760 f5 so once again we are on line 8 let's step over this line with f10 now this 5400 02:10:45,760 --> 02:10:45,770 step over this line with f10 now this 5401 02:10:45,770 --> 02:10:48,459 step over this line with f10 now this time we want to step into this multiply 5402 02:10:48,459 --> 02:10:48,469 time we want to step into this multiply 5403 02:10:48,469 --> 02:10:50,800 time we want to step into this multiply function so we see exactly what is going 5404 02:10:50,800 --> 02:10:50,810 function so we see exactly what is going 5405 02:10:50,810 --> 02:10:56,229 function so we see exactly what is going on here so instead of f10 press f11 now 5406 02:10:56,229 --> 02:10:56,239 on here so instead of f10 press f11 now 5407 02:10:56,239 --> 02:10:59,740 on here so instead of f10 press f11 now we are on line 2 so if you're calling a 5408 02:10:59,740 --> 02:10:59,750 we are on line 2 so if you're calling a 5409 02:10:59,750 --> 02:11:01,899 we are on line 2 so if you're calling a function that you have to find you can 5410 02:11:01,899 --> 02:11:01,909 function that you have to find you can 5411 02:11:01,909 --> 02:11:05,200 function that you have to find you can step into that function using f11 now 5412 02:11:05,200 --> 02:11:05,210 step into that function using f11 now 5413 02:11:05,210 --> 02:11:07,060 step into that function using f11 now here we are in the multiply function on 5414 02:11:07,060 --> 02:11:07,070 here we are in the multiply function on 5415 02:11:07,070 --> 02:11:09,820 here we are in the multiply function on the left side inside the variables panel 5416 02:11:09,820 --> 02:11:09,830 the left side inside the variables panel 5417 02:11:09,830 --> 02:11:11,560 the left side inside the variables panel you can see all the variables that are 5418 02:11:11,560 --> 02:11:11,570 you can see all the variables that are 5419 02:11:11,570 --> 02:11:14,200 you can see all the variables that are meaningful in this function so hungry 5420 02:11:14,200 --> 02:11:14,210 meaningful in this function so hungry 5421 02:11:14,210 --> 02:11:17,260 meaningful in this function so hungry locals we have numbers so this is our 5422 02:11:17,260 --> 02:11:17,270 locals we have numbers so this is our 5423 02:11:17,270 --> 02:11:19,899 locals we have numbers so this is our numbers argument you can see this is set 5424 02:11:19,899 --> 02:11:19,909 numbers argument you can see this is set 5425 02:11:19,909 --> 02:11:23,770 numbers argument you can see this is set to a topple with 3 numbers 1 2 3 right 5426 02:11:23,770 --> 02:11:23,780 to a topple with 3 numbers 1 2 3 right 5427 02:11:23,780 --> 02:11:26,290 to a topple with 3 numbers 1 2 3 right now our total variable is not in this 5428 02:11:26,290 --> 02:11:26,300 now our total variable is not in this 5429 02:11:26,300 --> 02:11:29,290 now our total variable is not in this list because it's not defined yet the 5430 02:11:29,290 --> 02:11:29,300 list because it's not defined yet the 5431 02:11:29,300 --> 02:11:31,979 list because it's not defined yet the moment we step over this line with f10 5432 02:11:31,979 --> 02:11:31,989 moment we step over this line with f10 5433 02:11:31,989 --> 02:11:35,080 moment we step over this line with f10 total comes to existence and you can see 5434 02:11:35,080 --> 02:11:35,090 total comes to existence and you can see 5435 02:11:35,090 --> 02:11:38,110 total comes to existence and you can see initially is set to 1 now we are at the 5436 02:11:38,110 --> 02:11:38,120 initially is set to 1 now we are at the 5437 02:11:38,120 --> 02:11:40,600 initially is set to 1 now we are at the beginning of our for loop let's press 5438 02:11:40,600 --> 02:11:40,610 beginning of our for loop let's press 5439 02:11:40,610 --> 02:11:42,840 beginning of our for loop let's press f10 one more time 5440 02:11:42,840 --> 02:11:42,850 f10 one more time 5441 02:11:42,850 --> 02:11:45,660 f10 one more time here we are we're going to multiply 5442 02:11:45,660 --> 02:11:45,670 here we are we're going to multiply 5443 02:11:45,670 --> 02:11:48,420 here we are we're going to multiply total by number so let's step over this 5444 02:11:48,420 --> 02:11:48,430 total by number so let's step over this 5445 02:11:48,430 --> 02:11:51,750 total by number so let's step over this line as well now at this point we have a 5446 02:11:51,750 --> 02:11:51,760 line as well now at this point we have a 5447 02:11:51,760 --> 02:11:55,140 line as well now at this point we have a new variable called number that is our 5448 02:11:55,140 --> 02:11:55,150 new variable called number that is our 5449 02:11:55,150 --> 02:11:57,980 new variable called number that is our loop variable initially it's set to 1 5450 02:11:57,980 --> 02:11:57,990 loop variable initially it's set to 1 5451 02:11:57,990 --> 02:12:00,720 loop variable initially it's set to 1 now here we are on line 5 5452 02:12:00,720 --> 02:12:00,730 now here we are on line 5 5453 02:12:00,730 --> 02:12:04,290 now here we are on line 5 if you press f10 we can see we jump out 5454 02:12:04,290 --> 02:12:04,300 if you press f10 we can see we jump out 5455 02:12:04,300 --> 02:12:06,780 if you press f10 we can see we jump out of this function so our loop did not 5456 02:12:06,780 --> 02:12:06,790 of this function so our loop did not 5457 02:12:06,790 --> 02:12:09,630 of this function so our loop did not execute to completion and that is the 5458 02:12:09,630 --> 02:12:09,640 execute to completion and that is the 5459 02:12:09,640 --> 02:12:12,930 execute to completion and that is the reason our program has a bug so to fix 5460 02:12:12,930 --> 02:12:12,940 reason our program has a bug so to fix 5461 02:12:12,940 --> 02:12:15,630 reason our program has a bug so to fix this I'm gonna stop the debugger with 5462 02:12:15,630 --> 02:12:15,640 this I'm gonna stop the debugger with 5463 02:12:15,640 --> 02:12:21,510 this I'm gonna stop the debugger with Shift + f5 now back here let's remove 5464 02:12:21,510 --> 02:12:21,520 Shift + f5 now back here let's remove 5465 02:12:21,520 --> 02:12:25,110 Shift + f5 now back here let's remove the indentation save the changes run the 5466 02:12:25,110 --> 02:12:25,120 the indentation save the changes run the 5467 02:12:25,120 --> 02:12:28,050 the indentation save the changes run the program in debug mode one more time so 5468 02:12:28,050 --> 02:12:28,060 program in debug mode one more time so 5469 02:12:28,060 --> 02:12:30,830 program in debug mode one more time so we press f5 5470 02:12:30,830 --> 02:12:30,840 we press f5 5471 02:12:30,840 --> 02:12:33,620 we press f5 here we are let's step over this with 5472 02:12:33,620 --> 02:12:33,630 here we are let's step over this with 5473 02:12:33,630 --> 02:12:37,910 here we are let's step over this with f10 now step into this with f11 and step 5474 02:12:37,910 --> 02:12:37,920 f10 now step into this with f11 and step 5475 02:12:37,920 --> 02:12:40,040 f10 now step into this with f11 and step over these lines with f10 a few more 5476 02:12:40,040 --> 02:12:40,050 over these lines with f10 a few more 5477 02:12:40,050 --> 02:12:44,930 over these lines with f10 a few more times so f10 one more time total it's 5478 02:12:44,930 --> 02:12:44,940 times so f10 one more time total it's 5479 02:12:44,940 --> 02:12:47,570 times so f10 one more time total it's set now we are in the second iteration 5480 02:12:47,570 --> 02:12:47,580 set now we are in the second iteration 5481 02:12:47,580 --> 02:12:50,300 set now we are in the second iteration let's press f10 one more time in this 5482 02:12:50,300 --> 02:12:50,310 let's press f10 one more time in this 5483 02:12:50,310 --> 02:12:52,640 let's press f10 one more time in this iteration you can see number is set to 5484 02:12:52,640 --> 02:12:52,650 iteration you can see number is set to 5485 02:12:52,650 --> 02:12:56,300 iteration you can see number is set to two our total is still one so let's step 5486 02:12:56,300 --> 02:12:56,310 two our total is still one so let's step 5487 02:12:56,310 --> 02:12:59,689 two our total is still one so let's step over this line as well now total is 5488 02:12:59,689 --> 02:12:59,699 over this line as well now total is 5489 02:12:59,699 --> 02:13:02,270 over this line as well now total is updated to two here we are at the 5490 02:13:02,270 --> 02:13:02,280 updated to two here we are at the 5491 02:13:02,280 --> 02:13:04,939 updated to two here we are at the beginning of the third iteration let's 5492 02:13:04,939 --> 02:13:04,949 beginning of the third iteration let's 5493 02:13:04,949 --> 02:13:07,129 beginning of the third iteration let's step over this line in this iteration 5494 02:13:07,129 --> 02:13:07,139 step over this line in this iteration 5495 02:13:07,139 --> 02:13:10,939 step over this line in this iteration number is three so after we execute this 5496 02:13:10,939 --> 02:13:10,949 number is three so after we execute this 5497 02:13:10,949 --> 02:13:13,760 number is three so after we execute this line because total is currently two when 5498 02:13:13,760 --> 02:13:13,770 line because total is currently two when 5499 02:13:13,770 --> 02:13:16,850 line because total is currently two when we multiply it by three we'll get 6 so 5500 02:13:16,850 --> 02:13:16,860 we multiply it by three we'll get 6 so 5501 02:13:16,860 --> 02:13:20,720 we multiply it by three we'll get 6 so f10 one more time now we only have three 5502 02:13:20,720 --> 02:13:20,730 f10 one more time now we only have three 5503 02:13:20,730 --> 02:13:23,390 f10 one more time now we only have three iterations in this loop so if you press 5504 02:13:23,390 --> 02:13:23,400 iterations in this loop so if you press 5505 02:13:23,400 --> 02:13:26,689 iterations in this loop so if you press f10 one more time our loop completes now 5506 02:13:26,689 --> 02:13:26,699 f10 one more time our loop completes now 5507 02:13:26,699 --> 02:13:28,399 f10 one more time our loop completes now we are ready to return total which is 5508 02:13:28,399 --> 02:13:28,409 we are ready to return total which is 5509 02:13:28,409 --> 02:13:33,050 we are ready to return total which is currently six so f10 we are on line nine 5510 02:13:33,050 --> 02:13:33,060 currently six so f10 we are on line nine 5511 02:13:33,060 --> 02:13:37,490 currently six so f10 we are on line nine and we're done now one more tip in this 5512 02:13:37,490 --> 02:13:37,500 and we're done now one more tip in this 5513 02:13:37,500 --> 02:13:40,040 and we're done now one more tip in this demo I put the breakpoint on the first 5514 02:13:40,040 --> 02:13:40,050 demo I put the breakpoint on the first 5515 02:13:40,050 --> 02:13:41,839 demo I put the breakpoint on the first line of the program you don't always 5516 02:13:41,839 --> 02:13:41,849 line of the program you don't always 5517 02:13:41,849 --> 02:13:44,300 line of the program you don't always have to do this for example here we know 5518 02:13:44,300 --> 02:13:44,310 have to do this for example here we know 5519 02:13:44,310 --> 02:13:47,060 have to do this for example here we know that our multiply function has a bug so 5520 02:13:47,060 --> 02:13:47,070 that our multiply function has a bug so 5521 02:13:47,070 --> 02:13:48,830 that our multiply function has a bug so instead of putting the breakpoint on 5522 02:13:48,830 --> 02:13:48,840 instead of putting the breakpoint on 5523 02:13:48,840 --> 02:13:52,629 instead of putting the breakpoint on line eight we could put it on line two 5524 02:13:52,629 --> 02:13:52,639 line eight we could put it on line two 5525 02:13:52,639 --> 02:13:55,370 line eight we could put it on line two so when we start the program in debug 5526 02:13:55,370 --> 02:13:55,380 so when we start the program in debug 5527 02:13:55,380 --> 02:14:00,020 so when we start the program in debug mode with f5 we immediately start in the 5528 02:14:00,020 --> 02:14:00,030 mode with f5 we immediately start in the 5529 02:14:00,030 --> 02:14:02,629 mode with f5 we immediately start in the multiply function and one more tip 5530 02:14:02,629 --> 02:14:02,639 multiply function and one more tip 5531 02:14:02,639 --> 02:14:04,700 multiply function and one more tip before we finish this lecture if you 5532 02:14:04,700 --> 02:14:04,710 before we finish this lecture if you 5533 02:14:04,710 --> 02:14:06,770 before we finish this lecture if you step into a function and you know that 5534 02:14:06,770 --> 02:14:06,780 step into a function and you know that 5535 02:14:06,780 --> 02:14:09,020 step into a function and you know that that function works properly we can 5536 02:14:09,020 --> 02:14:09,030 that function works properly we can 5537 02:14:09,030 --> 02:14:11,060 that function works properly we can immediately step out of that function 5538 02:14:11,060 --> 02:14:11,070 immediately step out of that function 5539 02:14:11,070 --> 02:14:15,229 immediately step out of that function with Shift + f11 so you don't have to 5540 02:14:15,229 --> 02:14:15,239 with Shift + f11 so you don't have to 5541 02:14:15,239 --> 02:14:17,750 with Shift + f11 so you don't have to execute the entire function line by line 5542 02:14:17,750 --> 02:14:17,760 execute the entire function line by line 5543 02:14:17,760 --> 02:14:21,500 execute the entire function line by line you can press shift and f11 to step out 5544 02:14:21,500 --> 02:14:21,510 you can press shift and f11 to step out 5545 02:14:21,510 --> 02:14:29,750 you can press shift and f11 to step out of that function 5546 02:14:29,750 --> 02:14:29,760 5547 02:14:29,760 --> 02:14:32,400 alright let's finish up this section by 5548 02:14:32,400 --> 02:14:32,410 alright let's finish up this section by 5549 02:14:32,410 --> 02:14:34,560 alright let's finish up this section by looking at a few very useful shortcuts 5550 02:14:34,560 --> 02:14:34,570 looking at a few very useful shortcuts 5551 02:14:34,570 --> 02:14:37,050 looking at a few very useful shortcuts for writing code fast first I'm going to 5552 02:14:37,050 --> 02:14:37,060 for writing code fast first I'm going to 5553 02:14:37,060 --> 02:14:39,030 for writing code fast first I'm going to show you the shortcuts for Windows users 5554 02:14:39,030 --> 02:14:39,040 show you the shortcuts for Windows users 5555 02:14:39,040 --> 02:14:40,920 show you the shortcuts for Windows users and in the next lecture we will look at 5556 02:14:40,920 --> 02:14:40,930 and in the next lecture we will look at 5557 02:14:40,930 --> 02:14:43,200 and in the next lecture we will look at the shortcuts for Mac so if you're a Mac 5558 02:14:43,200 --> 02:14:43,210 the shortcuts for Mac so if you're a Mac 5559 02:14:43,210 --> 02:14:46,050 the shortcuts for Mac so if you're a Mac user feel free to skip this lecture so 5560 02:14:46,050 --> 02:14:46,060 user feel free to skip this lecture so 5561 02:14:46,060 --> 02:14:48,030 user feel free to skip this lecture so here we are on line 9 and my cursor is 5562 02:14:48,030 --> 02:14:48,040 here we are on line 9 and my cursor is 5563 02:14:48,040 --> 02:14:50,520 here we are on line 9 and my cursor is right at the beginning of the line let's 5564 02:14:50,520 --> 02:14:50,530 right at the beginning of the line let's 5565 02:14:50,530 --> 02:14:51,750 right at the beginning of the line let's say you want to move the cursor to the 5566 02:14:51,750 --> 02:14:51,760 say you want to move the cursor to the 5567 02:14:51,760 --> 02:14:53,820 say you want to move the cursor to the end of the line instead of pressing the 5568 02:14:53,820 --> 02:14:53,830 end of the line instead of pressing the 5569 02:14:53,830 --> 02:14:56,070 end of the line instead of pressing the right arrow to go all the way to the end 5570 02:14:56,070 --> 02:14:56,080 right arrow to go all the way to the end 5571 02:14:56,080 --> 02:14:59,460 right arrow to go all the way to the end we can simply press the end key and here 5572 02:14:59,460 --> 02:14:59,470 we can simply press the end key and here 5573 02:14:59,470 --> 02:15:01,530 we can simply press the end key and here is the cursor or if you want to move the 5574 02:15:01,530 --> 02:15:01,540 is the cursor or if you want to move the 5575 02:15:01,540 --> 02:15:02,910 is the cursor or if you want to move the cursor to the beginning of the line 5576 02:15:02,910 --> 02:15:02,920 cursor to the beginning of the line 5577 02:15:02,920 --> 02:15:06,170 cursor to the beginning of the line simply press the HOME key there you go 5578 02:15:06,170 --> 02:15:06,180 simply press the HOME key there you go 5579 02:15:06,180 --> 02:15:08,190 simply press the HOME key there you go similarly if you want to move the cursor 5580 02:15:08,190 --> 02:15:08,200 similarly if you want to move the cursor 5581 02:15:08,200 --> 02:15:10,770 similarly if you want to move the cursor to the beginning of the file press ctrl 5582 02:15:10,770 --> 02:15:10,780 to the beginning of the file press ctrl 5583 02:15:10,780 --> 02:15:15,690 to the beginning of the file press ctrl + home here it is or ctrl + end/2 go to 5584 02:15:15,690 --> 02:15:15,700 + home here it is or ctrl + end/2 go to 5585 02:15:15,700 --> 02:15:18,000 + home here it is or ctrl + end/2 go to the end of the file now let's say we 5586 02:15:18,000 --> 02:15:18,010 the end of the file now let's say we 5587 02:15:18,010 --> 02:15:20,130 the end of the file now let's say we want to move this line up instead of 5588 02:15:20,130 --> 02:15:20,140 want to move this line up instead of 5589 02:15:20,140 --> 02:15:22,650 want to move this line up instead of cutting it from here and then copying it 5590 02:15:22,650 --> 02:15:22,660 cutting it from here and then copying it 5591 02:15:22,660 --> 02:15:25,410 cutting it from here and then copying it somewhere else we can simply move it up 5592 02:15:25,410 --> 02:15:25,420 somewhere else we can simply move it up 5593 02:15:25,420 --> 02:15:29,880 somewhere else we can simply move it up by pressing Alt + the up or down arrows 5594 02:15:29,880 --> 02:15:29,890 by pressing Alt + the up or down arrows 5595 02:15:29,890 --> 02:15:32,220 by pressing Alt + the up or down arrows or if you want to move these two lines 5596 02:15:32,220 --> 02:15:32,230 or if you want to move these two lines 5597 02:15:32,230 --> 02:15:34,560 or if you want to move these two lines up and down simply select them then hold 5598 02:15:34,560 --> 02:15:34,570 up and down simply select them then hold 5599 02:15:34,570 --> 02:15:38,610 up and down simply select them then hold alt and then up or down very easy now if 5600 02:15:38,610 --> 02:15:38,620 alt and then up or down very easy now if 5601 02:15:38,620 --> 02:15:40,200 alt and then up or down very easy now if you want to duplicate a line or multiple 5602 02:15:40,200 --> 02:15:40,210 you want to duplicate a line or multiple 5603 02:15:40,210 --> 02:15:43,530 you want to duplicate a line or multiple lines simply select them now hold down 5604 02:15:43,530 --> 02:15:43,540 lines simply select them now hold down 5605 02:15:43,540 --> 02:15:47,640 lines simply select them now hold down shift alt and then press the down key we 5606 02:15:47,640 --> 02:15:47,650 shift alt and then press the down key we 5607 02:15:47,650 --> 02:15:49,530 shift alt and then press the down key we can duplicate it as many times as you 5608 02:15:49,530 --> 02:15:49,540 can duplicate it as many times as you 5609 02:15:49,540 --> 02:15:52,710 can duplicate it as many times as you want there you go here's another useful 5610 02:15:52,710 --> 02:15:52,720 want there you go here's another useful 5611 02:15:52,720 --> 02:15:55,200 want there you go here's another useful shortcut if you want to convert this 5612 02:15:55,200 --> 02:15:55,210 shortcut if you want to convert this 5613 02:15:55,210 --> 02:15:56,970 shortcut if you want to convert this line or maybe these two lines into a 5614 02:15:56,970 --> 02:15:56,980 line or maybe these two lines into a 5615 02:15:56,980 --> 02:15:59,430 line or maybe these two lines into a comment simply hold down control and 5616 02:15:59,430 --> 02:15:59,440 comment simply hold down control and 5617 02:15:59,440 --> 02:16:03,420 comment simply hold down control and press slash using the same shortcut you 5618 02:16:03,420 --> 02:16:03,430 press slash using the same shortcut you 5619 02:16:03,430 --> 02:16:05,370 press slash using the same shortcut you can remove the comment so you can toggle 5620 02:16:05,370 --> 02:16:05,380 can remove the comment so you can toggle 5621 02:16:05,380 --> 02:16:08,280 can remove the comment so you can toggle it very easy and finally if you want to 5622 02:16:08,280 --> 02:16:08,290 it very easy and finally if you want to 5623 02:16:08,290 --> 02:16:10,140 it very easy and finally if you want to type the name of a variable or a 5624 02:16:10,140 --> 02:16:10,150 type the name of a variable or a 5625 02:16:10,150 --> 02:16:13,050 type the name of a variable or a function like multiplied you don't have 5626 02:16:13,050 --> 02:16:13,060 function like multiplied you don't have 5627 02:16:13,060 --> 02:16:15,690 function like multiplied you don't have to type all characters here are a few 5628 02:16:15,690 --> 02:16:15,700 to type all characters here are a few 5629 02:16:15,700 --> 02:16:18,420 to type all characters here are a few ways to type this quickly we can just 5630 02:16:18,420 --> 02:16:18,430 ways to type this quickly we can just 5631 02:16:18,430 --> 02:16:20,970 ways to type this quickly we can just type the first few characters and here 5632 02:16:20,970 --> 02:16:20,980 type the first few characters and here 5633 02:16:20,980 --> 02:16:23,070 type the first few characters and here in the intellisense you can see that so 5634 02:16:23,070 --> 02:16:23,080 in the intellisense you can see that so 5635 02:16:23,080 --> 02:16:25,440 in the intellisense you can see that so if you press ENTER this is what we call 5636 02:16:25,440 --> 02:16:25,450 if you press ENTER this is what we call 5637 02:16:25,450 --> 02:16:28,440 if you press ENTER this is what we call auto-completion here's another way so 5638 02:16:28,440 --> 02:16:28,450 auto-completion here's another way so 5639 02:16:28,450 --> 02:16:31,020 auto-completion here's another way so instead of writing the first few letters 5640 02:16:31,020 --> 02:16:31,030 instead of writing the first few letters 5641 02:16:31,030 --> 02:16:33,480 instead of writing the first few letters you can just pick any letters in 5642 02:16:33,480 --> 02:16:33,490 you can just pick any letters in 5643 02:16:33,490 --> 02:16:36,680 you can just pick any letters in sequence and type them so I can type mty 5644 02:16:36,680 --> 02:16:36,690 sequence and type them so I can type mty 5645 02:16:36,690 --> 02:16:39,240 sequence and type them so I can type mty or I can just type mpy 5646 02:16:39,240 --> 02:16:39,250 or I can just type mpy 5647 02:16:39,250 --> 02:16:40,410 or I can just type mpy or 5648 02:16:40,410 --> 02:16:40,420 or 5649 02:16:40,420 --> 02:16:43,379 or why there you go here it is so I hope 5650 02:16:43,379 --> 02:16:43,389 why there you go here it is so I hope 5651 02:16:43,389 --> 02:16:45,330 why there you go here it is so I hope you enjoyed these shortcuts and thank 5652 02:16:45,330 --> 02:16:45,340 you enjoyed these shortcuts and thank 5653 02:16:45,340 --> 02:16:53,230 you enjoyed these shortcuts and thank you for watching 5654 02:16:53,230 --> 02:16:53,240 5655 02:16:53,240 --> 02:16:55,340 alright now let's take a look at the 5656 02:16:55,340 --> 02:16:55,350 alright now let's take a look at the 5657 02:16:55,350 --> 02:16:58,280 alright now let's take a look at the shortcuts for a Mac keyboard so here we 5658 02:16:58,280 --> 02:16:58,290 shortcuts for a Mac keyboard so here we 5659 02:16:58,290 --> 02:17:01,010 shortcuts for a Mac keyboard so here we are on line 9 and my cursor is right at 5660 02:17:01,010 --> 02:17:01,020 are on line 9 and my cursor is right at 5661 02:17:01,020 --> 02:17:03,020 are on line 9 and my cursor is right at the beginning of the line if you want to 5662 02:17:03,020 --> 02:17:03,030 the beginning of the line if you want to 5663 02:17:03,030 --> 02:17:04,640 the beginning of the line if you want to move the cursor to the end of the line 5664 02:17:04,640 --> 02:17:04,650 move the cursor to the end of the line 5665 02:17:04,650 --> 02:17:07,160 move the cursor to the end of the line instead of using the right arrow to go 5666 02:17:07,160 --> 02:17:07,170 instead of using the right arrow to go 5667 02:17:07,170 --> 02:17:10,010 instead of using the right arrow to go all the way simply hold down the 5668 02:17:10,010 --> 02:17:10,020 all the way simply hold down the 5669 02:17:10,020 --> 02:17:13,160 all the way simply hold down the function key and press right here it is 5670 02:17:13,160 --> 02:17:13,170 function key and press right here it is 5671 02:17:13,170 --> 02:17:16,669 function key and press right here it is or you can press function and left to 5672 02:17:16,669 --> 02:17:16,679 or you can press function and left to 5673 02:17:16,679 --> 02:17:18,040 or you can press function and left to jump to the beginning of the line 5674 02:17:18,040 --> 02:17:18,050 jump to the beginning of the line 5675 02:17:18,050 --> 02:17:20,830 jump to the beginning of the line similarly you can press function and up 5676 02:17:20,830 --> 02:17:20,840 similarly you can press function and up 5677 02:17:20,840 --> 02:17:24,200 similarly you can press function and up to go to the top of the file or function 5678 02:17:24,200 --> 02:17:24,210 to go to the top of the file or function 5679 02:17:24,210 --> 02:17:27,010 to go to the top of the file or function and down to jump to the end of the file 5680 02:17:27,010 --> 02:17:27,020 and down to jump to the end of the file 5681 02:17:27,020 --> 02:17:29,780 and down to jump to the end of the file pretty useful now let's say you want to 5682 02:17:29,780 --> 02:17:29,790 pretty useful now let's say you want to 5683 02:17:29,790 --> 02:17:32,510 pretty useful now let's say you want to move this line up instead of cutting it 5684 02:17:32,510 --> 02:17:32,520 move this line up instead of cutting it 5685 02:17:32,520 --> 02:17:34,430 move this line up instead of cutting it from here and then copying it somewhere 5686 02:17:34,430 --> 02:17:34,440 from here and then copying it somewhere 5687 02:17:34,440 --> 02:17:36,890 from here and then copying it somewhere else you can simply move it up by 5688 02:17:36,890 --> 02:17:36,900 else you can simply move it up by 5689 02:17:36,900 --> 02:17:39,680 else you can simply move it up by holding down alt or option and then 5690 02:17:39,680 --> 02:17:39,690 holding down alt or option and then 5691 02:17:39,690 --> 02:17:43,340 holding down alt or option and then pressing the up arrow or down very easy 5692 02:17:43,340 --> 02:17:43,350 pressing the up arrow or down very easy 5693 02:17:43,350 --> 02:17:45,980 pressing the up arrow or down very easy or we can select these two lines hold 5694 02:17:45,980 --> 02:17:45,990 or we can select these two lines hold 5695 02:17:45,990 --> 02:17:49,070 or we can select these two lines hold down the alt or option key move it up or 5696 02:17:49,070 --> 02:17:49,080 down the alt or option key move it up or 5697 02:17:49,080 --> 02:17:52,640 down the alt or option key move it up or down here's another useful shortcut we 5698 02:17:52,640 --> 02:17:52,650 down here's another useful shortcut we 5699 02:17:52,650 --> 02:17:54,290 down here's another useful shortcut we can convert these two lines into a 5700 02:17:54,290 --> 02:17:54,300 can convert these two lines into a 5701 02:17:54,300 --> 02:17:56,930 can convert these two lines into a comment by pressing command and slash 5702 02:17:56,930 --> 02:17:56,940 comment by pressing command and slash 5703 02:17:56,940 --> 02:17:59,390 comment by pressing command and slash and then we can remove the comment using 5704 02:17:59,390 --> 02:17:59,400 and then we can remove the comment using 5705 02:17:59,400 --> 02:18:02,450 and then we can remove the comment using the same shortcut so we can toggle it 5706 02:18:02,450 --> 02:18:02,460 the same shortcut so we can toggle it 5707 02:18:02,460 --> 02:18:05,180 the same shortcut so we can toggle it and finally if you want to type the name 5708 02:18:05,180 --> 02:18:05,190 and finally if you want to type the name 5709 02:18:05,190 --> 02:18:06,950 and finally if you want to type the name of a variable or a function like 5710 02:18:06,950 --> 02:18:06,960 of a variable or a function like 5711 02:18:06,960 --> 02:18:09,260 of a variable or a function like multiply you don't have to type all the 5712 02:18:09,260 --> 02:18:09,270 multiply you don't have to type all the 5713 02:18:09,270 --> 02:18:12,040 multiply you don't have to type all the letters like multiply that is very slow 5714 02:18:12,040 --> 02:18:12,050 letters like multiply that is very slow 5715 02:18:12,050 --> 02:18:14,450 letters like multiply that is very slow you can type the first few letters like 5716 02:18:14,450 --> 02:18:14,460 you can type the first few letters like 5717 02:18:14,460 --> 02:18:17,180 you can type the first few letters like mult and here in the intellisense you 5718 02:18:17,180 --> 02:18:17,190 mult and here in the intellisense you 5719 02:18:17,190 --> 02:18:19,600 mult and here in the intellisense you can see it's selected so press Enter or 5720 02:18:19,600 --> 02:18:19,610 can see it's selected so press Enter or 5721 02:18:19,610 --> 02:18:22,640 can see it's selected so press Enter or you can pick any characters in sequence 5722 02:18:22,640 --> 02:18:22,650 you can pick any characters in sequence 5723 02:18:22,650 --> 02:18:26,990 you can pick any characters in sequence and type them like mty here it is or we 5724 02:18:26,990 --> 02:18:27,000 and type them like mty here it is or we 5725 02:18:27,000 --> 02:18:31,790 and type them like mty here it is or we can type an py or m TP so you can 5726 02:18:31,790 --> 02:18:31,800 can type an py or m TP so you can 5727 02:18:31,800 --> 02:18:34,430 can type an py or m TP so you can abbreviate it any way you want I hope 5728 02:18:34,430 --> 02:18:34,440 abbreviate it any way you want I hope 5729 02:18:34,440 --> 02:18:36,290 abbreviate it any way you want I hope you enjoyed these shortcuts and thank 5730 02:18:36,290 --> 02:18:36,300 you enjoyed these shortcuts and thank 5731 02:18:36,300 --> 02:18:44,340 you enjoyed these shortcuts and thank you for watching 5732 02:18:44,340 --> 02:18:44,350 5733 02:18:44,350 --> 02:18:47,110 one of the questions that often comes in 5734 02:18:47,110 --> 02:18:47,120 one of the questions that often comes in 5735 02:18:47,120 --> 02:18:49,650 one of the questions that often comes in programming interviews is the fizzbuzz 5736 02:18:49,650 --> 02:18:49,660 programming interviews is the fizzbuzz 5737 02:18:49,660 --> 02:18:52,120 programming interviews is the fizzbuzz algorithm you might be surprised that 5738 02:18:52,120 --> 02:18:52,130 algorithm you might be surprised that 5739 02:18:52,130 --> 02:18:53,800 algorithm you might be surprised that there are a lot of developers out there 5740 02:18:53,800 --> 02:18:53,810 there are a lot of developers out there 5741 02:18:53,810 --> 02:18:56,350 there are a lot of developers out there with even years of experience but they 5742 02:18:56,350 --> 02:18:56,360 with even years of experience but they 5743 02:18:56,360 --> 02:18:58,120 with even years of experience but they don't know how to solve this simple 5744 02:18:58,120 --> 02:18:58,130 don't know how to solve this simple 5745 02:18:58,130 --> 02:19:00,850 don't know how to solve this simple programming problem that's why I decided 5746 02:19:00,850 --> 02:19:00,860 programming problem that's why I decided 5747 02:19:00,860 --> 02:19:03,160 programming problem that's why I decided to include this in my course so let's 5748 02:19:03,160 --> 02:19:03,170 to include this in my course so let's 5749 02:19:03,170 --> 02:19:05,350 to include this in my course so let's see how this algorithm works and then 5750 02:19:05,350 --> 02:19:05,360 see how this algorithm works and then 5751 02:19:05,360 --> 02:19:07,660 see how this algorithm works and then you can spend 10 to 15 minutes on this 5752 02:19:07,660 --> 02:19:07,670 you can spend 10 to 15 minutes on this 5753 02:19:07,670 --> 02:19:10,000 you can spend 10 to 15 minutes on this exercise on your own so here we have a 5754 02:19:10,000 --> 02:19:10,010 exercise on your own so here we have a 5755 02:19:10,010 --> 02:19:13,090 exercise on your own so here we have a function fizz buzz that takes an input 5756 02:19:13,090 --> 02:19:13,100 function fizz buzz that takes an input 5757 02:19:13,100 --> 02:19:15,700 function fizz buzz that takes an input and depending on the input we give it it 5758 02:19:15,700 --> 02:19:15,710 and depending on the input we give it it 5759 02:19:15,710 --> 02:19:18,820 and depending on the input we give it it returns different results here are the 5760 02:19:18,820 --> 02:19:18,830 returns different results here are the 5761 02:19:18,830 --> 02:19:21,250 returns different results here are the rules if the input that we give it is 5762 02:19:21,250 --> 02:19:21,260 rules if the input that we give it is 5763 02:19:21,260 --> 02:19:24,490 rules if the input that we give it is divisible by 3 it will return the string 5764 02:19:24,490 --> 02:19:24,500 divisible by 3 it will return the string 5765 02:19:24,500 --> 02:19:25,360 divisible by 3 it will return the string fizz 5766 02:19:25,360 --> 02:19:25,370 fizz 5767 02:19:25,370 --> 02:19:27,670 fizz let me show you so we run this program 5768 02:19:27,670 --> 02:19:27,680 let me show you so we run this program 5769 02:19:27,680 --> 02:19:29,380 let me show you so we run this program we get fizz 5770 02:19:29,380 --> 02:19:29,390 we get fizz 5771 02:19:29,390 --> 02:19:33,310 we get fizz if the input is divisible by 5 it will 5772 02:19:33,310 --> 02:19:33,320 if the input is divisible by 5 it will 5773 02:19:33,320 --> 02:19:37,720 if the input is divisible by 5 it will return buzz take a look here's buzz now 5774 02:19:37,720 --> 02:19:37,730 return buzz take a look here's buzz now 5775 02:19:37,730 --> 02:19:40,210 return buzz take a look here's buzz now the third rule if the input is divisible 5776 02:19:40,210 --> 02:19:40,220 the third rule if the input is divisible 5777 02:19:40,220 --> 02:19:45,640 the third rule if the input is divisible by both 3 & 5 it will return fizzbuzz so 5778 02:19:45,640 --> 02:19:45,650 by both 3 & 5 it will return fizzbuzz so 5779 02:19:45,650 --> 02:19:50,100 by both 3 & 5 it will return fizzbuzz so let's pass 15 here we'll get fizzbuzz 5780 02:19:50,100 --> 02:19:50,110 let's pass 15 here we'll get fizzbuzz 5781 02:19:50,110 --> 02:19:53,440 let's pass 15 here we'll get fizzbuzz for any other numbers it will return the 5782 02:19:53,440 --> 02:19:53,450 for any other numbers it will return the 5783 02:19:53,450 --> 02:19:56,830 for any other numbers it will return the same input so if I pass 7 it's not 5784 02:19:56,830 --> 02:19:56,840 same input so if I pass 7 it's not 5785 02:19:56,840 --> 02:20:01,751 same input so if I pass 7 it's not divisible by 3 or 5 it will return 7 5786 02:20:01,751 --> 02:20:01,761 divisible by 3 or 5 it will return 7 5787 02:20:01,761 --> 02:20:05,470 divisible by 3 or 5 it will return 7 itself so spend 10 to 15 minutes on this 5788 02:20:05,470 --> 02:20:05,480 itself so spend 10 to 15 minutes on this 5789 02:20:05,480 --> 02:20:14,480 itself so spend 10 to 15 minutes on this exercise you will see my solution next 5790 02:20:14,480 --> 02:20:14,490 5791 02:20:14,490 --> 02:20:16,711 all right let's see how we can solve 5792 02:20:16,711 --> 02:20:16,721 all right let's see how we can solve 5793 02:20:16,721 --> 02:20:19,051 all right let's see how we can solve this problem so we get the input and 5794 02:20:19,051 --> 02:20:19,061 this problem so we get the input and 5795 02:20:19,061 --> 02:20:22,940 this problem so we get the input and check to see if input is divisible by 3 5796 02:20:22,940 --> 02:20:22,950 check to see if input is divisible by 3 5797 02:20:22,950 --> 02:20:26,761 check to see if input is divisible by 3 then we can set a variable like result 5798 02:20:26,761 --> 02:20:26,771 then we can set a variable like result 5799 02:20:26,771 --> 02:20:27,930 then we can set a variable like result to phase 5800 02:20:27,930 --> 02:20:27,940 to phase 5801 02:20:27,940 --> 02:20:30,780 to phase now let me temporarily simplify these 5802 02:20:30,780 --> 02:20:30,790 now let me temporarily simplify these 5803 02:20:30,790 --> 02:20:32,520 now let me temporarily simplify these rules because I want to show you a 5804 02:20:32,520 --> 02:20:32,530 rules because I want to show you a 5805 02:20:32,530 --> 02:20:35,671 rules because I want to show you a really cool technique so let's imagine 5806 02:20:35,671 --> 02:20:35,681 really cool technique so let's imagine 5807 02:20:35,681 --> 02:20:38,220 really cool technique so let's imagine if the input is divisible by 3 5808 02:20:38,220 --> 02:20:38,230 if the input is divisible by 3 5809 02:20:38,230 --> 02:20:41,190 if the input is divisible by 3 we'll return fizz otherwise we'll return 5810 02:20:41,190 --> 02:20:41,200 we'll return fizz otherwise we'll return 5811 02:20:41,200 --> 02:20:48,030 we'll return fizz otherwise we'll return bus so LS : we set the result to buzz 5812 02:20:48,030 --> 02:20:48,040 bus so LS : we set the result to buzz 5813 02:20:48,040 --> 02:20:51,001 bus so LS : we set the result to buzz and finally we'll return this resolved 5814 02:20:51,001 --> 02:20:51,011 and finally we'll return this resolved 5815 02:20:51,011 --> 02:20:52,940 and finally we'll return this resolved variable 5816 02:20:52,940 --> 02:20:52,950 variable 5817 02:20:52,950 --> 02:20:55,460 variable this is one way to implement these rules 5818 02:20:55,460 --> 02:20:55,470 this is one way to implement these rules 5819 02:20:55,470 --> 02:20:57,171 this is one way to implement these rules but it's not the best way there is a 5820 02:20:57,171 --> 02:20:57,181 but it's not the best way there is a 5821 02:20:57,181 --> 02:20:59,720 but it's not the best way there is a better and cleaner way let me show you 5822 02:20:59,720 --> 02:20:59,730 better and cleaner way let me show you 5823 02:20:59,730 --> 02:21:01,730 better and cleaner way let me show you so instead of defining this result 5824 02:21:01,730 --> 02:21:01,740 so instead of defining this result 5825 02:21:01,740 --> 02:21:05,180 so instead of defining this result variable and then returning it we can 5826 02:21:05,180 --> 02:21:05,190 variable and then returning it we can 5827 02:21:05,190 --> 02:21:10,671 variable and then returning it we can simply return this string here and also 5828 02:21:10,671 --> 02:21:10,681 simply return this string here and also 5829 02:21:10,681 --> 02:21:13,790 simply return this string here and also here and then we can get rid of line six 5830 02:21:13,790 --> 02:21:13,800 here and then we can get rid of line six 5831 02:21:13,800 --> 02:21:17,000 here and then we can get rid of line six so we remove one unnecessary line of 5832 02:21:17,000 --> 02:21:17,010 so we remove one unnecessary line of 5833 02:21:17,010 --> 02:21:19,820 so we remove one unnecessary line of code this was one technique the other 5834 02:21:19,820 --> 02:21:19,830 code this was one technique the other 5835 02:21:19,830 --> 02:21:22,160 code this was one technique the other technique I want to show you is when you 5836 02:21:22,160 --> 02:21:22,170 technique I want to show you is when you 5837 02:21:22,170 --> 02:21:25,160 technique I want to show you is when you have an if statement and in your if 5838 02:21:25,160 --> 02:21:25,170 have an if statement and in your if 5839 02:21:25,170 --> 02:21:25,700 have an if statement and in your if flock 5840 02:21:25,700 --> 02:21:25,710 flock 5841 02:21:25,710 --> 02:21:27,740 flock you're returning a value you don't 5842 02:21:27,740 --> 02:21:27,750 you're returning a value you don't 5843 02:21:27,750 --> 02:21:31,580 you're returning a value you don't really need an else clause because if 5844 02:21:31,580 --> 02:21:31,590 really need an else clause because if 5845 02:21:31,590 --> 02:21:34,430 really need an else clause because if this condition is evaluated to false the 5846 02:21:34,430 --> 02:21:34,440 this condition is evaluated to false the 5847 02:21:34,440 --> 02:21:36,710 this condition is evaluated to false the control moves to the else clause and all 5848 02:21:36,710 --> 02:21:36,720 control moves to the else clause and all 5849 02:21:36,720 --> 02:21:39,530 control moves to the else clause and all we're doing here is returning a 5850 02:21:39,530 --> 02:21:39,540 we're doing here is returning a 5851 02:21:39,540 --> 02:21:41,690 we're doing here is returning a different value so this is the only 5852 02:21:41,690 --> 02:21:41,700 different value so this is the only 5853 02:21:41,700 --> 02:21:44,511 different value so this is the only possible outcome so here we can remove 5854 02:21:44,511 --> 02:21:44,521 possible outcome so here we can remove 5855 02:21:44,521 --> 02:21:49,030 possible outcome so here we can remove this else clause and simply return bus 5856 02:21:49,030 --> 02:21:49,040 this else clause and simply return bus 5857 02:21:49,040 --> 02:21:51,950 this else clause and simply return bus so with this technique I remove an 5858 02:21:51,950 --> 02:21:51,960 so with this technique I remove an 5859 02:21:51,960 --> 02:21:54,080 so with this technique I remove an unnecessary indentation as well I've 5860 02:21:54,080 --> 02:21:54,090 unnecessary indentation as well I've 5861 02:21:54,090 --> 02:21:57,710 unnecessary indentation as well I've made our code more linear okay now let's 5862 02:21:57,710 --> 02:21:57,720 made our code more linear okay now let's 5863 02:21:57,720 --> 02:22:00,381 made our code more linear okay now let's go back to our original algorithm so if 5864 02:22:00,381 --> 02:22:00,391 go back to our original algorithm so if 5865 02:22:00,391 --> 02:22:02,270 go back to our original algorithm so if the input is divisible by three we'll 5866 02:22:02,270 --> 02:22:02,280 the input is divisible by three we'll 5867 02:22:02,280 --> 02:22:05,511 the input is divisible by three we'll return fizz now we check to see if the 5868 02:22:05,511 --> 02:22:05,521 return fizz now we check to see if the 5869 02:22:05,521 --> 02:22:07,910 return fizz now we check to see if the input is divisible by five we'll return 5870 02:22:07,910 --> 02:22:07,920 input is divisible by five we'll return 5871 02:22:07,920 --> 02:22:11,180 input is divisible by five we'll return buzz so here we don't really need an 5872 02:22:11,180 --> 02:22:11,190 buzz so here we don't really need an 5873 02:22:11,190 --> 02:22:14,780 buzz so here we don't really need an Elif because if this condition is false 5874 02:22:14,780 --> 02:22:14,790 Elif because if this condition is false 5875 02:22:14,790 --> 02:22:18,160 Elif because if this condition is false we'll get here anyway so we can check if 5876 02:22:18,160 --> 02:22:18,170 we'll get here anyway so we can check if 5877 02:22:18,170 --> 02:22:22,881 we'll get here anyway so we can check if input is divisible by five we will 5878 02:22:22,881 --> 02:22:22,891 input is divisible by five we will 5879 02:22:22,891 --> 02:22:26,600 input is divisible by five we will return buzz once again if this condition 5880 02:22:26,600 --> 02:22:26,610 return buzz once again if this condition 5881 02:22:26,610 --> 02:22:29,810 return buzz once again if this condition is false the control moves here now we 5882 02:22:29,810 --> 02:22:29,820 is false the control moves here now we 5883 02:22:29,820 --> 02:22:32,450 is false the control moves here now we check the same if the input is divisible 5884 02:22:32,450 --> 02:22:32,460 check the same if the input is divisible 5885 02:22:32,460 --> 02:22:36,801 check the same if the input is divisible by three and it is also divisible by 5886 02:22:36,801 --> 02:22:36,811 by three and it is also divisible by 5887 02:22:36,811 --> 02:22:43,640 by three and it is also divisible by five then we will return fizz buzz now 5888 02:22:43,640 --> 02:22:43,650 five then we will return fizz buzz now 5889 02:22:43,650 --> 02:22:45,591 five then we will return fizz buzz now this expression is a little bit long I 5890 02:22:45,591 --> 02:22:45,601 this expression is a little bit long I 5891 02:22:45,601 --> 02:22:48,200 this expression is a little bit long I would prefer to make it more readable by 5892 02:22:48,200 --> 02:22:48,210 would prefer to make it more readable by 5893 02:22:48,210 --> 02:22:51,560 would prefer to make it more readable by putting parentheses around the first and 5894 02:22:51,560 --> 02:22:51,570 putting parentheses around the first and 5895 02:22:51,570 --> 02:22:56,690 putting parentheses around the first and second parts like this that is cleaner 5896 02:22:56,690 --> 02:22:56,700 second parts like this that is cleaner 5897 02:22:56,700 --> 02:23:00,171 second parts like this that is cleaner now if this condition is also false the 5898 02:23:00,171 --> 02:23:00,181 now if this condition is also false the 5899 02:23:00,181 --> 02:23:02,480 now if this condition is also false the control moves here that means our number 5900 02:23:02,480 --> 02:23:02,490 control moves here that means our number 5901 02:23:02,490 --> 02:23:05,270 control moves here that means our number is not divisible by three or five so we 5902 02:23:05,270 --> 02:23:05,280 is not divisible by three or five so we 5903 02:23:05,280 --> 02:23:06,719 is not divisible by three or five so we should simply return the 5904 02:23:06,719 --> 02:23:06,729 should simply return the 5905 02:23:06,729 --> 02:23:08,639 should simply return the input once again we don't need an else 5906 02:23:08,639 --> 02:23:08,649 input once again we don't need an else 5907 02:23:08,649 --> 02:23:12,319 input once again we don't need an else or another if we simply return the input 5908 02:23:12,319 --> 02:23:12,329 or another if we simply return the input 5909 02:23:12,329 --> 02:23:14,910 or another if we simply return the input now let's run this program and see if 5910 02:23:14,910 --> 02:23:14,920 now let's run this program and see if 5911 02:23:14,920 --> 02:23:17,519 now let's run this program and see if it's working properly or not so we call 5912 02:23:17,519 --> 02:23:17,529 it's working properly or not so we call 5913 02:23:17,529 --> 02:23:20,609 it's working properly or not so we call our function with three and we get fizz 5914 02:23:20,609 --> 02:23:20,619 our function with three and we get fizz 5915 02:23:20,619 --> 02:23:24,510 our function with three and we get fizz beautiful let's call it with five we get 5916 02:23:24,510 --> 02:23:24,520 beautiful let's call it with five we get 5917 02:23:24,520 --> 02:23:28,050 beautiful let's call it with five we get Buzz perfect what if we call it with 15 5918 02:23:28,050 --> 02:23:28,060 Buzz perfect what if we call it with 15 5919 02:23:28,060 --> 02:23:31,649 Buzz perfect what if we call it with 15 we should get fizz bus however we get 5920 02:23:31,649 --> 02:23:31,659 we should get fizz bus however we get 5921 02:23:31,659 --> 02:23:32,279 we should get fizz bus however we get fizz 5922 02:23:32,279 --> 02:23:32,289 fizz 5923 02:23:32,289 --> 02:23:34,649 fizz what is going on here the reason this 5924 02:23:34,649 --> 02:23:34,659 what is going on here the reason this 5925 02:23:34,659 --> 02:23:37,290 what is going on here the reason this happened was because when we pass 15 5926 02:23:37,290 --> 02:23:37,300 happened was because when we pass 15 5927 02:23:37,300 --> 02:23:40,769 happened was because when we pass 15 here line two is executed obviously 15 5928 02:23:40,769 --> 02:23:40,779 here line two is executed obviously 15 5929 02:23:40,779 --> 02:23:44,040 here line two is executed obviously 15 is divisible by three so that is why we 5930 02:23:44,040 --> 02:23:44,050 is divisible by three so that is why we 5931 02:23:44,050 --> 02:23:46,769 is divisible by three so that is why we immediately return fizz to solve this 5932 02:23:46,769 --> 02:23:46,779 immediately return fizz to solve this 5933 02:23:46,779 --> 02:23:49,290 immediately return fizz to solve this problem we need to move this condition 5934 02:23:49,290 --> 02:23:49,300 problem we need to move this condition 5935 02:23:49,300 --> 02:23:52,170 problem we need to move this condition which is more specific to the top so 5936 02:23:52,170 --> 02:23:52,180 which is more specific to the top so 5937 02:23:52,180 --> 02:23:54,479 which is more specific to the top so I've selected these two lines using alt 5938 02:23:54,479 --> 02:23:54,489 I've selected these two lines using alt 5939 02:23:54,489 --> 02:23:59,189 I've selected these two lines using alt + up I move these lines up beautiful all 5940 02:23:59,189 --> 02:23:59,199 + up I move these lines up beautiful all 5941 02:23:59,199 --> 02:24:00,809 + up I move these lines up beautiful all right now let's run the program one more 5942 02:24:00,809 --> 02:24:00,819 right now let's run the program one more 5943 02:24:00,819 --> 02:24:01,519 right now let's run the program one more time 5944 02:24:01,519 --> 02:24:01,529 time 5945 02:24:01,529 --> 02:24:04,950 time so we get fizzbuzz once again let's test 5946 02:24:04,950 --> 02:24:04,960 so we get fizzbuzz once again let's test 5947 02:24:04,960 --> 02:24:08,819 so we get fizzbuzz once again let's test it with three now we get fares let's 5948 02:24:08,819 --> 02:24:08,829 it with three now we get fares let's 5949 02:24:08,829 --> 02:24:11,160 it with three now we get fares let's test it with five when writing functions 5950 02:24:11,160 --> 02:24:11,170 test it with five when writing functions 5951 02:24:11,170 --> 02:24:13,080 test it with five when writing functions don't assume that your function is 5952 02:24:13,080 --> 02:24:13,090 don't assume that your function is 5953 02:24:13,090 --> 02:24:15,000 don't assume that your function is working make sure to test it with all 5954 02:24:15,000 --> 02:24:15,010 working make sure to test it with all 5955 02:24:15,010 --> 02:24:17,819 working make sure to test it with all different kinds of values let's test it 5956 02:24:17,819 --> 02:24:17,829 different kinds of values let's test it 5957 02:24:17,829 --> 02:24:20,399 different kinds of values let's test it but 5 we get Buzz beautiful what if you 5958 02:24:20,399 --> 02:24:20,409 but 5 we get Buzz beautiful what if you 5959 02:24:20,409 --> 02:24:23,969 but 5 we get Buzz beautiful what if you pass 7 which is not divisible by 3 or 5 5960 02:24:23,969 --> 02:24:23,979 pass 7 which is not divisible by 3 or 5 5961 02:24:23,979 --> 02:24:27,149 pass 7 which is not divisible by 3 or 5 we get 7 beautiful so what you see here 5962 02:24:27,149 --> 02:24:27,159 we get 7 beautiful so what you see here 5963 02:24:27,159 --> 02:24:29,460 we get 7 beautiful so what you see here is the simplest and most elegant 5964 02:24:29,460 --> 02:24:29,470 is the simplest and most elegant 5965 02:24:29,470 --> 02:24:32,160 is the simplest and most elegant implementation of the fizzbuzz algorithm 5966 02:24:32,160 --> 02:24:32,170 implementation of the fizzbuzz algorithm 5967 02:24:32,170 --> 02:24:34,080 implementation of the fizzbuzz algorithm and that brings us to the end of this 5968 02:24:34,080 --> 02:24:34,090 and that brings us to the end of this 5969 02:24:34,090 --> 02:24:36,120 and that brings us to the end of this section in the next lecture we're going 5970 02:24:36,120 --> 02:24:36,130 section in the next lecture we're going 5971 02:24:36,130 --> 02:24:38,700 section in the next lecture we're going to explore data structures in Python 5972 02:24:38,700 --> 02:24:38,710 to explore data structures in Python 5973 02:24:38,710 --> 02:24:40,679 to explore data structures in Python you're going to learn about lists tuples 5974 02:24:40,679 --> 02:24:40,689 you're going to learn about lists tuples 5975 02:24:40,689 --> 02:24:43,859 you're going to learn about lists tuples sets and dictionaries I hope you enjoyed 5976 02:24:43,859 --> 02:24:43,869 sets and dictionaries I hope you enjoyed 5977 02:24:43,869 --> 02:24:45,850 sets and dictionaries I hope you enjoyed this section and thank you for watching 5978 02:24:45,850 --> 02:24:45,860 this section and thank you for watching 5979 02:24:45,860 --> 02:24:48,051 this section and thank you for watching [Music] 5980 02:24:48,051 --> 02:24:48,061 [Music] 5981 02:24:48,061 --> 02:24:48,290 [Music] you 5982 02:24:48,290 --> 02:24:48,300 you 5983 02:24:48,300 --> 02:24:54,400 you [Music] 5984 02:24:54,400 --> 02:24:54,410 [Music] 5985 02:24:54,410 --> 02:24:56,870 [Music] you made it this far and that makes me 5986 02:24:56,870 --> 02:24:56,880 you made it this far and that makes me 5987 02:24:56,880 --> 02:24:58,160 you made it this far and that makes me think that you're really enthusiastic 5988 02:24:58,160 --> 02:24:58,170 think that you're really enthusiastic 5989 02:24:58,170 --> 02:25:01,100 think that you're really enthusiastic about learning Python so I highly 5990 02:25:01,100 --> 02:25:01,110 about learning Python so I highly 5991 02:25:01,110 --> 02:25:03,051 about learning Python so I highly encourage you to enroll in my complete 5992 02:25:03,051 --> 02:25:03,061 encourage you to enroll in my complete 5993 02:25:03,061 --> 02:25:05,541 encourage you to enroll in my complete Python course where we go way beyond 5994 02:25:05,541 --> 02:25:05,551 Python course where we go way beyond 5995 02:25:05,551 --> 02:25:07,520 Python course where we go way beyond this crash course you will learn how to 5996 02:25:07,520 --> 02:25:07,530 this crash course you will learn how to 5997 02:25:07,530 --> 02:25:09,921 this crash course you will learn how to use Python in real-world scenarios such 5998 02:25:09,921 --> 02:25:09,931 use Python in real-world scenarios such 5999 02:25:09,931 --> 02:25:11,980 use Python in real-world scenarios such as data analysis and visualization 6000 02:25:11,980 --> 02:25:11,990 as data analysis and visualization 6001 02:25:11,990 --> 02:25:14,930 as data analysis and visualization automating repetitive boring tasks that 6002 02:25:14,930 --> 02:25:14,940 automating repetitive boring tasks that 6003 02:25:14,940 --> 02:25:17,200 automating repetitive boring tasks that involve working with files and folders 6004 02:25:17,200 --> 02:25:17,210 involve working with files and folders 6005 02:25:17,210 --> 02:25:20,320 involve working with files and folders spreadsheets PDFs data compression 6006 02:25:20,320 --> 02:25:20,330 spreadsheets PDFs data compression 6007 02:25:20,330 --> 02:25:23,780 spreadsheets PDFs data compression sending emails web crawling consuming 6008 02:25:23,780 --> 02:25:23,790 sending emails web crawling consuming 6009 02:25:23,790 --> 02:25:26,270 sending emails web crawling consuming api's and much much more this course 6010 02:25:26,270 --> 02:25:26,280 api's and much much more this course 6011 02:25:26,280 --> 02:25:28,850 api's and much much more this course comes with a 30 day no questions asked 6012 02:25:28,850 --> 02:25:28,860 comes with a 30 day no questions asked 6013 02:25:28,860 --> 02:25:30,680 comes with a 30 day no questions asked money back guarantee and a certificate 6014 02:25:30,680 --> 02:25:30,690 money back guarantee and a certificate 6015 02:25:30,690 --> 02:25:33,381 money back guarantee and a certificate of completion if you're interested click 6016 02:25:33,381 --> 02:25:33,391 of completion if you're interested click 6017 02:25:33,391 --> 02:25:35,211 of completion if you're interested click the link below this video to access the 6018 02:25:35,211 --> 02:25:35,221 the link below this video to access the 6019 02:25:35,221 --> 02:25:37,461 the link below this video to access the course once again thank you for watching 6020 02:25:37,461 --> 02:25:37,471 course once again thank you for watching 6021 02:25:37,471 --> 02:25:39,350 course once again thank you for watching please support me by liking and sharing 6022 02:25:39,350 --> 02:25:39,360 please support me by liking and sharing 6023 02:25:39,360 --> 02:25:41,660 please support me by liking and sharing this video and also subscribe to my 6024 02:25:41,660 --> 02:25:41,670 this video and also subscribe to my 6025 02:25:41,670 --> 02:25:44,240 this video and also subscribe to my channel to get free new videos every 6026 02:25:44,240 --> 02:25:44,250 channel to get free new videos every 6027 02:25:44,250 --> 02:25:48,680 channel to get free new videos every week thank you and have a great day 6028 02:25:48,680 --> 02:25:48,690 6029 02:25:48,690 --> 02:25:55,239 [Music]