1 00:00:06,940 --> 00:00:10,350 - Welcome to Python Fundamentals part three of five. 2 00:00:10,350 --> 00:00:12,760 My name is Paul Deitel and I'll be your instructor 3 00:00:12,760 --> 00:00:15,061 for these LiveLessons videos. 4 00:00:15,061 --> 00:00:17,986 Part three is based on chapters eight through 10 5 00:00:17,986 --> 00:00:20,480 of our textbook, Intro to Python 6 00:00:20,480 --> 00:00:22,870 for Computer Science and Data Science, 7 00:00:22,870 --> 00:00:25,940 learning to program with AI, big data, and the cloud, 8 00:00:25,940 --> 00:00:29,320 and also chapters eight through 10 of our professional book, 9 00:00:29,320 --> 00:00:30,893 Python for Programmers. 10 00:00:32,374 --> 00:00:35,720 The prerequisite for part three are either 11 00:00:35,720 --> 00:00:38,890 Python Fundamentals LiveLessons parts one and two, 12 00:00:38,890 --> 00:00:42,003 or equivalent Python programming experience. 13 00:00:43,470 --> 00:00:45,440 Many people find that as they work their way 14 00:00:45,440 --> 00:00:47,584 through the videos, it's helpful to have a copy 15 00:00:47,584 --> 00:00:49,540 of the book at hand. 16 00:00:49,540 --> 00:00:52,070 However, this is not required. 17 00:00:52,070 --> 00:00:54,370 There is additional information in the books 18 00:00:54,370 --> 00:00:57,170 that I don't cover as part of these videos. 19 00:00:57,170 --> 00:01:00,010 If you're interested in getting a copy of one of the books, 20 00:01:00,010 --> 00:01:03,400 you can find them in various print and electronic formats 21 00:01:03,400 --> 00:01:05,523 at the sites that are listed for you. 22 00:01:07,110 --> 00:01:08,490 If you're a college instructor, 23 00:01:08,490 --> 00:01:10,160 you'll probably want to take a look 24 00:01:10,160 --> 00:01:13,390 at Intro to Python for Computer Science and Data Science, 25 00:01:13,390 --> 00:01:17,030 which is our college textbook version of the book. 26 00:01:17,030 --> 00:01:20,250 This one is in full color, it's 880 pages, 27 00:01:20,250 --> 00:01:23,610 240 pages more than Python for Programmers, 28 00:01:23,610 --> 00:01:27,290 and in particular, it contains a ton of exercises, 29 00:01:27,290 --> 00:01:32,290 557 self-check exercises, as well as 471 additional 30 00:01:32,790 --> 00:01:36,170 end-of-chapter exercises and projects. 31 00:01:36,170 --> 00:01:37,630 Now many professionals find that 32 00:01:37,630 --> 00:01:39,750 they like to work with the textbook version, 33 00:01:39,750 --> 00:01:42,773 specifically because of the exercises. 34 00:01:43,813 --> 00:01:46,060 If you're interested in learning more 35 00:01:46,060 --> 00:01:49,480 about Intro to Python for Computer Science and Data Science, 36 00:01:49,480 --> 00:01:52,500 please take a look at the links that I've provided below. 37 00:01:52,500 --> 00:01:55,140 The first one is for an architectural diagram 38 00:01:55,140 --> 00:01:56,798 in which we show you the four-part 39 00:01:56,798 --> 00:01:59,420 modular structure of this book, 40 00:01:59,420 --> 00:02:02,400 and that really applies both to the college textbook 41 00:02:02,400 --> 00:02:06,250 and our professional book, Python for Programmers, as well. 42 00:02:06,250 --> 00:02:09,960 The for programmers book has one fewer chapter, 43 00:02:09,960 --> 00:02:13,030 but the overall architecture of the two books is the same. 44 00:02:13,030 --> 00:02:14,800 And also, in the for programmers book, 45 00:02:14,800 --> 00:02:18,220 we have less of the lower-end pedagogical material 46 00:02:18,220 --> 00:02:19,605 that's really geared to people 47 00:02:19,605 --> 00:02:22,320 who are novices in programming. 48 00:02:22,320 --> 00:02:24,630 The second link is for the full table of contents, 49 00:02:24,630 --> 00:02:26,353 where you can see everything that we're going to cover 50 00:02:26,353 --> 00:02:27,560 throughout the book. 51 00:02:27,560 --> 00:02:29,660 And the third one is the book's preface, 52 00:02:29,660 --> 00:02:31,970 where you can learn more about our approach 53 00:02:31,970 --> 00:02:34,240 to teaching Python, data science, 54 00:02:34,240 --> 00:02:37,473 artificial intelligence, and various big data topics. 55 00:02:38,740 --> 00:02:40,298 I'd also like to recommend that you take a look 56 00:02:40,298 --> 00:02:42,720 at these two additional links. 57 00:02:42,720 --> 00:02:45,190 The first one is for the full book cover. 58 00:02:45,190 --> 00:02:48,860 And in particular, if you look at the back cover copy, 59 00:02:48,860 --> 00:02:51,410 you'll see a nice summary of everything 60 00:02:51,410 --> 00:02:53,970 that we're going to do throughout these LiveLessons videos. 61 00:02:53,970 --> 00:02:55,882 And I'd also recommend that you take a moment 62 00:02:55,882 --> 00:02:58,620 to read through the technical 63 00:02:58,620 --> 00:03:01,370 and academic reviewer testimonials 64 00:03:01,370 --> 00:03:02,896 to really get a sense of all the things 65 00:03:02,896 --> 00:03:06,380 that they liked about how we presented Python 66 00:03:06,380 --> 00:03:10,053 and the various data science, AI, and big data topics. 67 00:03:11,660 --> 00:03:14,530 To begin this lesson, we'll take a look at lesson eight, 68 00:03:14,530 --> 00:03:16,290 strings, a deeper look. 69 00:03:16,290 --> 00:03:18,990 Now because Python is a scripting language, 70 00:03:18,990 --> 00:03:21,340 it is frequently used in all sorts of 71 00:03:21,340 --> 00:03:23,940 string processing capabilities. 72 00:03:23,940 --> 00:03:25,920 So as we go into lesson eight here, 73 00:03:25,920 --> 00:03:29,600 we'll be looking at a lot of little individual details 74 00:03:29,600 --> 00:03:32,610 of how to work with strings in Python. 75 00:03:32,610 --> 00:03:35,090 We'll take a look at various string methods, 76 00:03:35,090 --> 00:03:36,470 look at how to do various 77 00:03:36,470 --> 00:03:39,130 string formatting capabilities as well. 78 00:03:39,130 --> 00:03:41,150 And as part of that, by the way, 79 00:03:41,150 --> 00:03:43,930 we're going to be not only talking about 80 00:03:43,930 --> 00:03:46,487 the F-string concept that you saw 81 00:03:46,487 --> 00:03:48,640 in some of the earlier lessons 82 00:03:48,640 --> 00:03:51,140 for creating formatted string content, 83 00:03:51,140 --> 00:03:54,740 but also looking at an older style of string formatting 84 00:03:54,740 --> 00:03:56,720 that you will frequently encounter 85 00:03:56,720 --> 00:04:00,010 in other people's Python programming code. 86 00:04:00,010 --> 00:04:01,810 And of course, Python has been around now 87 00:04:01,810 --> 00:04:04,500 for an extremely long time. 88 00:04:04,500 --> 00:04:06,900 So it is important for you to have a sense 89 00:04:06,900 --> 00:04:08,930 of other ways of doing things, 90 00:04:08,930 --> 00:04:12,110 even if they're not the most current, as well. 91 00:04:12,110 --> 00:04:14,340 One of the key aspects that we'll be looking at 92 00:04:14,340 --> 00:04:16,570 for string processing in this lesson 93 00:04:16,570 --> 00:04:18,710 is Python's extensive set 94 00:04:18,710 --> 00:04:22,030 of regular expression processing capabilities. 95 00:04:22,030 --> 00:04:24,650 And we'll introduce a variety of those 96 00:04:24,650 --> 00:04:26,240 as part of this lesson, 97 00:04:26,240 --> 00:04:28,880 and then start to use those a little bit more 98 00:04:28,880 --> 00:04:32,170 as we move into the intro to data science section, 99 00:04:32,170 --> 00:04:34,570 where we will continue our discussion 100 00:04:34,570 --> 00:04:38,110 of the pandas library from lesson seven in part two. 101 00:04:38,110 --> 00:04:41,000 But we're also going to use pandas now 102 00:04:41,000 --> 00:04:45,490 to perform some data manipulation and data preparation. 103 00:04:45,490 --> 00:04:48,610 And we'll combine the regular expression concepts 104 00:04:48,610 --> 00:04:51,533 that we learn with pandas to do that. 105 00:04:53,380 --> 00:04:55,780 In lesson nine, files and exceptions, 106 00:04:55,780 --> 00:04:59,210 we're going to take a look at several different file formats 107 00:04:59,210 --> 00:05:03,090 and introduce Python's version of exception handling. 108 00:05:03,090 --> 00:05:04,730 With respect to file processing, 109 00:05:04,730 --> 00:05:08,640 we'll look at basic text files for both input and output. 110 00:05:08,640 --> 00:05:11,500 We'll also take a look at the very popular 111 00:05:11,500 --> 00:05:15,420 Java Script Object Notation, or JSON for short. 112 00:05:15,420 --> 00:05:19,630 JSON is one of the most popular data interchange formats, 113 00:05:19,630 --> 00:05:23,910 and we'll be using that extensively in subsequent lessons. 114 00:05:23,910 --> 00:05:26,140 So we want to introduce it to you here 115 00:05:26,140 --> 00:05:29,810 in the context of writing Java Script Object Notation, 116 00:05:29,810 --> 00:05:33,435 out to a file on disc, and also reading data back in 117 00:05:33,435 --> 00:05:35,970 from such a file as well, 118 00:05:35,970 --> 00:05:39,510 and turning it back into a Python object. 119 00:05:39,510 --> 00:05:41,430 Now we're going to get in depth 120 00:05:41,430 --> 00:05:44,410 into the Python exception handling mechanism. 121 00:05:44,410 --> 00:05:46,070 And if you're coming into this videos 122 00:05:46,070 --> 00:05:49,550 from a language like C++, or Java, or C#, 123 00:05:49,550 --> 00:05:52,950 you're going to see a lot of familiar concepts. 124 00:05:52,950 --> 00:05:54,833 Python uses some different key words 125 00:05:54,833 --> 00:05:57,380 and also has some additional concepts 126 00:05:57,380 --> 00:06:00,570 that you won't find in those other programming languages. 127 00:06:00,570 --> 00:06:03,620 So I'll be sure to point all of that out to you. 128 00:06:03,620 --> 00:06:06,321 Now when we get to the intro to data science section 129 00:06:06,321 --> 00:06:08,372 in this lesson, we're going to focus on 130 00:06:08,372 --> 00:06:10,850 comma separated value files. 131 00:06:10,850 --> 00:06:12,377 And one of the key reasons for that 132 00:06:12,377 --> 00:06:16,890 is part of our focus on processing data sets 133 00:06:16,890 --> 00:06:19,330 in a lot of the higher-end lessons. 134 00:06:19,330 --> 00:06:21,630 Many of the data sets that you will work with 135 00:06:21,630 --> 00:06:25,000 are provided in comma separated value format, 136 00:06:25,000 --> 00:06:26,440 so it is important to know 137 00:06:26,440 --> 00:06:29,380 how to get such data into an application, 138 00:06:29,380 --> 00:06:32,670 and sometimes how to write out such data as well. 139 00:06:32,670 --> 00:06:36,000 So in the context of both the CSV module 140 00:06:36,000 --> 00:06:39,620 that's built into Python, and the pandas library, 141 00:06:39,620 --> 00:06:42,960 we will be showing you how to load and store 142 00:06:42,960 --> 00:06:45,133 comma separated value data. 143 00:06:47,170 --> 00:06:50,350 To finish up part three, we'll take a look at lesson 10, 144 00:06:50,350 --> 00:06:52,540 object-oriented programming. 145 00:06:52,540 --> 00:06:54,900 Now over the course of a year and a half 146 00:06:54,900 --> 00:06:56,790 of research for this project, 147 00:06:56,790 --> 00:06:58,840 as I mentioned in an earlier lesson, 148 00:06:58,840 --> 00:07:00,713 we rarely encountered the need 149 00:07:00,713 --> 00:07:04,310 to create custom class definitions. 150 00:07:04,310 --> 00:07:06,760 In fact, I think for the project, 151 00:07:06,760 --> 00:07:10,360 we wound up creating only four or five or six of them total, 152 00:07:10,360 --> 00:07:14,620 outside of lesson 10, where we show you the mechanisms 153 00:07:14,620 --> 00:07:17,150 for creating your own new data types in Python. 154 00:07:17,150 --> 00:07:20,930 So the vast majority of Python programming is done, 155 00:07:20,930 --> 00:07:24,280 as what we like to refer to, as object-based programming, 156 00:07:24,280 --> 00:07:27,220 where you create an object of an existing class, 157 00:07:27,220 --> 00:07:29,192 probably imported from one of the many 158 00:07:29,192 --> 00:07:31,500 open-source libraries that are out there, 159 00:07:31,500 --> 00:07:34,350 and then you interact with that object. 160 00:07:34,350 --> 00:07:37,560 In lesson 10, we focus on how you can create 161 00:07:37,560 --> 00:07:40,340 your own new custom data types. 162 00:07:40,340 --> 00:07:42,563 So for instance, if you're creating a library 163 00:07:42,563 --> 00:07:44,950 that other people are going to use, 164 00:07:44,950 --> 00:07:47,280 a lot of what I present here in this lesson 165 00:07:47,280 --> 00:07:49,330 is going to be relevant to you. 166 00:07:49,330 --> 00:07:52,670 If you are going to need to create any custom classes, 167 00:07:52,670 --> 00:07:56,080 which we do a few times in some of the subsequent lessons, 168 00:07:56,080 --> 00:07:58,615 you'll probably find that you can look at 169 00:07:58,615 --> 00:08:02,010 the classes we defined and figure out what they do, 170 00:08:02,010 --> 00:08:05,710 if you are already an object-oriented developer. 171 00:08:05,710 --> 00:08:07,714 If you are not, however, I will cover 172 00:08:07,714 --> 00:08:12,500 object-oriented programming in detail here in lesson 10. 173 00:08:12,500 --> 00:08:14,200 Some of the things that we'll be looking at 174 00:08:14,200 --> 00:08:16,226 are how to create custom classes, 175 00:08:16,226 --> 00:08:19,290 how to use a concept called properties 176 00:08:19,290 --> 00:08:22,280 for accessing data inside of an object. 177 00:08:22,280 --> 00:08:24,110 And by the way, one of the things 178 00:08:24,110 --> 00:08:25,980 that you're going to find in Python 179 00:08:25,980 --> 00:08:28,561 is that its approach to object-oriented programming 180 00:08:28,561 --> 00:08:33,561 is a lot different from languages like C++, Java, and C#, 181 00:08:34,650 --> 00:08:37,600 which all have concepts of what we call public, 182 00:08:37,600 --> 00:08:40,820 protected, and private members of a class. 183 00:08:40,820 --> 00:08:45,770 In Python, everything is public no matter what you do. 184 00:08:45,770 --> 00:08:47,960 So one of the things that we're going to do 185 00:08:47,960 --> 00:08:50,840 is look at Python's conventions 186 00:08:50,840 --> 00:08:53,310 that Python programmers follow 187 00:08:53,310 --> 00:08:56,370 to indicate aspects of a class definition 188 00:08:56,370 --> 00:08:58,850 that should not be used by somebody 189 00:08:58,850 --> 00:09:00,900 who is a client of the class. 190 00:09:00,900 --> 00:09:03,910 So you create an object, you interact with that object, 191 00:09:03,910 --> 00:09:07,930 but there's still specific attributes and behaviors 192 00:09:07,930 --> 00:09:10,880 that you should be using to interact with those objects. 193 00:09:10,880 --> 00:09:14,430 And there are others that are meant for internal use only. 194 00:09:14,430 --> 00:09:17,420 And in Python, internal use only is done 195 00:09:17,420 --> 00:09:20,500 with naming conventions, not key words, 196 00:09:20,500 --> 00:09:22,310 like public, protected, and private. 197 00:09:22,310 --> 00:09:24,599 So we're going to talk about those issues 198 00:09:24,599 --> 00:09:29,030 and show you how you can simulate the concept of private. 199 00:09:29,030 --> 00:09:32,640 But even those things are still publicly accessible, 200 00:09:32,640 --> 00:09:35,990 as I will demonstrate to you throughout this lesson. 201 00:09:35,990 --> 00:09:38,150 Some of the other things we'll take a look at here 202 00:09:38,150 --> 00:09:42,120 are how to create new classes from existing classes. 203 00:09:42,120 --> 00:09:43,830 So we'll talk about inheritance 204 00:09:43,830 --> 00:09:45,750 and polymorphism capabilities, 205 00:09:45,750 --> 00:09:48,490 and you'll see that those are very similar to some of 206 00:09:48,490 --> 00:09:51,598 the C-based object-oriented programming languages. 207 00:09:51,598 --> 00:09:55,586 We're also going to introduce a really key concept in Python 208 00:09:55,586 --> 00:09:57,940 known as duck typing. 209 00:09:57,940 --> 00:10:01,760 So basically the idea is if it looks like a duck, 210 00:10:01,760 --> 00:10:03,020 and it walks like a duck, 211 00:10:03,020 --> 00:10:05,770 and it makes the same sounds as a duck, it must be a duck. 212 00:10:05,770 --> 00:10:09,380 So basically in Python, when you pass an object, 213 00:10:09,380 --> 00:10:11,320 for example, into a function, 214 00:10:11,320 --> 00:10:14,170 as long as that object has the capabilities 215 00:10:14,170 --> 00:10:16,011 the function expects it to have, 216 00:10:16,011 --> 00:10:17,540 the function will be able to 217 00:10:17,540 --> 00:10:19,730 interact with that object and use it. 218 00:10:19,730 --> 00:10:22,650 So for instance, a lot of the visualization libraries 219 00:10:22,650 --> 00:10:27,650 expect you to provide objects of the numpy array data type. 220 00:10:27,920 --> 00:10:30,590 But because Python lists have a lot of 221 00:10:30,590 --> 00:10:33,200 the same capabilities as numpy arrays, 222 00:10:33,200 --> 00:10:38,070 you can often pass in a list where an array is expected. 223 00:10:38,070 --> 00:10:39,194 Some of the other things we'll look at 224 00:10:39,194 --> 00:10:43,420 are additional syntax features like operator overloading, 225 00:10:43,420 --> 00:10:46,720 where you can create your own new operators 226 00:10:46,720 --> 00:10:49,000 to work with your custom data types. 227 00:10:49,000 --> 00:10:50,862 So for instance, if you wanted to create 228 00:10:50,862 --> 00:10:52,940 some new mathematical type, 229 00:10:52,940 --> 00:10:56,130 you could overload the plus operator and the minus operator, 230 00:10:56,130 --> 00:10:58,400 and the multiplication operator, et cetera, 231 00:10:58,400 --> 00:11:00,900 so that you can use objects of your type 232 00:11:00,900 --> 00:11:04,510 as conveniently as using integers, for instance. 233 00:11:04,510 --> 00:11:07,080 We'll talk about a concept called named tuples, 234 00:11:07,080 --> 00:11:09,141 which are tuples where you can access the elements 235 00:11:09,141 --> 00:11:13,260 by their names instead of by index numbers. 236 00:11:13,260 --> 00:11:16,250 We'll also introduce a relatively new feature to Python 237 00:11:16,250 --> 00:11:20,770 that was introduced in Python 3.7 called data classes. 238 00:11:20,770 --> 00:11:23,670 And we'll show you some unit testing capabilities 239 00:11:23,670 --> 00:11:27,920 that are built into the Python standard library as well. 240 00:11:27,920 --> 00:11:29,720 In the intro to data science section, 241 00:11:29,720 --> 00:11:33,100 to finish up part three, we're going to start to 242 00:11:33,100 --> 00:11:36,340 take a look at some more data sciencey stuff. 243 00:11:36,340 --> 00:11:39,750 In particular, we're going to look at time series 244 00:11:39,750 --> 00:11:42,690 and a concept called simple linear regression. 245 00:11:42,690 --> 00:11:44,813 And this will be our first introduction 246 00:11:44,813 --> 00:11:48,060 into some of the topics that we're going to start to see 247 00:11:48,060 --> 00:11:51,183 in more detail in parts three and four.