Python 3: From ZERO to GUI programming | Joe Ghalbouni | Skillshare

Python 3: From ZERO to GUI programming

Joe Ghalbouni, I aim to teach in a fun and useful way!

Play Speed
  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x
15 Lessons (4h)
    • 1. Python Skillshare Promo

      0:42
    • 2. 01_Introduction to Python 3

      6:48
    • 3. 02_Elementary programming

      10:54
    • 4. 03_Mathematical functions, strings & objects

      12:32
    • 5. 04_Conditional statements

      12:52
    • 6. 05_Loops

      11:54
    • 7. 06_Functions

      9:50
    • 8. 07_Objects and Classes

      14:26
    • 9. 08_GUI (Graphical User Interface)

      12:05
    • 10. 09 _Lists

      30:13
    • 11. 10_Inheritance & Polymorphism

      18:41
    • 12. 11 _Files and Exception Handling

      24:33
    • 13. 12 _Tuples, Sets & Dictionaries

      33:18
    • 14. 13_Recursion

      13:26
    • 15. 14_ Bonus: OS datetime random

      27:55
17 students are watching this class

About This Class

Python 3 is one of the strongest programming languages and one with a high demand on the market. Whether it is for scientific programming, gaming or web development, Python has the tools and libraries that will make your project come to life.

This first course will help you set a foot in the world of Python 3, without any prior knowledge. We will guide you through these 14 chapters, allowing you to code right away from the very beginning.

Once this course is finished you will be able to expand your Python horizon to other features such as Pygame for example, which is for gaming development under Python.

The course is divided into the following chapters:

  1. Introduction to Python 3

  2. Elementary programming

  3. Mathematical Functions, Strings, Objects

  4. Conditional statements

  5. Loops

  6. Functions

  7. Objects and Classes

  8. GUI programming with Tkinter

  9. Lists

  10. Inheritance and Polymorphism

  11. Files and Exception Handling

  12. Tuples, Sets and Dictionaries

  13. Recursion

  14. Bonus - Additional Modules

All the source codes are available for download below:

Source Codes

Transcripts

1. Python Skillshare Promo: Hi, this is Joe, founder of learning or practicing it. And welcome to this course entitled Python three from 0 to GUI programming. Python three is a very versatile and powerful programming language in case you want to learn it, but have absolutely no previous skills. This course is for you through these 14 sections, we will guide you from the very beginning until you learn how to write your own pieces of programs. This is a very useful tutorial in case you want to continue learning Python for database programming or PyGame. If you're interested in learning Python, three, do not hesitate to enroll in this course. 2. 01_Introduction to Python 3: Hello everyone. I'm cal it and on PR and instructor for despite them course provided by learning wide practicing. In this course we'll learn about the Python programming language and how to develop Python applications and scripts. Python is already popular programming languages nowadays and it's been extensively used in many, many different applications. For example, used for machine learning, deep learning applications, data analytics and also to mention. And moreover, you can do like any kind of desktop and web development using different Python framework. And this tutorial series will learn how to write Python programs and scripts in order to do any kind of project and a few in the future. Learning Python is a really good investment by phi1 is one of the easiest to programming languages ever. And it's one of the most popular programming languages right now. So it would be a really good thing to learn Python at early stage of your career. Okay, in order to start development Python applications we need to do or to download and install to a different thing. The first thing is to then look Python itself, which is the basis that we have right now. So we went to python.org slash downloads. And then we can just click download Python here to download the Python interpreter and files. The next thing that we need to do is we need some fixed editor or what we call an integrated development environment in orchards to develop Python application. You can think of this as took place the kitchen where you write your own Python programs and scripts. And integrated development environment would be very powerful while developing applications in general. And to provide many features that we'll go through over the course. So we chose for this course the integrated development environment, which is caused by charm. So we search for PyCharm ID. We go to the website and we go to Download. And we can find here we have two different version, the professional one and the community version. So the professional one is abate one. You can get a free trial for 30 days in the community to one is don't get we're going to use any of this free and open source. And that will be all that we need for our Python development. Then you need to download, to download this community version. I've already downloaded them, so let's go and installed. So I have them on my desktop here. So the first thing that we need to do, we need to install Python first. So double click on that. This told now. And then goes over the installation, takes out a little bit of time. Right now we can start the installation by charm. Just double-click installer by Churn. And it is just a symbol. Windows installer hit Next, Next and takes a bit of time to finish a little extraction installation files. So after the installation is then we can just take this checkbox term PyCharm immediately and then click Finish. Right now it will bring up a bite Charmaine window, a bit, a bit of time to load and just get this. And now we can start working on our projects. So the first thing that we need to do is to create our new project. We can name it, let's say you. And then as you can see here, that the base interpreter is the Python interpreter that we have installed from the previous step. So that's why we needed to install Python first and then we hit Create. So it will take a bit of time saver, since it is the first time that take a bit of time downloading and installing some files in here. After it's done, we can find that or project here is ready. So we have this pain and you'll find new project which is the name of our project. If we expand that, we can find all of the files that we have here. These are like built-in fibers that come by default with any project. And then we need to create a new file in order to start tried to narco. So in order to do this, we just stick, Right-click the project name and then new file. Let's call this file and all or. And so this opens up this editor and this is where we can write our code and Python script. So in this video we're going to do a very simple HelloWorld program which was printing and lower statement will print hello or. So. This is a built-in function in Python school, print, and it prints some statement. This statement is inside here which shows us remove later over strings and how to do how to work with the strings. And then this is enclosed between these two parentheses. That's it. That is our program, a simple program that prints hello or in order to run this program will just be crumb run and then will choose Hello World. And this part, you can see, this part is pain books up from the bottom. And we have here the output of our program, which is a little aura, the statement that we tried to print. So that'll be it for the first tutorial. Hopefully, you enjoyed it and see you in the next one. 3. 02_Elementary programming: In this video, we start going into some Python code and starts writing some actually interesting statements and see what happens. So let's get started. So as we described in the previous video, I have just created a new project and created a new Python file in here so that we're ready to go and start tried to in our code. So we can start striking quote in this space. So the first thing that we need to start with is to define very, So what does a very variable in any programming language has some location in memory that stores some specific value. And this value could change over the course of the program over and over again. So in order to define a variable in Python is very simple actually, let's say that we need to store the value five in some memory location. In order to do this, we need to name this memory location means that some identifier order to reference this memory location. So let's just say that we named this as x. And then Let's just say x equals five. That's it. Here we have defined a variable called x. And this variable is a space in memory for a name for a space in memory that contains the value five. As you can see here, that we don't need to specify any kind of type for the variable. Once we have this variable x and a value of five, the Python interpreter automatically identifies this variable as an integer. So in order to see that, let's print the type of the variable and earlier to find the type of some variable which just died. And x. So we're under, we can run, as mentioned before, we just run an inventory. And then we can find here that the type of this variable is an integer. Okay, sounds good. We can have also some other kinds of variables that say that you have a string like Donald printed last time, hello or. So here we have defined a variable called y and we have assigned the value of hello world. Why? Soil? As we can see here, this is a string. Words, sentences, or fewer characters, and they are now stored at the memory location identified by the variable y. We can print y as we did before. Then run, we can just hit Control Shift and F21. And it prints. Can also find out the type of this y variable. So print type of y. Let's see what would be the results here. And we can find here that there is all this trend. So STR is a string. Okay? Another interesting type or another interesting time of variables is the floating point. Variables. And let's say you have a variable called z. And this is the just 2.5. In order to store numbers like 2.5. some interior and the fractional part, we need some kind of variable scope. So if we look at the type of this variable Z, we can find that is defined as floats. So a float variable is some numeric version that has an integer and a fractional. Okay? So we have also some other interesting kind of variable scope component value. So if we have, let's say variables t and we set it to false. And I had with R1, we can find that t here is a bool, so a boolean variable or a boolean variable to some variable that can take either the value true or false. So either one or 0 is very useful in some kinds of application like flags. We'll see that later in the course. And this could be a saint, either false or true. We can also, we'll also see later how we stored the result of some comparison operation into some Boolean variable. And you need to notice here, here, capital F. And it is not imposed by double quotes or single quotes, it's just false. This is a keyword in Python. The tests the value false. So this is the Boolean value False. Also sit at the Georgia onto and if we return the type, we still have the TI. Well, okay, he sounds interesting. Let's look at some of the operations that we can do on variables. So let's look at the easy one. Let's look at the addition. So we have here x is five and z is 2.5. That's true. And just print out what would be the value. So the value is 7.5 as you would expect. So this is the basic mathematical operation if we want to do a multiplication here and run. So here's the multiplication value. And let's have another variable, c. C. For example, in this value of F is 15. And let's say that we assign o to b. And we need to do some division. So we print f nash. Oh, so the slash hears the division operation. And 7.5 because 15 over six to 7.5. So this is the real division. We'll just divide these two numbers and just get a floating point value. If I want to just get the integer part of it, we have some other grazer, which is double stack. And if we do a double session here, we can get only. Seven on the anterior part of the division. Okay, let's move on to another one. And we have this modulo operation, Missy Montello o. And if we do this, we'll find that the value is one. So what does this value? This is the remainder of the division of 15. So 15 over 77 multiplied by two is 14. So the remainder is here, 15 minus 14, which is one. So the multimode operation here, um, and returns the remainder of the division of this number over that number with S over, Oh, so basically seen over two. So here that it prints the remainder of the division as well as we can see here in this example, this is 15. So 15 over two would be 7.5. Remainder here is 0.5 multiplied by two, which is one. So that's why we have the result with one ovary. Ok, so let's also look at some more complex expression. Let's say we want to print f plus Z plus o multiplied by x and find out the results. So the results here is 25. So f was 1502, and x is five. And we can find that the results here's 25. But why is it 25? Just 25, because here we have something called the British precedence. So some integrations have precedence over other British. So for this expression, now multiplication operation will be evaluated first. So all multiplied by x, which is two, multiplied by five, which then, and then after evaluation of this part, we add the result f. So here we have 15 plus ten, so that would be 25. This is really important to note because in some cases you might get an unexpected cloud, but you don't know why, because that's so. Then if you really intended to do if plus four and then multiply the result by x, then we can use parentheses. So it kinda just write down the same operation again, the same expression again. But if we want to change the order, you need to do if plus 4 first we need to do can close these parentheses. So in this case, that would be 15 plus two. And the result of that would be multiplied by five. And let's see what would be the output. So that would be 85. Celebration brisk events is very important thing to take into consideration. And there are lots of tables that has the precedence order operations of Python. So you can look it up and down fisher website. And you can find lots of resources about that as well. There were two has the full precedence of operations. Okay, so that was it for this video as a brief introduction to some of the programmatic approaches in Python or some statements and iPhone. And hopefully see you in the next video. 4. 03_Mathematical functions, strings & objects: And this video, are you talking about mathematical and stream function in Python? So let's get started. So let's start with a mathematical function, Python. And in order to use most of the built-in functions for math operations, we need to import or use some existing module in Python. And this module is called math. In order to do this, we can just write this statement. So from math or S3. So this just importing all of the content of the mass molecule into this program in order to be able to use different functions exist in that one. So the first assumption that we're going to use is called seal. So this function takes some floating point number. Let's say you have a floating point number which is x. And the values, let's say 10.9. So the seal takes the number to the next integer. So this is converting it to an integer and that integer or beat the next value for that number. So if we do see effects and then run, that would be 11. So this is 10.9. And when we do, that would be the opposite for dysfunctions called floor. So if you do floor of x and run, that would be ten, which is this number without the fraction bar. And another interesting functions to power function. So if you want to erase some number to a specific, or there is an existing function for that. So this function is called field w or other, and it takes two arguments. The first argument is the number itself and then the power that we need to raise it to. So let's say we need to calculate x with a bar two. So this is how we're to. Let's make simpler number here. Let's say it's fine. And then or brand that out. So when we are on this, you find that the value is 25. We can do the power using another different methods in Python. We don't even need to use the math module at all. So there is less br, ration the borrow bridge or in Python. So in order to do the same thing, we can just type x two S two. This is exactly the same, except for one small difference theorem that we'll still get 25. So the difference here, if you notice that this number is a floating-point number, Tessa, a fraction bar to the thoughts 0, but it still counts this one. It's only an integer. So this methods returns only integers by using the power function in the math module, returns floating point numbers. And also make sure that this is the case. Now using the type function here to see what Tie it with this result and then run. And as I mentioned, this is a floating point and the second one, this way returns an integer. Okay, so let's move on to the next function, which has the factorial function. So the factorials takes a number and say x, and then it gets the factory for this number. So the definition of the Victorian engineers, X multiplied by X minus one, multiplied by x minus two, and so on, all the way down to one. So we'll print that failure. And so this is 120. So that's just the factorial. We can also use log function. So we have looked to the base ten, log to the base ten. So let's start with looked to the base two. And let's have a number like 512 and then print run. So that's nine. Why does nine? Because two to the power of nine is 5126 Ryan on their own. And 24 run, so that is ten, and so on. We can also use the log to the base ten function and then give it a number like 1000 and R1. We can find here delta value is three. So a Y3, because ten to the three bar, three sets of 1000. Sounds good. Let's move on to the next function. We have the square root function, horse, it takes a number and finds out the square root of that number. Sophie have 25 and will print a square root for that number one. So that would be five. And try another member like nine and should be three. And here we go. And another popular trigonometric functions like sine and cosine or can use them. In order to use sine. We just type sign and then it takes a radiant decree. So what if we didn't know the radiant degrees or ARM, sorry, radian angles because decrease are more popular. We can also convert the degrees into radians using radians. So we have a method or function called gradients and takes the grease. So here we have the radian representation of 90 degrees. And this is an argument of the sine function. And we need to find the value of this sign. From here, w is one. We also can do the same as the cosine function, radians 45 for example, and crime. And here we go. So sign on, design. Very commonly used function might be very useful. We also had the constant by, which is very popular in mathematics. There is. Institute views in it if you're using some mathematical operations. So if we just tried ion printed, we know the value that would, that would be expected, this value. So let's use a tendineae useful like program, small program. Let's say that we need to calculate the area for specific circle. And we have the radius for this circumstance saved, this RNA 2.5. mean to calculate area. So the area is just falling multiplied by r raised to the power of two, right? So in order to do that, we have to learn to bar R two. Then we'll print area R1. Then here we find that the area is calculated as per the equation we have web provides. Ok, so that would be at four bar. And let's move on to the string functions. So we have looked at strings before in our very first program where we printed the hello world. So hello or there was our first string. So we can have a string defined as No. Or of course we can print that as we have seen before and later on, to just printing the string. So this is a string and it will be enclosed by two double quotations or double quotations. But we can also use single quotes. And it'll still ok. So the next thing is that we can also have like a very long strings that take many, many lines. So in order to do this, we need three double quotes or single quotes. Both of them would work. And then we can start trying to now writing down our string. So let's say in this very long string and extends many minds and, and using its y and see what would be the output. And it prints out exactly the same way that we enter this in our source code. So that would be a very good thing to notice. We can have like shrimps that span multiple lines. We also need to know that strings are considered like arrays, characters. So we can access individual characters within this string, can access this specific character, can access that one. So how do we do this? We access them using index. So each character within the string has an index. So this character, the first character has an index from 0. This one, the second character is index one. And then x one has an index of two, and so on. So in order to get the first character of a string, we can just print that, prints the first character and prints the first character of our string. Again also do this. Lets say x sub four without this D gold letter at index four and so on. We can also do some slicing them, the string if we need to print or have some substring stored. We can say that we have a string STR. And that's training would be x only from indices one through seven. And let's print that out. Str one. Run. We find that this is a portion of single fell originalist string that we had before. So what does this mean? So that means that we're constructing a string starts to index one, to index one heres e to seven but not to. So if we go over here, we can find that index seven year is o, as we looked at this before. And it doesn't move the character at that index, so it basically stops. And the previous one, which is W right here. So slicing, slicing. We can also know the length of the string by using this function LAN or length. And I'm just fast bus that string name. So let's try it. Str R1 and R1. We didn't print that, we need to print it. One can find that the length here is six, which is expected here we know how we constructed this string. On. Another fun function is called upper. So this function converts all of the letters of a string that's sitting here, X uppercase. And then we can print that. So we can see that all of the characters has now been converted into uppercase. And also have NOR, which does exact opposite. Characters here have been converted into lowercase. So that would be it for strings and mathematical functions for now. And hopefully see you on the next. 5. 04_Conditional statements: In this video, we'll be talking about conditional statements in Python. So let's get started. Actually, before we start looking into conditional statements, we need to look in tools like the comparison operators in Python. So let's assume that we have two variables. Let's say that we have x and y, which is equal to 20. And then we need to check whether x is greater than y. Y is greater than x, or are they equal, and so on. In order to do this, we have a couple of operators in Python. So the first one is the equal equal operator, which compares for equality between two variables. So if we say that x equal equal one, and then we print that out. And then we are identical. We can see here that the result is false. So this is like the comparison operator, has two sides, the left side and right side. And it compares the values of these for equality. If they're equal, it will return true. And if they're not equal to return false. And since here we have x equals ten and y equals to 20, so obviously they are not equal. So the answer here is false. And false here is called the Boolean value. And we can have such variables as integers, floats, and strings. We could also have some boolean variables. These variables could have a value either true or false, as we might have seen. And these become very handy in situations where we use in flags and why we're using conditional statements. So let's have a look at that kind of Boolean variables. So let's see that z is equal to x, not equal to y. So this is also another comparison operators. So that comparison compares for inequality. So towards return true if they are not equal. And here we're assigning a value or a variable called z. So the value of this value x0, would be either true or false based on the evaluation of this comparison. So let's take a look at the type of z or to make sure that it is a Boolean variable. And let's run that code. And we print it. We need to print that some athletes. And we can find that the type here is Boolean, which is, as we mentioned before, this is a Boolean variable. So we can actually assign variables we inverted like this. Let's try another one. So let's say we have a variable c m. And this m is equal to x less than y. So if x is less than y, disabled Pietro, otherwise it would be false. So let's em. And R1. We can find the interest that the value is true here, because here we actually have x is less than one. We have also Fraser is then equal. And say, this greater than or equal to x here is greater than or equal to y. And if C1's would paint the results here, It is false because as we know, x is less than y, then of course we have less than, equal or brand that. You can find that the value here is true because actually x is less than y. Ok, sounds good. We know a bit about the comparison of racers here in Python. Let's use this in a useful statement or useful f, c. So how do we, how do you write f statements in Python? So let us look at the symbol if statements. So if we have some condition like f, Let's say we want to print some message. Is that if x is equal to y, so we say x equal equal to y. So we need to make sure this is, we know that this operator is double equal operator. It's not the assignment, but this means comparisons so or chicken for equality. And then we have this colon, colon. And then we had, after we hit Enter, we find that the cursor here is a bit intensive. From the original place where we write, we wrote d, f. And this indentation indicates flux in Python. So if you're familiar with any other programming language like C or C plus, plus Java, you'll find that we would use curly braces like this in order to indicate the block a chair. This is not the case in Python. We don't have these curly braces. We just use this implantation in order to specify that this code belongs or would be executed, this condition is satisfied. So here, x is equal to y, that sprint x is equal to y. And then that's foreign to. You can see that we don't have x is equal to i because here, when this condition is being evaluated, x here is ten and wise flaming sword, not that you make them equal for the sake of this assembled. Then run again and find that you have printed out that x is equal to y. Okay? So this is a simple if statement. We could also have some other French. It's called El scratch. So this branch gets executed if this condition is not satisfied. So if x is not equal to one, the quote inside this branch will be executed. So let's print another message which is next is not equal to y. And see what happens. As you can see it was tiling are getting the same message, which is x is equal to y, because here we have x is ten and wise ten. If exchange them, get twice back to 20. Again. So message has changed. X is not equal to y. So this is also a simple if else statements. Let's look at that a little bit more complex example. So let's assume that we're having some student grades. So these crates or scores are, we have some numeric Cree and discrete sum value between 10100. And we need to convert this, these screens and into their life perspective. Little grates. So let's say that the numeric create this tree, and let's say that it is a 100th initially. And then we have this letter grade that we need to calculate. And that should be just character. And let's say it's initially a assume that Sweden has created. We need to go over different conditions in order to find out what would be the letter grade corresponding to its total, this student, Craig. So we do an if condition. We see that the grain is less than 60. So this is like the failed CRE is with the letter grades here equal to F. Yes. We need to add another condition. But not only one condition, we need to consider the case which in which the creator, rather than 60 but less than 69 or greater than, and greater than or equal to 70, but less than 79 and so on. So we have multiple conditions that we need to go over and over in order to determine the literal Craig. So in this case, using a construct called NSF or lf in Python, that would be very use. So we have multiple if statements, so that first step, and then if this condition not satisfied and goes to the fallen condition, the following elif condition, and so on until it finds the condition that is satisfied. So if this condition is not, so once it finds a condition that is being satisfied that just exits doesn't even execute the rest of the LS. And then eventually aerators, whatever we are trying to return. So, okay, so let's start doing this. So here we have considered the case where the grade is less than 60. So the letter grades here would be f, L if the grade is greater than or equal to 60, less than 17. So in that case, the litter rating should be d. Okay? So n here is like a logical operator that makes sure that both of these conditions are satisfied. Not only one of them, so you need to create is greater or equal to 60 degree, it is also less than seven. So it makes sure that both of these conditions are satisfied. Okay, let's move on. So as you might move psi m whenever I finish the block sites, well, if I go back to the original In addition, so Azure hit Earth to go back to the original indentation because this is how it should period. Again, so that creates is greater than or equal to 70, well, less than 80. We can have the litter radius equals c greater than or equal to 80. And this, and that litter. And then finally, this is the planar condition. None of these albums, and of course the editor create E, a. And then we can just print the literal trade out there. Or could actually walk. So let's turn this. So here now that creates a 1000. So of course, this is an animal. We go here over there, the dire conditions. The first one is not satisfied, the second one is not satisfied and so on. So it just goes into this else and then has agreed to PA, hey, let's change the screen that sing like 65 and see what happens. Okay, so 65 goes over this one. This is not satisfied. Result for this condition. This condition is satisfied. Cos 65 is greater than or equal to 60, but less than 70, so that it's a great years. And it skips the rest of these conditions and just goes to the print because it has founded a condition that has been satisfied. Okay, let's try one more. Let's say 80. So we try, OK. That grade here is B, which is where x goes here. This is not satisfied. This is not satisfied, and this is not satisfied. Them eventually finds this condition to be satisfied and then that isn't created ps sine as a. So that was like a brief overview of the if conditional statements and different types of simple f, MFLs and FL's F. So hopefully you found this useful and see you next video. 6. 05_Loops: In this video, we'll be talking about loops in Python. Two loops are like some constructs in programming languages that are used to do some derivatives. For, for example, for doing the same kind of form over and over again of our sequence data. So that would be a good fit for using loops in this situation. So let's get started. So the first kind of loops that we're gonna be talking about is the for loop. The for loop is one of the most popular kinds of loops in any programming language. And it works like this. So we have four and then we defined some variable, let's say I. And then we define the range from which I will be taken or duration over which I will penetrate and all that. So we can do this by using a function called range in bison. And this function returns arrays or lists. And as we've seen in the tutorial, we'll be talking more about this. But in this video, let's just assume here if we say, for example, range of five returns a list or a range from 0 force. So the starter will be 0 and the last number would be for. Let's try this and print what would be i in this case. And then run this code. So for R1 here and print that. So we can see here that this code sprinting 0123 all the way up to four. So goes, so this range turns into list two and starting from 0. And the last item for which is not including that number that we defined here. We're gonna define a different range. But if we want to start from a different number 0 and end at a different level. So we can also use range differently. Can first commended Codapps. So order to commend that code and we can just press control slash that woman stuccoed PyCharm. Okay, so let's try another thing. Let's say for j. And then we need to define a start and end. So we can start with. And then let's say the aid and print. Let's see what happens. Ok, so here as we can see, the stores here starts with two, which is the number that we have defined. And then print all the numbers all over, well, the way you over seven, which is minus one. So that is another way of using range. We can define the start and they can also define a step. So it doesn't always have to be on the step of one. We can define our step. So let's try this. Let's save for x in range. Let's say. 2102. So here the star should be two, and that is the step. Let's save a step here is to go and print 0, d 246, and so on until eight. So let's try this. Yes, as we can see here, starts with 2468. Of course it doesn't print ten because the range here ends with nine. So nine out of the range, so it doesn't print. Okay? So this is the basic usage of the for loop. We have also some other kinds of loops, which is the line. So I look neat set counter and then a condition. And then we have here the buggy of little. So let's say that we have some variable, let's call it count and it starts with 0. And then we will say that the condition here is y counts less than five. Let's print count. And then we increment. So count equals count plus one. And then around that. So as we can see here, count starts with 0 and then it enters the while loop. Evaluates this condition. If the condition is less than phi or count is less than five, which is true in this case. The prince council trans friends 0 here. And then it increments count by one. So here count is one. And then goes over the loop again, checks the condition. Count now is 11 is less than five years, so it prints count and go increment and so on until it 34. So four will be the last number. It should be printed for this wild loop. So this is another kind of loop. We can, let's talk about something else. We have something called the continue and the prey can do. So the continual, continual keyword is used to simply ignore the current iteration for this loop and go directly to connect iteration. For example, let's say that we're having for Luke is, say that we have a for loop for i in range ten. And we don't want to print every number in this range will only need to print the even numbers. Okay? So one way that we can do this is that we can say inside this MOOC, the numbers, even numbers or just ignored. So if I wanted to not equals to 0. So here, that means this is an odd number. So this condition means that this number, that the remainder of the division of that number by two is non-zero. It means that because all even number, for all even numbers, the remainder of the division. Who should be 0 if we have, for example, and say H by two, that's four and the remainder ten by 25 and remainder of 0. So that is a good way to test even an old number. So even numbers would have OLS remainder of 0, otherwise that would be an odd number. A. Let's go back to here. So we need to print all of the odd numbers. I'm sorry, all of the even numbers between 010 and so on it. So up to nine. Walter doing here inside this loop, we check for each number that we're going over and we see if it is an odd number. We can just ignore it. Or ignore it. We have the keyword continue. Okay? So continue her or simply ignore this current nutritional and go over to the start again if it is not out of the range. Okay, so we need to print other numbers. So print. So if we have reached that point, which means that we haven't ignored the current iteration of the loop. So it means that we have an even number right here. So we can just simply print it, which is what we need to do it. Okay, so let's try this out. As we can see here. It actually prints all of the even numbers between 010. So that's 02468 and so okay. So yeah, that's one way. Of course we couldn't do that, do that. And the other way would just metadata for i in range ten. And then if the number is actually even, that remainder is 0, then just Brand ethnography, which will be exactly the same result. Okay? Another thing that we could use her another keyboard is useful in looks is called prey. So prey, instead of ignoring just the current iteration of the loop, it just gets out and digital immediately. So it's not executing any subsequent iteration, not only ignoring the current iteration. So for example, let's say that we are doing Deloitte again. And while it seeing wise count less than five. And we need to get out the door when we reach that first number. Okay. So we do this, we check if that is an odd number with an amber during remainder by two is non-zero. So we know that is an odd number. And we just prick. And there was the increment count, count equals count plus one. And we can just print number here. So count, I'm sorry, this is count. Right? Let's try this. Okay. So as we can see here, when the number, when we, okay, so for the first iteration number here 0, then this condition is satisfied. It is preempted. And then we can see if it's hard to get out of that loop and then increment a. That's not the case here because even though it continues. And then for the second number it would be 11 is less than 0 or five, I'm sorry. Okay. And then it would be printed. Just again as with our other not it finds out it is. So it immediately predicts outcomes at all. It doesn't even execute this number. And you can get cell to build up and doesn't execute any subsequent iterations or so we still have, we still haven't reached into condition where they count is equal to or greater than five. But here we have set a condition whenever we encounter the first odd number, it breaks out. So Crick could be also useful in many, many kinds of obligations. Unprecedented condition that it see you out at the universe. That condition is satisfied. So this is also one of the most important keywords while dealing with loops. And so that'll be it for this lesson from the loops. And hopefully see you the next lesson. 7. 06_Functions: In this video, we'll be talking about functions. So let's get started. We have seen lots of examples of functions before. As we have been going on over the last few videos in Python, we have seen the first function, we have seen a sprint. So that is a function that takes an argument and then prints whatever inside these parentheses. And we have also seen lots of mathematical functions like seal. And then it takes a flow. We have also seen that before, except float as well and song. So all of these, the print, seal and flora and all of these are so these are like built-in functions. There are some lines of codes that are existing in Python, and they're grouped together so that we can simply call this function and execute. This is lines of code without needing to write all of these over and over again. So in this video, we'll learn how to define our own functions that we could use in our code. So let's start. So in order to define a function, the first thing that we need to do is to say this, which is a keyword for function definition. And then we have the function name. So let's say that we have to define a function that will calculate the area of a circle. And given a radius, which we have done before to use. And we'll do this in the form of a function. So let's say this is hole's area. So this is the name of the function and then the list of arguments that this function will be operating on. So let's say taken only some variable, core radius. So this is the name of the variable. And then we can say that area. This is also another variable, is equal to two pi, multiply pi or three Ts. And of course, in order to use these functions, we're going to use by its simple math, everything. Okay? So now we have calculated the area. And then in order to return this value to the main program or to our code which is using dysfunction. We some keywords called return. So it returns a return from a function today. But the parent function or till, the quote, the quote which called as function. So here we're just gonna return area. And that's worse if we run this, we wouldn't find any output here. We didn't do any printing, we didn't even call that function. So let's first called that function. We're going to call that function. We can use it from like original indentation here. It says you are going to have some radius or r equals two. And then we're going to calculate the area. Or so, as we can see here, calculate area is a function. Britain takes radius as an argument. These two variables doesn't have to mention name, but they have to match the type and into number. I mean the number of arguments have to match between the two function, between calling the function and the original function definition. So here what we're doing here is called calling the function. So that is using the function. We're calling the function that we have implemented. Okay, let's run this. This could execute spot, it's not printed anything. So what we can do here is that we can say that x calculate area. So x here, we'll store this value, the return value from this function, the value of area. So this is most likely will be a float number because this function returns a float. So this whole calculation would be afloat. So this would be a float number. So we can simply capture this value returned back from a function by using some variable in the main code. And in this quote, We'll call this variable x. And it is just storing the value returned by this function. So then we can print x B, the area calculated for this specific radius. Ok, so let's try this out next sprint. And here we go. It actually calculated the area and printed the value returned by the calculate area function. Forcefully can't change or, or let's say we have another variable. Let's say we give it the value five and then say j, calculate area. And then print Jane. And we've got the other calculation as well. So this is the basic idea of a function. So some code or some statements grouped together defined 1's in the code, and then we can use it multiple times. So it is highly, highly affects the code reuse in our source base. So it is really important to implement functions within our code as much as we could in order to use good and not write lots of lines in our current. Okay, let's try another function. Let's say that we have seen the function len before. So we have a string, it returns the number of characters within that string. Okay, so let's run that 11 characters here. So let's implement our version from them. Let's see how can we implement them. So in order to do this, let's also define a function. Let's call it customer then. And then it takes some string, let's call it S. Then him doesn't match. So how are we going to calculate the number of characters for this string? So what we can do is we employ our previous knowledge from the previous video about loops you have in watching this. Go over it again. So we can go over each character in the string. So in early to do this, using for loops, you can say four. And let's define the variable that represents the current character and then n. So instead of using range as we did before, we're using switches, the whole string. So here, what this slide says, do this for each character. That's true. What are we going to do? It then increment some counter count equals count plus one. And then we need force to define town's first and initialize it to 0. And then finally. Also, by the way, we could do this increment using different way. By sum, we can just say plus equals one, which has exactly the same as incrementing the count by one. And then we can return to account for senior to make sure that you're using the current and the correct indentation. So this returns should be on the outside level of dysfunction and that would be our function. Okay, so let's test our customs in function. So let's feed it some string. Let's say the string is lower and not already consists consistent with 11 function that is living characters. That is what the original LinkFunction told us. So we can apply this custom then of course we don't need to say that symbol, strings, any name, do you gonna have to match? And let's store this in some variable called y. And then let's print. Let's run this code. And then we see that actually this function prints correctly the number of characters. Then our code, and I'll then our string. So here we go. We built our custom then function. So that would be it for today. And I hope that you can see that functions are a very powerful concept. And see you next video. 8. 07_Objects and Classes: In this tutorial, we'll be talking about objects and classes in Python. Objects or entities that encapsulate both data items and functions or methods that operate on these kind of variables. Unless there's a blue player blueprint where we create objects from. For example, we could define classes in Python. Very simply, just student that keyword class. And then the class name did say that we were creating a class for students from which create different students, different data items or different values. So let's first see how do we create objects from a class. So we can write something like passed surpassed whenever you write a parser in a class or a method, it means that you're going to leave it empty for the time being. In order to know not to generate any URL, you need to write this skewered best. Socialists having an entire class. For now. In order to create instances or objects from this class, we can just create a variable, let's say student one. And that would be equal to EPA to the student. Parenthese. We can earn this code. Of course, we didn't print anything. We can just print to then move on. And we can find that it is a Student object at some specific memory location. So here we're instantiating or creating an instance from the student class and disassemble desorption school student one. And of course, if we have some other, sooner can create student to student. And then we print students. That would be also another innocent and a different location on distance. Okay, so now we know how do we define classes, that keyword to define classes, and how do we make an toxic to create an instance from that class? Let's move on to exciton different variables or data variables for this. And so we can't assume that students would have different variables like, let's say student along, they voted tie that firstName. It say this is our first said the first name and last name. Then we can also keep track of which students beam. Now. We can also keep track of the phone number. And so this is how we sit different data variables for each instance score for each object of the class. Using the dot. We can define the different variables were the different values for decades have variables for this object. So here for a CDMA code. First name, last name, email, phone, we might have a grade and so on. So this is how we can do the same for the second student. So they are different instances. P Student two. And we'll have a different name. Amen for s2 is the firstName. Lastname, phone number. Okay. If we run this, we still didn't see anything, but, you know that we have sent the data variables for each distinct. So here we can see that we have two different objects. And each object is mainly a student. So it is an instance of festers in class. At each one of these objects have different data types or different values for the data variables. So we have different students, each of them has different, would have different names and they will have different emails and phone numbers. Holes. We can print that we can print. Let's save. Wanna print the first name. The student, one, student one to the first. And most have been a student, and will actually print the full name. So as to last. And you do the same here for student one. Small, let's run this. And we can see here that we print the full names for each of the students using data variables assigned by each of these instance. Okay, so that is a good way to, Let's start to actually define the different values for data variables for objects from classes. But there is a more efficient way of doing this. And this way is by using an initializer or equity structure within the class that actually sets these data variables at the beginning. To do this, here in the class, we should delete, dispense them. We defined some special method called init. So we define Mint, takes this first parameter or the first argument's self. So self here refers to the instance that's class or object that's been initialize it. And let us think that we're going to initialize all of these variables. The last email. And then we can see that self, that first, which is the first, the first name for that option, should be equal to the past. Firstly, the last name print the object should be equal to whatever we said. Set it to be email. Notice Same here. And one would be the past form. Okay, so now we can see that we can set all of these variables once when we create the object. So foreign and notice here we set them using the same order. So here's self is ignored. When we do actually instantiate and decode. It will not pass the object itself because we know this is the option. So we'll start from the first, so the first name here and say it use the same data here. And the last name. And email. And finally in a phone number. And we can comment all of this. We don't need them. And we can do the same for the second student. Copy this into. Here. We said the firstName, lastName. And that would be a male and the phone number. And we can also move all of these clients because none meantime anymore. And then we are printing the first center last name again and see what's happens in this case. As you can see, we also print the first and the last name, and it does exactly the same. But here we can see that God's more compact. It's less error prone in here because we do not have to write all of these lines and define all of these. And I have variables one by one. But since we're using this initializer or Dennett's function or the constructor as you might call it. In order to set all of these variables initially, when we are carrying it in, we're instantiating the objects from the class. So this is a very important concept. Classes and objects or object-oriented programming using the constructor that ordain its function or method. And we can also, instead of, instead of printing on multicores, typing all of this, we can define a method within the class. You'll print full_name, since that would be a functionality that we'll be using a lot. So we can define a method for that. So we find that say Print Full Name. And by default it takes at least the argument which is the ultra itself. Okay, so here we can print first or first. Plus Sawyer doing concatenation here and last. And instead of doing these two lines, we can just comment them out. And then those student one, print full_name and get into a friend fullName. And we can run, we can get the same exact results. But we don't know tag to specify all of these. All of these. Every time we need to bring the fullName already have this defined in the class and all of the objects of the classwork give that function. And this function could be applied to each of the n instances. Okay, let's define one more method. We can define a method, let's say changes the phone number instead of doing that manually. So it can do define, change form. And of course it makes self as well. But here we need to change the phone number, so we need the new phone number and b to be used and the updates from them. So also need to pass the new phone number. And in order to do this, update its 300 symbols. So cell phone, which his daughter's phone number would be changed to the newer form that would be provided. Okay. So let's say we wanna change then here, changed the phone number for the first student. So the student change form and then will best than your phone number. And see this is the new form number. Then we can print Student one to make sure that it has been changed. A. So let's run this. And as we can see here for Brenda CD14 number, we can see that it has been actually changed through this method that we haven't defined in our class. And here, we could also have some variables in the class that do not depend on the incense itself. So we can have a variable at say, contract down the number. You didn't. So the total number of students. And initialize that to 0. And read to count. Each time we create a new silane we need to count and you or increment that number. So the best place to do this would be the __init__ and the unit method, which is the constructor here. So this is the method that gets called whenever we instantiate a new objects from that class. So that would be the perfect place. Who count or keep track of this counter here is totally stupid. So in order to do this, we simply add the class name dot and then the variable name, and then incremented. So every time this init method is invoked, so every time there is an instantiation from that GAS, this counter will be incremented. Then finite n, like print that in here. So student, the students. And we can print that after we have created to students and run. And we can find here that the numbers that took a number of students so far as to, because we have created, so add instances of this class, which in our student one and student to. So that would be it for this video. So we have talked about classes and objects and degenerate concept that could be used. Contributing causes an object. And then hopefully that was useful and I'll see you next week. 9. 08_GUI (Graphical User Interface): And this video will start to move into a graphical user interface programming. In Python programs. So far, we have been looking into producing some output in the terminal window or some command line window, which is a black screen with some text inside of it. But actually we can do more than, we have lots of frameworks that would enable us to a, build some programs using graphical user interface. It has windows and has some lemons like Path6, buttons, radio buttons and check boxes and so on. So in this video we'll look into how to do this using the best in Python library through GUI programming, which is called decaying. In order to start using TK Enter, which is the library for everything joy programming in Python. We should just need to import it. Like we did was the Math Module three. Remember? So we just take KMs are esoteric and then we start try it in our pool. So the first thing or the first basic element that we need to have in order to build a Windows controls can actually have the window itself. Over time. A window, we can have some variable, let's say window. And then the variable should be an instance of a TK class. So this is the main TK enter class that enables us to build a wind to. So the first step to do is to build an object which is an innocent, an instance of that class. Then in order to show a window, we need to write something cause window dot main lobe. So main loop here is the method that instructs Python will start listening to events and actually displayed the window on top of that application. And of course, it looks every code that is written after this line. So every line in here, what you blocked until the window. So all of our work, all of the code that we need to do for the GUI program should be inside in here between this instantiation and doing the main loop. Okay, so let's run that. You can see that we have the symbol small window. We can actually like other title for this window. So let's say that when either tightens saw the window, the title, and then write and say, well, they're learning. We know that. We can then see that the title is shorthand, but it's not completely shown because of it's small. You can actually control the size of the window. So we can do a window, could geometry. We save the size in pixels. We can define engineer, let's say it's 415 and run again. Now we can see that the title here fits in Darwin's. Okay, so now to do that title when you have to define the size for the window, let's move on to actually add in some controls. Within doing so controls them that TK, Tkinter library are called widgets, so it can add widgets. Within our window. We have different types of widgets. The first one that we'll be talking about this to label. So in order to enter labeled, let's define some variable. Let's call it LP rail. And then we have the enabled us and insight enable fast. With the first theme that we need to do is to attach it to the or window. So that is the first argument. And then we can have some text here. And let's say that takes here. And we'll run that we still don't see are labeled. Why is that? Because we didn't define the location or how to add this enabled him to our Wendy. So one way to do this is to actually use something called the grid. So we have MRD called credit. And then this, we can define which column and row should it be on? What did I say? Its column equals 0 and rho equals 0. Now, we'll close this and run again. We find that the labeled here actually shows up row 0, column 0. There are many other ways of defining the exact location of widgets, but let's stick to this approach that V. Okay? So let's also at some fixed, some place where we can actually insert text or input text from the user. And this is called an intron ticking. So an enter in order to add an intern can just simply having a variable with an instance from the entry class. Of course it should be attached to a window, to our window. And then we can maybe define the widths of these texts or this entry in pixels as well. Let's say it's 20. And again, we need to attach to the Dred. Let's say its column one and row one. Let's find it. We can see that we had here a textbox here that we can earn texts into. Let's say there's some texts. And it is actually in column one and row one. Okay, good. Let's move on to the next window. We can also add balance. So let's say we have a Watson. So we have this bottom class. And we can, we first need to attach a tall window as well. And then we can define the text thick medium, for example. And then define the grids. So let's see, it's called them to row one. So it should be in the same row as this fixed, this entry. But the next skull. We can see this. Bhutan has been added and it has the text at worst, who can also add, let's say, some background color. So we can see Vg, which is the background color. You can define something like hello and foreground color. We can say something like considerate and run again. As we can see here, the colors are changed of course include under this was mostly Any kind of widgets. These progresses can be defined within any kind. We can also define the phone and the phone within the labeled. For example. Let's define some form. So here we can say font equals. And then we have these parentheses and thirst weekend to find a name that saved skirt old. Then we have a comma and we can define the size as we would say it's 12. And her eyes again. And we can see here that the fund has been changed a cause, and you don't want something that's interesting here, let's say that the user will be required to enter his or her name. And then we print out a message to the user using listening. Okay, that sounds very simple. So let's see how we could do this. So first, we say that we need to add a label. Down here. Let's say it's able to fill-in the user to enter his or her name. So we attach a window and that takes us enter name. And for the grid. And seeing Skolem 001. And here let's say this is the entry handled column one. Well one, okay, that's fine. And this button will be on the same line clone to L1. And it's termed IS. Okay, the layout looks fine. So here, this is a labeled instructed. The user's answer is sitting here, should enter his or her name and then taking that in order to have some kind of action associates it with your button. There is some progress Ecoles comment from the Muslim. So here from the Watson math common. And this takes a name of a function. Say this function is hermitian. So of course, creatures or smoke defined yet. So we need to define that function. So as we did before, finding a simple function. So this function should take the things that the user has entered. So notice that to get the text, because there is enter, we have dismissal, missiles, calls, get yet. So we have this as the entry and this is the message gets. So now we have here was name could be stored in data. Now we need to like have a message box that takes the username and then adds it in a message. So in order to use a message posts and dictate. And third, we have, first import the class for that school. Here's a message box. And here we can say message box, show useful. And then the first parameter here would be the title. And say learning. And then we need the actual message here. So the actual message here would be hello and then username, which we have captured before. Okay, so that sounds good. Let's try running. This. Is enter your name that same element, then click here, I go to a message, hello. Okay. So that was like a, like a brief introduction to decay insert. And hopefully that was useful. Then. See you next video. 10. 09 _Lists: In this video, we'll be talking about lists in Python. So a list is simply a sequence of values. There could be any of any type, which could be strings, integers, floats, objects that could be of any type action. And these items are, these values could be changed. So we could change the values of these items. And they're also sorted, saw their orders. So we have the first item in the second item and so on. Lists could be defined in Python and many different ways. So the easiest way to the final lesson by Tunisia's doing close the items within these practice. For example, the Phono defining this called a. And that would be initially an empty list. So we could just say a equals and double empty square brackets. The printer type II here will find that the type here is a list. To a list could be simply defined by using these square brackets. Okay, in order to have a list that has some items for some values, we have a list like this, 1234, and so on. So each value here is separated from the next value using this column. And this could be indexed using an index like we did in strings, if you remember. So if we're gonna get the first element here, my less than 0. And then print that out. Print one which has the first filming or this list. Let's try it with another index. Let's say three or four there under the nth item at index four, which is five. So this is it one is at index 02. At index one, three says is at index two and so on. Okay? So we could also have the length of the list using the len function that we use to strings as well. So a free tool, Lynne my list here and print. That would be five, which is the number of elements within this list. Okay? We could also use the same slicing techniques that we did was if you remember slicing from strings, we want to have something like that. So what does this mean? It prints all of the elements in this list, starting at index 13, but three is not included. So here, that should be index1 is two and this is two. So it should print 23 if we didn't. So let's run this. So actually we get another list of these two items. Okay? So we could also use some other tricks we're slicing here. So if we like the first index here, why resorts slicing? It means that It starts at the first element of the list, starts at index 0. And then we can say, let's say three as well. Footprint that. We can see that here it returns another list which consists of three elements in the original list, which meant the one. And then say, let's say from one. And then we do not specify the number here, the second index. So it prints all of the items, can be the last index. So starting index to the last item in this list. We have also mentioned that lists are any types of theta. So we can have some new list. And this list we could store different types of variables. So we could say a string here and integer, float. And we could have even a Boolean variable, true, could have character. And we have an object from a classroom could also have this toward realist. Print this new list. We can see that all of these items, so a list which is a powerful feature and Python could have any kind, any kind of variables within the same list. Okay, we can also have, let's try to print this list here of 0. Indexing work as well. So it prints the first element here which happens to be a string. So that proves that lists are ordered. So we could access elements using the index to the first element is at index 0 and so on. We also mentioned that lists are mutable. So mutable year means that we could change elements within the list. So let's say that we want to change this to two B, for example, cat. So how could we do this? They do this in many civil waste. Let's just try the simplest one. So two here is at index one, right? So could simply seeing new lists of one equals f. Okay? And then we can print new list. We can find now that the second index here or the second element has been changed from two to cat. Okay, that sounds good. We can also add elements to the list. So the first way is to add elements to the end of the list. So if we're gonna add another element to this list and say we want to add to number five. We can use a method called add some element to the end of the list and say it's five, then print. Okay, as we can see here, this list has been grown. So the last element here is dawn that we have added. But this is very limited, right? What if we wanna add some elements in the middle of the list to react to specific index, let's say, and X1 and X4. We don't necessarily always want to have some item to be added at the end of the list. Luckily, there is also another method for that, which is insert. So we could also use this method, Insert And now takes two different arguments. The first argument here is the index we want to insert at. And the second parameter argument here is the object or the data that we want inserted this index. So you can see here lets say owning, insert at index two, the value, let's say. And then we'll print the new list here. We're under. We founded here at index to the new values elephant. And all of the other elements originally starting from index two has, have been shifted. One position bank. So all of these elements, 10.5 through 85 had been shifted by one position. So this is also a very partial method that could be used within list. We want to insert at a specific index here. Okay, so let's move on to the next thing that we want to discuss here. We could have, but it's one I like search or a specific item in index. So this is our lists right now. Only see we have an item that's net present value of cash within that list. So it could use the loops that we have been using before. You could. We could do, or let's say you do this. It's a cat. And foreign debt, we can find that at, found near. So this is basically going through all of the elements in the list. So for IE, which is an element in new list. So all of the items or all of the values in our list, and it goes right by one, at least indices. One value is equal to cat, then it prints the statement. We can do this in another way and simply have one condition. You can see in your list. Then the print list. You didn't even have to cool full disclosure. I don't have to do it that way. So we'll consume Tiran there. And also I could find that it's trying to find something which is not. Then it saves time. Of course it doesn't find it in the list. Then doesn't prim That's so this is an easy way of assertion within the lists using the keywords in and just using a condition. We don't need a loop here. This is done internally by Python. We don't need to worry about. And of course, as we have mentioned, we could use a new tool, the tree to all of the elements or the items within the list. So for an print these items one by one, we could see for c x equal to x. So if we do that to find that we have printed all of these items one by one within the list. So this is no aid to iterate through the list if needed. And we have also found out how to search the list for a specific item. Ok, so we have also seen how to add items, how to search for items. Now let's see how we could then remove items from the list. So in order to remove items from the list, we have to measure methods. Actually there are more than that that we're discussing in this video. The first method that we could use, gold remove. So when I remove the capstone list, so we could simply say, you list the train moves. Then we send the value at the end. Here, we need to send the value that we want to remove some list. So let's say we're removing the value of k. And then we could simply print it out to see if actually happened to know. And as you can see here, to catch us no more, no less. So remove is a method that will breed some lists that takes the value of the 200 and move as parameter. It's not taking the index. Okay, so that brings us to the next method. What happens if we wanna delete from a specific index or at a specific index and don't actually want to use the value or we don't even know the value of this index. Actually, there is another method which is called up. So the Buckminster jury takes an index. So for noted see moving item index here. So it should remove elephant. But let's assume that we do not know that the item at index one is. So we could do this. And then print list. So BOC hears only thinking to index the tuna, remove an item. And let's try. As we can see here, the item elephant has been removed or the venue in the front has been removed by just using the index that we passed. So this pump, okay, actually book also has an interesting feature. For example, best if we didn't pass any parameters that the bulk myth, what should the trim of? Let's try this, append, this sounds pointed and think of it. So if I just it all and then you list, you can find that tends removes the last item fits. So if we don't specify the index one, I remove an item from Minnesota. It's just simply removes the last item of the list. Okay, sounds good. Let's look at copying lists. So now we have this new list on a qubit in a new list, or another lists bulge at say list1. So how could we do this? So we need a copy of these contents on the list of the contents of the list to another list. So you might think that we could just simply assign it to the notice that we want to call the firm. So this one equals new list. Okay, so let's try this out and print the list and print a list one. And it's actually prints the contents of venue list. Okay, but this is not actually copying the list. What we did here is that we mean list one refers to the notation if new list. So now both the awards new list and this one, they are both referring to the same location in memory, but list1 is not actually a copy of it. So how do we prove it? Let's just change something within new list. Let's say you list that Bob, just remove the last item and then we're not printing new lists toward clinton. List fun. And see what habits. As you can see here from these statements, we haven't changing list1. I don't write down the thing that you have changed here is new list. So we removed the last term for new list. And now let's see how this fun looks. As you can see here. And actually change. A new list has been reflected in list one. Even though we didn't even touch list1. This is because we didn't actually copied this new list into two lists. One, we did make them both reference or both. Point to the same location in memory, but miss 20 snot Jacoby nearness, it just holds the same reference. So this is not the correct way to copy items or Colby lists what we have the specific method to that. So if want to have list1 to be a copy of newness, so it could notice new lists, the code. So I have this method copy as W on this to another. And we are in the, let's move this time from now. It's not remove anything from unicef. And now let's hear from your list last night. And then we'll print this quantizer. As you can see here, printing list1 or using the coffee may be affected when we remove some item foo new lists. So. This is this one. And this is, we can see now here that both of them are having different values. So this one is having the complete four items, but new list as the last eyes removed as we did here, using departments. So this is the correct way to copy a list using the copy method and not just signing your name to the oldest. Okay, that sounds good. Let's move onto something else. So one thing that is interesting, which is the range method. So we mentioned wind, we're talking about loops, the range method to generate ranges. So let's say that we want to generate all of the odd numbers from one to ten and stored them in a list. So if we do this, we note that the range takes the first number and the range, and then the less than Bernanke would have the step. So let's save it would range, which says that look number range. And then we could print a number, right? Okay, so for a blueprint that we don't find like Ghana's something very useful here. It's actually you just mentioned that it's syringe and the first one is one and then the last item is ten. And then we have a set of autofill. Wanna convert it into a shape of a list soul in half. The items that we are talking about, the odd numbers from one to two. We could convert to the range coalesced us in a method called Les, which takes this strange. And then we can print this units. Okay, as we can see here, we have, we now actually have the numbers, the numbers from one to ten by converting this number range into August using this method which is called OK. We could also then we would like some mathematical functions over the lists. So let's say that we want to have the sum all numbers on the list. So an easy way to do it wouldn't do use a loop. So for seeing numb, they're each number in this list. You can see that sum equals j. And then we could finally some, let's call it some other. Some men could initially equal to 0. So now here we're going over each item of business and then add that item to the sun. And then eventually we're printing the sum. Ok, we can find here that the sum is 25. But we actually needed like three lines of code in order to address Bison who could simply do this in one line using the built in function sum, which takes an interval. In our case, we're using a list, which would take a list here. So if it takes so list num which has the numbers from one to nine. And then cold this methods some her, we simply has the same results here as 25. There are some other function that could be done non-numeric lists. One of them is called max and get the maximum number here, which is of course mine. Yeah, full sun other function which is a certain minimum number here as fun as well. What it going want to have the average? Let you think about it for a second. We could actually have the, the average very simply here over the list. So day in definition of the average or the mean is the sum of the number over the extra number. Are they count numbers that we have? So we could simply use dismissal methods, sum, and then divide that by our list here, which is that's p, r f, which is five, as we can see. So that is something that could be interesting, that could be useful in many application where we don't have to do the actual by ourself. We don't have to implement a quote from the summer to max for the men. But Python had as some function that goes over this list, the whole list and aggregates the summer, the maximum and minimum, and so on. Okay? So one last thing that we wanna talk about in this video is multidimensional list. So as I mentioned before, list could have elements of anytime. So we found, we looked into a list where we have different types of variables here and the string integer flow, a Boolean character and so on. We can also have lists of lists inside them and as elements. So this kinds of lists are closed nullcline dimension on lists. So for example, you could have it sitting on it. So this is a list. And instead of having just And I'm bar simply like this, we can have the lists, lists. So we could have missed here. And we'll put that in another list here and there and so on. So we can add these numbers and some other numbers. And here, another list here, and so on. So this list is called a two dimension on this because the mainList consist of. And elements, and each element is a list. You could also have more dimensions. So we could have three-dimensional MNIST and seeing the list. So we have that outer list, list. And this inner lists also consists of lists within them. So that would be very annoying to write, but you got the constants here. You've got that if we have lists of lists that this is a two-dimensional list, we have lists of lists, of lists, that would be three-dimension list and so on. It could have any number or any number of dimensions within them. So let's stick with two-dimension here for simplicity. And this is how we define that two dimensionless in order to make them more visual to programmer who could do this. So could simply have them as rules like this. Being just print the list here. We can find that it is a list of lists. Okay, so what happens now if we tried to access this list, an item, the item at index 0, and expect that it would be a list itself. So we didn't print that out. We'll bring that out. We find that we've got the first element, which is that, which has an entire list. But this one, I go to that number to watch a funny this element. Then we need the notes at another living indexing here. So at this level gets close to the first array or the first list. And then within that list we want to get that item wishes index1. So for reinvent down, we get that item that we want to do printing. So let's try another one. Let's save owner that item nine here. How do we get that? So the first thing that we need to do is to get the list, that list. So that list is index 012. So index. And make sure that we note that exist in. So this is the list that we're looking for. And then we need to get item nine. So within that list, item nine here is at index 01 to the other level of indexing that we're doing here. And as you can see, you go on to item nine in here. Okay, that sounds good. Also, all of the methods that we have mentioned before also applies to these kind of lists. So they're basically lists. So we could also do that technique of slicing that we did before. So something like that. Then gets us one of the items that list from index 0 to index one. So m indices 01. So that shouldn't be that item. And that's otherness, which, which are printed out in here. Will slicing works. Unlike, let's say, let's just try appending elements. So M list. Let's say we're passing another list here. So solicitor 131415. And then you will find also that item mere or this list has been appended to the main vein tiredness that we have defined as MS. Okay, how about iterating over items from this list? Well, let's say you want to print all of these items. Sure, 123456 and so on, one by one, or iterate. When we add them mostly dimension, sorry, passing one-dimensional. But when we do this for x and best, and let's just print material. This is not the case if we do that, it would print individual lists within the list, atone and print each number, each visit individually. In order to do this, we need what we call a nested loop. So that little blue pen, an additional loop inside it. So for y in that case. So here we have the mainList and x here is each individual list within the mainList. Then we need, within each individual list here, we need each item, each value within that smaller, and then we print y m here. So let's try this out. And as you can see here, we could simply print all of these items or all of these fishes individually one by one by using this technique of nested? No. Okay. So that would be it for today. We discussed the lists, some of the methods and the techniques on this and multi-dimensional lists. Hopefully that was useful for you and see you in the next one. 11. 10_Inheritance & Polymorphism: And this video will continue our talk about classes. So this one would be talking about inheritance and polymorphism. And we'll see what, what both of these features may. So let's first start to inheritance. So here we have the class between middle class time from the classes and objects video. We had a class of students we could make or create objects out of these, of this class. Here we have the net method, which is called whenever we instantiate an object from the class, also the constructor. And he recreated two methods. One of them is to print the full name of the student. So it takes one argument, which is the innocence of the classroom, that object, and some other methods which is used to change the phone number for dexter. So let's talk a bit about what we mean by inheritance. So inheritance is a situation where we have the base class and a child class. And this class is inheriting all of the features from the base class. And I might add to them. So what do, what do I mean by that? So here if we have another class, let's say this. For the student class, we have a special kind of students, which is a grad student. So grad students are this kinds of students who are pursuing a masters or a PhD degree. So let's say we want to create a class which is called a grad student. So if we create that class will mean the same thing here name, and we'll need that firstName, lastName, email, the phone. And we might also need to use these two methods, print full_name and changeful. In addition, we need to add some other maybe variables or some other methods. So a good idea is to reuse the class because this is still a student described sin is still a student. It is using the same variables used in here. And it would seem it will use many of the functionality to use in the student class. So one way to do it in order to reuse code is to use inheritance. So make this grad student class inherits from the student class. In order to do this, we just add these braces here next to the class name. And then we write down the name of the class that we need to inherit from, which is seated in this game. So now in this case, we know we have this grad student class is inheriting from the base Student. Could we say Warner? Just leave this empty for the time being and make sure that this is, now this class is actually like inheriting from the student class. We can use some function called subclass. So this function is testing whether a class is a subclass of another class or not. So clear, let this grad student and student. So this is saying test whether this graduating class. A subclass. Subclass is the same as a child. And since grants Sinan classes inheriting from the same class. So by definition it is a subclass from the student-led soy footprint, this result down here and run. We can see that it returns true actually because the grad student incentive is a subclass or a child class or just given to us. We tried to do it the other way around if we test to see if the student class is subtracted. Rather the student class. And of course that is false because this is the reverse. We have this grad student, which is the subclass from the silicon. Okay, so let's go ahead and finish our grad similar class. So let's say we still have our init function here. And of course it will have also the firstname for the student. First and the last name and the email. Maybe using the phone as well as erode added on. And another field is that degree then tested in his persona whether it should be a master? Repeat again. Okay. So in order to initialize an innocence from that class will still need these firstName, lastName email. So what we could do is the way that we did before. So self depth-first, first, and so on. But we can see here that we're using a lot of this code from the init method, from the super class or the parent class. So could we use it? There is obviously a way of using this, using the old code or reuse and dual code. So it could simply say student dot. And then we pass the parameters that superclass or the bearing plus or structural can use. So of course I can use the first, the last, the email and the phone. But of course the degrees, some new variables that we introduced hearing discredit student class. So we have to do it separately. So I have two men read that. Note. Agree? Agree. That's it. So here we could use the init function from the main class or the superclass. We don't need to rewrite all that code again, but we only need to write new code for the new variables that we introduced here, which is the green screen page. There's also another way instead of typing system we could use for not sure about the name, we could just use the super method. So this is a built in method in Python that automatically goes to the superclass water parents class and Jen here, we're fetching. The next method are calling init method over. These are. Okay, so let's say that we also need to keep count or keep track of the counter students that the grad students set we're actually instantiating for mere. So it could have some other variable. And it totally grad students. The same trick that we had before in the student class who had tutors students. In the init function. We could also say that students plus equals one incrementing discounters to keep track of students that we are the crisis in debt to instantiate informed discourse. And of course, we need to use the name in here. Not what's in the grad students. Okay, sounds good. So see what we can do again here. We can also have another method usually mentioned that in the subclass we could have mission functionality. We're not using the superclass. So let's say we're introducing a new message called Ben degree info. And then only takes one parameter which is cell. So this is basically saying printing which degrees this student resume. So here we'll have the first name for the student is pursuing, then that inquiry. And then we can format this using. So the first one here is the first thing. And the second argument years to decree degree. So this is an additional function that we didn't have in the base class appearing class. So here we had only two methods, print full_name and change font. Here we're adding another message which is crammed degree in food. And of course the grad student class, any object you could use also the print full_name and the change form methods from the parent plus, as we mentioned before. Okay, so let's try out these two classes. So first let's create two students. Students sit in one and you take the firstname, first last name, email and phone numbers. And scary to another system. Let's let's check. And you will have a different phone number. And let's create a grad student here. It's called a G as one. That would be a grad student. Here we need the firstname, CMI. And we need the form. And we need the degree here, which is the additional variables that we have introduced. Let's say it's a limit h. Okay? So let's try these methods. Let's first try one. We said that the grad student class should be able to make use of these methods so that spin to fullname. And then let's try scientists out first. And we can see here that actually prints the fundamental decision which is the first and the last name. Let's comment this out because it's using right and run this again. And we can see it prints the full name. So we can, we, we can see here that this print full_name method is only available in the base class. But by inheriting this into that and the subclass, we could also use this method. Looking. So let's try sometimes that see the grad students and let's see the Tilton students. Let's find out what are the total what is the total number of students first? Okay, we didn't bring that out. It's printed. And we can find that the total number of students, three. Because here every time this init function schools, we're actually incrementing the total number of students. We, whether this student said grad student or a typical students. So we have three students down there. We have instantiated three students with three student objects. So it counts three in here. Okay, how about grad students, the number of grad students? And that you can see it's only one. Because here, this toxin grad student variable is only available in the subclass gradually dynamic snot available here in the base class. So as you can see here, that the concept of inheritance is very useful. In many cases. We can also use this other method that we implemented. She's been decree and the full. And then around that, we can see that Mike is presumed PhD degree, which we have assigned here. And this is how this function and this method operates. Piece that would be all for this. Selection to inheritance. And let's move on to the next topic which is Polymorphism. Polymorphism is something that means current in many different forms. So what is the meaning of that? It means that we could have, let's say, a method or function that tests the same name. And it could operate in different objects or exists in different classes. So let's see how we could do this. Let's say that we have another class gets called discuss employee. And this class has an init method. We'll have the first name and last name, and the address, and for example, the Age. And we can do this again, or initialized the first, firstName, lastName, and the address, and also the age. And then let's say we have the function here, a method called print. So print full_name is a function that happens to be of the same name as this pen full name. And another glass, which is students. But this class or totally the employee class and disillusioned, totally unrelated. So there's no relationship between either of them. So here we can say employee name is when we have these placeholders and format first and last name. So what we can notice here is that we have now two classes were actually three classes. And all of them have method that has the same name is discussed. This employee class is not related to either students or graduate students, but to tenants to have some method which has the same name, we could use. The property or the feature of polymorphism is calling this function with this method, different options, these classes. So let's create an object from that nuclear class and states employee. And then we need the firstname, Steve johnson. And the address is Main Street. And the saints, 13. And we have already created some students here. Let's use any one of them. And let's create a list which contains the employee. Lets say student one and student than currently sit in one. And for each of these elements in the list, we can call the print full_name because this spring foaming is a function that will ornamental Death exist. All of these or respect in all of these instances because it's implemented in all of the corresponding classes. And let's run that. You can see that here we created would print it. Got it got the output from this method in the employee class. So employee fullname is then also the outputs from the student. Plus, because this is how this function is defined. Print first and last. So we're using a function or a method that has the same name in different classes. Of course, a function could exist in different note with different children from the same base class. And each of them would have the same name of the method or a method of the same name and we can do the exact same thing. So that was like a brief overview of like the inheritance and polymorphism features in Python. And we talked about both of them. And we are on a simple application, an example providing some details about them. So that would be it for this video. And I hope you enjoyed it and see you in the next. 12. 11 _Files and Exception Handling: In this video, we'll be talking about files and exception handling Python. So let's get started. There are many kinds of files that we can deal with an oil using our computers and writing. In any programming languages. We have text files, multimedia files like images, videos, the databases, and so on. In this video we'll be focusing on text file for simplest. In order to deal with two fives in general, there are two major functionalities that we need to do, which are read or write. So we need to read from files and we need to write to files in this video to do these functions. So the key method that we'll be using is a method built in method in bison called Open, which takes many arguments, will be using this method for both reading and writing to a file. So the major arguments that we need to provide here is the first one is the path to the file to be read or written. So the path here could be an absolute path or could be a relative path. So we'll be focusing on relative path. A relative path means that this file location is relative to our current working directory. You can see your current working directory navigating here to the left pane here by sharp. You can see that this project, this project is called files. This project is located in this path. So if you go to see users and then this directory, that would be the directory that contains our files for this project. As you can see here. We created this phi, phi p y, which is the Python script that we're writing, right? So for this video plays or our files inside this directory, the one that we're currently working in. And in the exercise file, you would find the file that caused that to repeat a TXT. So please go ahead and copy this file into your current working directory in which you can find by using this directory in here. Okay? So this LWD is dissemble file. It's just a text file that has fewer lines here. And we'll be using this file to read from. Okay, so let's start by opening up this file and let's see how we can read from that file. So as we mentioned, we'll be using the open function. And the first argument that we'll be using is the file location. So using relative location here or relative paths here. So just need the filename because we're dealing because both of the script and the filer in the same directory. So I can just use the filename. And then we need to define the mode that we'll be using. So mod here could take many different values depending on what we're trying to do with this file. So for this one we're just trade treated. So just use the MOOC are so small r's refers to read pseudomonas hero period. And then we need to assign this to some variable name. Okay? And one thing that you need to be very careful about is that you need to close the file once you're finished operating on this. So it would be a good practice to have this functioning or close method called veneer. Or they're not to forget to close the file and then the logic would be between these two lines. Ok, so this creates an object that opens a file as a string object. And then how do we actually read the contents of the file? So one method that is that we can read it line by line. So there is a method called read line. So if we call this method, and then let's say this is the first line. It actually brings us line by line from the first line here. And we find that that is the first line for non far from our file. This is the first time from our fun. One I get the next time. We can do the same again, raised line again, and then print second line. We can see that it also prints the second line here, which is that line. And so I'm a fluid. So we also got the third line here. So this is one method you can read line by line from my file. And that doesn't also work in all of the cases. If you have like a very large file, you cannot unless you're using some kinds of loops or, or, or something like that. So this is one method, readline. What if we want to like read some other or read the entire file and want us to do this after closer. And then we open it again here. And let's try to print the whole file at once. Metadata. So we have a method called periods lines. Sorry, headlines is a method that we could use SML. And if we just print it, of course, and forget to close here. This small mountain smartly. And run again. So you can see that it returns a list. So this list has multiple items and each item represents alarm. And you see here that each line here backslash n. So this is a special character for a new line which indicates a new line character. So this is also another method that we could use if we want to return all of the lines in one step. But of course you need to know that this is returning them as a list. Okay? So that is also another method. We have a different wave doing this. Let's do the same. You open the file reads. And then let's see what we got here. What would be the next method of doing this? So the first thing that we need to make sure that we close the file. And then we could actually employ a loop or a for loop. So we can do something like that for line in f n, which is this variable, we can just simply print line. So what this loop does is that it iterates over each line and this hole. The two have opened. And David could actually print the line or reject whatever logic that we want to do over this line. So if we run that, can see that it has printed all of the file line by line and not returning them as a list at, as there are eight lines method that so this is, I think this is a very useful and commonly-used method here on Earth technique or freedom fives or reading lines from files. So you can iterate over them line by line and then just do whatever logic you want to do over each line using this symbol for loop. You can also read the specific number of characters from the beginning of the file. So if we open the file and close it or make sure close it. And then we can use a method called read trades. Speed. And Fen specified the number of characters that we need to read from the beginning of the file. So if we say, let's say at ten. So that should first thing, characters of the phi we run that. We can see it prints onto the first ten characters, the phi. So few unary the specific number of characters. You can use this method, the read method. So what if we didn't know, we didn't specify the number of characters here. It's tried to also prints the whole file at once. So this is also a useful method. There could be some use cases where you could use this method. Redone the whole fight or specifying the number of characters to be written form the Pickin. Okay, so that is good for now. So this is reading from a file. Look at Triton till five. So there are many modes for writing 2-5. So basically would be using the same function. And let's say we wanna add or append to this file some other lines. So demoed that we should use for that is called appends mode or a. So for the azimuth, we could append to the file. So it opens that file and ads whatever one, right, the end of that file. And then also we need to make sure clothes in here. And then we can say in the Triad and then reach generalize something. This is your line that we have. And let's see what happens when we don't. It's okay. So of course I didn't print anything we should expect to see the algorithm to find itself because we're writing to that file. And this scene here, we can see that this was just this is a new line that I've just transit. But we use this method client, for example, to exist. So it doesn't automatically adds this new line character. So in order to do this, we could add it at the beginning here. And we could also add them to foreign to add a new line in here. So we can just remove this and save the file, and then run that again. And look at the five. And here we can see that it's added a new line because we manually edit this character. So this character stands for unaligned. So the right method doesn't actually add this character that dramatically. We need to do this if we need to. And we use the a mode, which is the append mode in order to add to the fight and not over i its existing content. We have also some other Mrs. method cold, right lines. So write lines and lines and it's this just commented. So let's say that we have the list of lines, lines. And then each client would be an item of the list is strangled Dennis, this is line one, and then this line to this line three. And scenarios in the pinMode. So it should add it to the end of the file and shouldn't override anything. We run that we did in bus lines here when you took that new lines. And we can see here that they all also where it's internet seam line, you didn't add new lines. So this is L1, this is line two and so on. Up to fix that, that's what we need to add the backslash character at Northerners to add a new line. And then from here first, save, then run this code again. And here we know, we can see that each line is now meant some dividend nine. Okay, so we then so that was that Ben-Moshe woman. The other moods source simply using the same function over and over again. And he was something called the rights more. So for the right's motor to fulfill rights, the file, if it exists, and if the file doesn't exist, it creates a new fun. So let's say that we want to keep this finding text and let's creates and you'll find that you find the dx3. So the rights multi-year with Korea and that's fine if it doesn't exist. And then riots, whatever one or i, it's using the same methods. So let's say that's the same from here. When I write the same lines here to the New File. And then some momentum. And we're writing to the file and then close. So what should the having here? Because we don't have this file inside this directory, this question be created first. So the equivalent created and generate these lines. And then closest the five string. Hey, if we run that, we can see here that my phone is created the new file, which we name that's here. And if we open that file, we'll find our, the lines that we have created as expected. Okay, so if we do this again, let's comment that out and have a new set of lines. And say, this is the over all writes the first line. And that's Colby. This again. Second. And more thirds. And then we need to write lines, these lines and see what happens. Okay? Some soil US into W mode or direct mode. And this height already exists. What could happen? It should go through the contents of this file and override these contents is the new ones that we have used here. So let's run this code and see the, Let's open new file again. And we can see that the old con contests been overwritten and we only have the new content that we have written right now. So this is a very important distinction between the pinMode and the right to overwrites would. So for that bend more three do not overwrite whatever exists in the hot. What was this right motif? Override. It, actually override sweats. Existing. Though. The file is not there it would create. Okay, so that sounds good. Let's talk about myth about exception handling. So let's say here. Then. Let's say we read in a phone. Let's comment that out. And say read in a fight and use this course. We're either in or find, we miss, miss this five baths. And let's say we use some file that doesn't exist. And I didn't say it's old violin or something like that. And let's run the code and see what happens. So firm that code, we can find an error which is fine. Milk found no such fine. And that's stub sends crashes our program. So this is not something that we liked seeing or broken this kind of errors. So instead we could use some other way to make sure that fives are open safely. And if they do not exist or if we don't have the right permissions, we don't get this kind of errors. So one way to do this, we use something called tri except block. So try except block is he's away. You've trying trying to open the 54 exemple, then something something like an error like that. A beard. If the fight is not found in you don't have direct permission. It's what they execute, whatever qualitative findings it told to ensure this, the error message into a define we will define the behavior to do if this box here faith. Okay, so if we do the same here, and let's try that. And then for the except for here, we're just print a friendly message from our application, which is old. Or open. The flied. All forces that could do all kinds of things that we might be able to do here or might be able to use, let's say a backup fired or some default fight or define any kind of behavior if the fight was inaccessible in this part. But for here, let's just show the lifted more friendly message in here. And let's try that. So here we will be in the old file which doesn't exist. And let's see what happens and re-execute this code. Let's make sure that this is implemented. And then let's just execute this. If foreign debt, we find this friendly message. We cannot organ the finer these check-in unquote, which we have defined. We had some other quoting here. After that, the program with continuing execution. Some other quote, any other quoted will continue execution and it doesn't crash the program. So this is a really good way of handling exceptions while opening files. Also another thing we have seen that we always needed to open the file, open for reading or writing and then we need to close it. So what if we forgot that might cause hymns and buffers and it will leak, leaks some memory in some cases. But we also might forget. So how do we overcome this? Proton? Might forget to close the file. After we open. We could use a statement called with statement. Let's comment this out. Instead of doing this, we replace it with and then the function open, this city that has our files. And then the mode, the same definition, the same way that we call the open function here. But then we do as in, they didn't give it a name. It's the n. And that would be a block. And then we can do exactly the same that we did here. Copy that. We're swinging will correct the indentation test to be inside this block. And as you can see here, we don't need to do the close. So what does this statement? One does this with S. So it basically safely open this file. And after disk block finishes execution, it automatically closes the file. So we do not means to actually close it manually. So this is a very clean way of doing such code. And of course it should be a combined with try-except for error and exception handling here. So let's run that. And we can see that we get the same exact results, but in a much greener way. Here, we don't need to manually call the FN close, so you do not need to worry if you forgot it or not. So this is one of the best practices while dealing with fives in Python. So make sure that you use this approach or a similar approach while you were and while your journal, but dealing with fives and Python in order to make your code cleaner and safer. So that would be it for this video, we discussed how we could handle files in Python, how to read and write to files. We discussed different modes, the r mod, append mode and the W or overrides mood. And we also mentioned how to use exception handling and how to safely open and close files. So that would be it for this video and hopefully see you next one. 13. 12 _Tuples, Sets & Dictionaries: In this video, we'll be talking about different types of data structures, which are tuples, sets, and dictionaries. So let's get started. So toggles are set some theta or sequence values which are mutable or immutable means that you cannot change them. They're very much similar to lists. So let's see how we could deal with tuples in bison. So in order to create a W can simply don't want to variables like this and just use these two braces. So this has created an empty talk. In order to make sure that it actually create sets level, we can just print a type of dance and see what will happen. So we actually can see that this is a toppled later. So this is one way of creating a table. But also like, let's save this tuple here. We can create a table by immediately assigning items. So a tableau is pretty much like lists. We have items and these items are separated by comma. So we can have something like apple. And that would be a tuple. It's printed. And we can see that the test been vented in here. We can have under one item for a tuple. So something like that. When I have only Apple can do something like this. Then we can print it. So this is also a table, but you need to make sure that you still have the coming even though I have only one element or one item within the discount in order to make sure that this is actually a toppled here. So if we have enough reuse, if we lose this and print that tunnel, and we find out that it turns out into a string. We don't see these presses anymore. These brackets can make sure by printing the type here. And we can see here it has been converted into a string. But when we add this comma, we can see that it has been returning back to a tuple. So even if you have one item within your taboos to me, discover just to make sure that it isn't a. Also you can have this double without even using these brackets. So let's have the same level, but the sine of two different items, we can also have different kinds of data within the table. It doesn't have to be only one type within the tabulates, pretty much the same list. So we can have, let's say we have some integer, some streaming, and have some food. And then we can print the stubble and printing the type of this title to make sure that it is actually gets old. When we printed that, WE grammatically added these brackets. And we can see that this variable is oxide. So we don't need to use the brackets. We can just do this. And also like unbanked, this total Mbeki means that we can assign each of these different variables. So we can do something like that. X, y, z equals this table. Let's see what happens when we print x, print y, z. So each of these values separated in one variable, this is called TBL unpacking. So we have these various fair, these variables separated by commas and we assign the table to this. That means that we're, we're unpacking this stumbled into these different variables. So the first variable to get the first value, the second variable will get the second value, and so on. So that's sometimes your code, very easy to understand and very compact, very few lines. So that might be useful in many cases. Also tuples. So we can use the same techniques or the same rules that we use two of them lists. So we're gonna have this tuple of 0. And so that will return the first element of the tuple, which is two-year, can do slicing and soil, so free. And this tuple or Mom to the end. So we get these two elements of the tuple. So they're pretty much the same. Things that we could do is we can do with tablets. But the thing that we cannot do with couples is two, add or remove items from the table since it has been assigned. So free trials. So we don't have actually a missile. Let's say this type of 0, you wanna change it to something else. Let's say six. You can see here that we got some error because it doesn't support the item Assange, because as we mentioned, tuples are immutable so it cannot change any item within this one exception. So if we have a double that inclusiveness, Let's say that reassigned this thermal to something at city to city. And then we have the list within the toggle goods as other items. And then we tried to look at filing this item in this list. So the second item of the list to be something else. So let's say we wanna modify this. So this list is at index two of this double, because this is 012. And then within that list and modify the second item which is one. And we want to set it to ten. Okay? And then you bring this term here and run. In this case, we do not get an error. And we actually can see that we did modify that second item within the list. So this is the exception to modify and publish. So we cannot modify our teams within the table, but we can modify items within a list which is within that. Well, that might sound that interesting. Okay. So pebbles also have some special methods. Let's say we have something called new trouble, and this is just some numbers, 1234. And then you want to count how many times the number two appears in data. So I have a method for that. So this method is called gowns, and it takes the argument to which is the value that you want to count. So I can just count to want to see how many times that number to appear. And around that, we can see that the accounts here is three, because here we have to repeat it three times. So that could be useful in many applications. We can also have, let's say the owner and find out what index. Then I2 for his act within this total method or data. Which index? And then the venue that you want to find the index for foreign debt. And find that this endless fine. So that is correct. That's 012345. So it might be useful. Methods into table would, could also search, will search for a specific items. So let's see. I wanna see if fight exists and discovered or not number five, existence in this terminal. So we can see in your hotel and should be evolution, should be a true or false when. And as we can see, it is false because five doesn't exist here. How about in C2? And it is true because to exist this double. And seeing it is true as well because three is here. So the assertion is almost the same as the same way we did with lists. And it also applies to tuples as well. Okay, so that's all for today. Let's move on to the next data structure which is called set. So a hint is unordered but mutable data structure or a sequence of values. So since let's see we have a set a and this set consists some numbers. So we define a set by using these, Sorry. Curly braces and then we have the items separated by commas 11 thing about the sets as well is that it only stores unique items. So if we have quantified this set and have three repeated three times. And then let's print out this sense. We can say that we can see that three is only here. Once doesn't appear repeated because sets a low only unique values to be stored. If you have a value that is repeated multiple times it honest, it is only stored. So that might have lots of applications. So sound kitchen, you might want to store some values and you wanna make sure that the events are unique within this structure. So a set to might be the way to go watch storing these kinds of parents is something special about sets. So sets, what do you want to define an empty set? You cannot just say, let's see, we have set P. You might think that we do this the same way we didn't lose doubles or with lists. We use these braces, use these curly braces. But this is not true because these curly braces are like preserved for dictionaries as we'll see in a bit. But for sets we cannot use them in order to define an empty set. So let's try this first. Let's find the type B here. When we do this, we didn't print it. And it's Brenda, type of p here should be a dictionary, which shouldn't be talking about. Next. You wanna define b as the set is the keyboard set. And these two practice, that's fine. Times V Now. So this is something important that you need to pay attention to when you're defining an empty set, you should go that way. Okay, so let's have some look at some methods within the set. So sets, we mentioned that there are mutable, so we can add items to the set soon. Let's say b is equal to means a set is an empty set right now. And then we want to add the item set. Then print B. So it's only from an empty set to Andi on itemset which is seven. So fun to add one item used the method, add him to the set and specified the value that we want to add to that. What if I want to add multiple items? There is another method for that which is called update and takes list or an iterable. So let's could be one thing. So let's say you want to add these numbers. Then we put in as we can find that. We added 8910. And of course, as we mentioned, the sets are not ordered, so you shouldn't expect any kind of ordering while adding items to the set. So that also means that we cannot index sets is in indices. You cannot say b two, something like that because they don't have or. Okay, that sounds good. Let's try and remove an item from this set. In order to do this, we have to mix us. So let's say the first one is discard. And let's remove seven here, itemset and print p. So this actually remove the item seven, sounded tendon removed it. And we have also another method called remove. And we can remove item eight in print B again and run. So now we only have 910. What if we tried to remove an item that doesn't exist? Let's say I want to discard. We do not have an item called dinner. Then we can see that you just didn't do anything. So the item doesn't exist. So the discard method didn't doing. Let's try the remove method with the same thing here. We can see that we got an error here because we have the key error 11, cuz this item doesn't exist. So this is almost like the only difference between discards and removed. So fewer remove an item if you tried to remove an item using discard. If that item doesn't exist, it wasn't complaining to just return. The original set and wooden container wouldn't throw an error. But a fuse, remove and try to remove an item which doesn't exist into contain and throw that error. This is like conceptually the only difference between this card and remove overstep. Okay, so let's look at some of the set unique operations. So let's redefine a. Almost the same numbers before, but just to make sure. And then we have B, which is equal to, let's say 268 now. Okay, so have these stats if you're familiar with the concept from Azure borough mathematics that you have studied before, have many of the set operation. So let's look at the first operation which is called intersection. So the intersection between two sets that are returns, there's items that appear in both of them. So for these two sets of, we look at the intersection between these two sets, can find that items, 26, people said beer impose. So fishers DO this intersection. So any one of these sets, that intersection. And the other set. And then we'll print that intersection R1. So that is also another set metadata. So that this also another set here, which is 26, which are the two items that appear in both these sets. We can also use this Buddhist same functionality using m percent operate. So a person who breaks are roughly half both sides here, the left side and the right side. Our sets. So it does the intersection operation. So let's try this. And it gives the exact same results. So that is the first operation that we spoke about here. The second one is the Union. So if we have a union B, that gives us the union of these two sets, which is the combination of these two sets, like joining them together. Except that of course, repeated item login bureau, they would appear only once. And we have also the same thing we have done for the Union, which is greater. And these two lines should get the same results. As we'll see here. We get into companies or does join of these two sets without repeating any repeated elements. And this separates or does exactly the same as the union method that we use. Ok. Another method is the difference between the sets. So if we say a difference, difference here, and this is exactly the same as a minus b, which is the items that are in set B and set a, but not in set B. So the item E minus the intersection, or without the intersection of a and b. So we can see here that the items are 1345, so disarmed items with a which are not members of sets BS1, horse the difference or wouldn't be different if we have b difference. Or that would be p minus e. And we will find the items in B which are not elements or parsed a. Okay, so that sounds good. Let's look at some other method, which is the symmetric difference. So let us see what it does. So if we say that c, e, that symmetric difference B, and run that. So we can find the items, the items of a and B which are not in the intersection between a and b. So it's like a union B. So you do something like that. E union E minus E intersection B. So this should be exactly the same results. So yeah, that is exactly the same result. So this is the definition of symmetric difference. So these are the items existing in the Union, but not part of the intersection. So it's basically the union minus the intersection. And we can also, we have an operator for this operation as well. So you think that's symmetric intersection is its long. You can do this operation, this operator and R1. So that's what also be exactly the same. Okay, that sounds good and beautiful the sets. And let's move on to the last data structure that will be liquid into this video, which is the dictionary. The dictionary. As you might guess now we could find an empty dictionary using this. And if we print the type here, we can find it is a dictionary actually. So dictionary is it a set of unordered items? And each item, and that is that they are. So each item is except they're actually a pair. And this pair would be a value pair. So we have keys, we have values, and each key has a corresponding value. These keys and values could be on sexually anything. So we might have addiction, let say this is d1. And we can start listing items. So with the first one and the value corresponding to that key, it's the path. Then we have an index two and we have the values down. And let's see, we have a totally different types of E at C. And then we have John. So it could be mixed. It could be like keys and values can be with anytime. And if we printed, we can find that inside our dictionary. Okay, so how do we actually these items, we could access news items using the index. So the index here is not, doesn't have to be an integer as we did use the lists. So it could be. So if we want to access this item and this value zone, we basically need to do a new one or main. Brings out the very young here. So we can access these items, are these values within the dictionary? You are using the same method that we did with tuples and lists material. The index here is the key, not. Doesn't have to be an integer value. So the key here depends on the structure of the dictionary that we have. Set, let's say renamed to access this venue Doc. Just need to t1, t2 here and run. Then we can find out that this is the very bargain you, okay? This is something that we need to keep in mind. Another way to build the dictionaries using a list of doubles or a list of pairs so we can define the new dictionary. Let's say it's need to. And we can see it's a dictionary. So this is like the construct, the dictionary. And we can give it a list. So the first item myths say S1. And this is the first pair. So here it wouldn't be this column, it would be a common because this is a double. And then the second item is through none, for example. And then we'll print D20. Let's see what it looks like. And it is actually building a dictionary out of these lists tables. So this is another way to construct a dictionary using a list of doubles. So each toggle is a key value pair. Then we combine them into that list and then baseQ today the class or that the constructor. So we can also x's items the same. So d of two, if we printed, shouldn't be dug here. Okay. So another way to access items using the method gets, So for use gets exactly the same here we just pass in the key. And if we run that, we also get the value stored at that. So what if we wanted out, like remove an item from the dictionary? So let's say that we want to remove that. I went to remove down from this lecture. How can we do this? So one method that we can do is use the bulb method. So we're going to Bob, and then we'll pass in the key. So the key here is to and actually bulb also returns the value. So it returns the value stored at that key and then removes it from the dictionary. And then print x. And we'll bring the dictionary here to see. So x here is don't. And then after deletion, after removing talk from the dictionary, you can find that have only one item which isn't the first item. Keys one and the value scattered. Okay, once if we want to add an item to the dictionary, we could simply do this. So we define the key that we want to add, let's say form. And we define the value here. Let's see this is the value for the foreign debt on it. And then let's spend the two here. R1 and We can see that it actually has been added here. So we define the key here. And then that is a value that would be sport. And so this is how to do addition and removed from dictionaries. So let's look at insertion, for example. So let's say we have some dictionary which storing countries and capitals. So let's say we have us and it's capital V, c. And we have the friends and the cover seven years then. And it turns out and the continuum sperm. Okay, so this is a dictionary that countries and their capitals. And let's see if we can search this Pictionary. Let's see. We're gonna see a use in addiction and run that. And it is through AN because, see USA Here is a key in the dictionary. So this statement turns out to be true. But we try something like this. And around that, that is false. Why isn't that false? But we have this value right here. This is because the invertebrates or dictionaries, it's only search for peace. So insertion within keys. It looks within keys. And looking for this value right here is a part of the keys. It's not. So it returns false. So how do we know that keys we already built a dictionary here, but let's say if we don't know, so new, that is, we have this method that there is the keys. So it is sort of the keys here, which would be used as indices swine dictionary. So if we look something like that to, let's see. So this is one of the keys, so that should be returning. So that is one thing that we will look into. Another thing is that the method called license. Which dictionary? So what does it do? If we do this? The list items and print that interesting dictionary items? So each one is a beer. Okay, so let's go and try on a loop for these items. And let's just print each item individually. So here we, we did a loop that iterates over each item in the dictionary items and then prints it out and run. So we can see that it is printing. Each pair is a tuple one by one here. Okay? So this is how to iterate over items, then the dictionary. But what if we lose this item so we don't use the items method. Let's just say for i knew the print, I once would be i here. Let's run this and see. As you can see here, the lawyers just the keys. Selfishness wanna iterate over Keys who could use this year. They just knew that the name of the dictionary and patriots or here would go over only the keys of this dictionary. We didn't go over the items. Hey, what if we want to print the values? That could be very symbol S1, we confuse exactly same here. And instead of printing, I would print new dictionary y. So this is going over each of the keys and then getting the corresponding value for that. Let's run that. And here we can see that we got, starting here, we'd gotten the values for each of these case force within these books. So could do any kind of processing that we wanted to depend on data indication that we are trying to develop. And that is the whole idea of how to iterate over values. And both keys, values as items. How to search within the dictionary, and how to build a dictionary, how to add and remove items from a dictionary. Okay, so I think that has been a bit longer video Here we have looked to over tuples, sets and dictionary. Take your time to go over the video again if there is some concept that you catch quite well, and that would be it for this video and hopefully see you next week. 14. 13_Recursion: This video we'll be talking about recursion. And by recursion is a construct in programming, which means the ability of a function to call itself. Several times. We haven't encountered this concept before, but we haven't encountered calling a function. So if we have a function like at, and this function takes two numbers and simply returns the addition of the two numbers. We have seen that we can actually call the function from outside the scope of this function using some numbers. And we can actually bring that out because we were returning the addition. And then we can run and we get the result. So right here we're calling the function from outside the function. So for not doing discordant inside the function, which makes sense in this case. And this video will be to be looking at a case where we could actually be calling a function from within the function. We're calling the same exact function from within the function. We'll see how that makes sense and what would be the cases. We might be using that in. So let's start with the simple example of calculating the factorial. The factorial. A number is simply the multiplication of this number by all the numbers down to one. So if we have five factorial, five factorial submitted by five and then this exclamation mark. So this is for one I calculate five factorial is simply five multiplied by four, multiplied by three, multiplied by two, and then multiplied by one. So this is how the five factorial orders a factor for any numbers calculate. So it starts with the number itself, and we keep multiplying numbers down to one. So we knew that the factorial of one is simply one and also the factorial of 0 is one. Would you solve some definitions that we need in order to understand how to calculate the factorial. So let's try and implement this factorial using native approach using just four loops. And it seems pretty simple to do this. So let's define a function called factorial. And this function takes a number. And in this function would be going over the range one to n plus one, because here we need to include the most patricians. So phone a factorial five. You can see that here we're actually multiplying five. Fishes had n. So the less number of Orange is not included as we have seen in the for loop tutorial and the for loop. So we need to actually include that number, so n plus one. And then we could simply have a factorial variable, which we accumulate our factorial. And it would be initially set to one because we re just lifted on initialized it would be 0. We don't want to R1 multiplied by 0. And this vectorial factorial would be aggravated every time. And it will be multiplied by i here. And then eventually we're at cern, which is the result. That we would like to have. So that's pretty simple. We're just using this definition. And then iterating over all of the numbers in the range from one to n, so that we're here and exactly n plus one because n wouldn't be included if we just had m. And then we have this vectorial variable which is initialized to one. And then we keep multiplying each number until we reach the final. And then we're returning the factorial symbol and straightforward. So let's try to print that out and pull different tutorial, rover and sank five for example. Run. Then we can see here the result is 120, which is exactly this multiplication that we have described. So this is called the iterative algorithm or the iterative approach. Okay? So a dent is spread assembled. There is also another way that we could do this, which is using the recursion. And this is based on the fact that if we look at this equation, So five factorial is actually five multiplied by four factorial, right? Because this eventually accounts too. Four factorial, which is four multiplied by three, multiplied by two multiplied by one, and so on. And actually four factorial also accounts to four multiplied by three factorial. Four factorial isn't this part, which is four multiplied by three factorial, wishes that bar, and so on. And if we go for three factorial, that's just three and multiply it by two factorial. And two factorial. Just do a multiplied by one factorial. And here we have the base case, which we know that one factorial is exactly one. So we call this the base. Then of course, if we have to move to 0, we should put in an Haben eventually in our program where you would also know that 0 factorial is that counts to exactly one. So we can see here if we could somehow broken magically implement factorial using a function in order to calculate five factorial could do five multiplied by four factorial. And four factorial is another call to the function to disclose would calculate for structures to be four multiplied by three factorial. So that is another call to the factorial function and so on. So this factorial function in that implementation would be calling itself or D sparks in order to calculate these parts. So it is like pulling different instances on the function. And then eventually, when it reaches that base cases, templates, it knows discount tuition, which is one, and then goes backwards to substitute for whatever the values that should be substituted. So for example here for calculating five factorial would be five multiplied by four factorial. So this would issue a call to a function factorial four. She's kind of nakedness here and then goes all the way down to here. But tier, we tried to calculate the factorial of one renewed active factorial is one, exactly one. So we go back to here on substitutes. So that would be one. So two multiplied by one. So we know that two factorial would be two. And then we'd go back, substitute this value, the value of two that we know. So that's three multiplied by two, so that would be six. And then here we know that three factorial is six, so four multiplied by six, that's 24, and so on. So we go backwards again in order to calculate the factorial until we reach on to appear. So this is an ideal aliveness, simply ambition torque, right? So it's actually implement. I'm going to slow that is, there is radiative one that's trying was recursive algorithm where we define the factorial function as well. The first thing that we need to check is the base case. We are the base case. If n is equal to one, we just return one. Else. Once if n is not equal to one. So that this NANDA base case here. So in this case we should return multiplied by the factorial of n minus one. So that is what we have exactly described here. Suited for a year was let's say, five factorial. Five factorial. So here n is five less than equal to one, no soy or non returning one, right now, instead we're returning N, which is five multiplied by N factorial for let's say this. And I'm like, okay, so this issue is this spark issues and new coal for the factorial function. So factorial of four. Notice same here. Goes through this branch is n equals to one knowing because in here is four. So it goes through that else branch, excuses. So that's four multiplied by factorial three. Then we need to calculate factorial of 333 multiplied by factorial 22. Through multiplied by factorial one. Now here we have n equals one, which is this base case. So if this base case was equal to one, then we return one. So this part will be substituted by one. We're returning to them, that's cool. So now we know that factorial tours to multiply it by one. So stuck, we, we go back backwards to this one. We substitute that by two. So this is over now. And we know that would be six. So this part is over. And we go back, multiply that by six. So that is also known now, this art is over, so that's 24, and eventually that would be 120. So this is actually how exactly this program would operate. Well, let's run it and see if this program actually works. Let's try sectorial five again. And it actually works. And this is how it gets the exactly, exactly the same. So using recursive programming has some advantages and disadvantages. So afford advantages could be used in some problems that, that's our big N could be unlike split into smaller program and could be divided into smaller problems. So we could use, we could find that the recursive approach is useful in some of these problems like tree traversal or like in some sorting algorithms. If you're familiar with the Merge Sort of QuickSort, we will find that using recursive algorithms is very efficient because it enables you to divide the problem into smaller subproblems, but also it uses slots of memory. So for each goal, if this number, for example, is a very large number, you can imagine that we're issuing many, many calls to this function. And each of these schools would be a frame and an independence frame in the stack frame and understand for the program. So that would use slots of memory which might be not very efficient, might still don't get Program. And in some cases the iterative approach, the one that we use don't there would be the better option. Mainly depends on the problem and it's up to the decision of that developer, the designer of the program, to see if we're using recursive algorithm would be helpful in this specific case. So that would be it for this video. We talked about the recursion and Python. And the difference is between the iterative approaches and recursion and recursive approaches. We have looked at one very popular implementation or one very popular problem, which is the factorial problem. We implemented this in both ways. And we have seen some of the advantages and disadvantages of recursive program. So that would be it for today. And I'll see you in the next one. 15. 14_ Bonus: OS datetime random: In this video, we'll take a look on a few of the, some very interesting modules. And in Python, some of the built-in modules in Python. And see what we can accomplish using these modules and name methods implemented within these markets. So the first one that we'll be looking into is the OS module. So we can import the module by just writing import OS. And this module enables us to kneel with the underlying braking system that we are using. So for example, here, I'm having a Windows machine saw. This enables us to interact with the Windows operating system and do some of that system operation that can be done using the operating system. And the first one that we'll be looking into is a very simple one, which is how to find out the current working directory for which directory we are currently working. So there is a method for that which is always to see WD. Cwt stands for current working directory. So it returns a string as mentioned here, representing the current working directory. So let's try this out and print what would be the outlet in here. So as we can see, this is the current working directory. So that is trying to see users and disorder in directories, or this is exactly the directory this fight we're working on is in. So we can also create a new directory. We can do this in two different ways. So the first symbol is S, is not empty. Their wishes creating or make directory. And then we just need to name this directory. So let's call it, for example, you wonder. And let's run this on. Or actually we can first also like to introduce the other method or introduce another method, which is listing the contents with the current directory. So this method is called list there. So S dot Lester. Just print it out or listing the directories and files within the current directory. Okay, so let's execute this code. So first here we are printing out the current directory, and then we're making a new directory, which is the new there. And we can see here that this trajectory has all, has actually been added to the current directory. And when we list the current directory contents, we can find that we have this Python file that we're working on and this directory that we have just created anywhere. Okay, so let's create another directory. So let's just comment this out. And let's create another directory. But it wouldn't be in this same level of distracter, so on and create a directory and another directory inside. In order to do this, we can use a method called main. So this is taken apart and creates all of the directories needed for this path. So for example, let's say we're in a dielectric calls and other Ritter. And then we have two backslashes and then it c. So what this should do is is creating this directory, but in order to create this directory testable, some period, this one. So this new, new order would be in another register. So let's try and execute this code. And when we look at the list, we can find out that here we have another directory, which is the directory that I created. And if we open up this directory would find a new new there which we have written down here. So for an accredited like Anniston directory structures, so we need to use nice meet tears method. Okay, so that is the turnout. So let's look at how to actually remove directories. Actually, we have also two methods similar to the ones that we use to create directories. So the first one is called R, which takes a directory to remove erodes latent and knew there that recreating here. And let's try this out and print the list again and run. And so we should remove this because we cannot create a file and this file already exists. So we need to condense that down because we already created that. And let's turn again. And we can find here that the listener doesn't have genuine 0 here we kill one another and knew there has been removed. And we can also see that this has been removed from the contents of the current jerks. Ok. So how could we like to delete or remove Mr. Directories As we've created one. So we have a similar method which is called your move. And then also like Canada's old bath, but it's do exactly the same as here. Or deleting or a move into directories that you have created here. So we'll be removing this TR and this another directory has no. Let's run this. And we can find that it actually created all of these narratives needs to directors domestic ones. And when we print the list of the current contents of the directory, we can find that it has also been removed from here. So also we can do some other operations. So one of them is to change directory. So changing the directory means we want, we want to be in another directory, then the one that we are currently in right now. So let's just comment this out number just to get an idea of what we're trying to do here. So here if we print the current directory, you can see the directory that we're in. Right now this direct wanna change it to another directory. In order to do this, we can do and use the Smith a CH, which is changed directory. And then we can type in the full path for the director of water. We all would like to move toward change to the documents. And we have a directory here called portions. And let's print the current directory now. And we change this directory. So after changing the directory using this method, we can find that we have the current, we print the current working directory right now we can find that it would be the new directory which would change. Let's list the contents of this directory. And then we can see here we have the contents of this directory. So here we have two directories and one final scientists and new directory that we have changed. Ok, so that's also some, could be some useful operation here. We could also go and change the directory to another. So we are here right now. So we could use to, for example, and run. And then we could list the contents for this directory. And we can find here in this new directory that we have changed too. So this one, we can find that we have a fine time. We'd like to have some information about deciding we need to find information about this file. So you also have a method for getting some information which is called Last stat. And then we forget. Now we typed down the filenames. We have to brush to P1. And we can just print that out and see what kind of information that we can get out of it. From that we can find some information here. So each of these properties means something. So for example, here we have the size, we have the modified time and the creation time axis down access time and user ID, Coverity, ruin. And I understand all of these. We can just simply look it up and find what each of these mean. But this is, for example, to find the size of the phone. These are all timestamps. So that should be the the access time to modify time and accretion funnel, that's one. But these times are not like really understand, right? Because these are just a number. So this is a timestamp. And in order to convert it into time that we could understand, we'd like to import some other module, which should be our second molecule here is called datetime. And we actually need to embossed in time this class from this module. And then we could actually have this fat stored in a variable. Let's see what we are just interested in this creation time solar could simply say dot cs t c time. So this spring's only the creation time. And we can see this variation. I am for the font. Okay, so let's spend the town. So that is still sometimes Tim that tweak not easily interests then from here, in order to convert it to something we can actually understand, we could use this method from the datetime module. So datetime dot from times ten and then the creation time. So from timestamp converts timestamp somewhere, something like that, into a date time format, which will quote untrusting. So for pin that down, we can find that this has been converted into some date. So this is the date and the hours, minutes, and seconds and milliseconds and so on. So this is our second module that we used here, which is the time and provides many functions, were many methods that we could use to format and I'm very neat things and so on. So this is one popular method that could be used, an unused and application which is actually representing the maid sometimes into timestamps. And we could revert back to our user readable form was in this method from timestamp. Ok, so let's get back to the OS module again. So what if we would like to find the contents of the contents of specific directory? We would like to walk down the directory and see all of the subdirectories. And then all of the files within each of the subdirectories and so on. We can do this using a method called pole. So let's first start back to the same old, same directory. And then we'd like to find out all of the tree into directory tree of this directory. So we have a method called voice to 12. But this Returns says generates it. So it first takes an argument which is the best not to rely for. So we could say get WD, which is good, the current directory. Or you could simply write down the path and this path and pass it as a parameter in here. And this always swore cruiser zone, which is a generator, so it's something that we could iterate over and it returns three, it doubles actually. So the first one is the current directory name, and then the directory is within the directory. And then the files within this directory has. So we could iterate over all of these sort of quadrate trait over a current directory name directories within this directory identified within misdirection. And we could simply print all of these. So let's say Penn. Guns. There are extreme and we could just format. It will supplement drinking trees inside. And then the second element in the tuple. And then we could also have defiance. And you have the non-kin. So let's run this and see what will be the output y. So here, this is the first current directory. So this is the root directory that tour starting form, which is this one, the one that we changed two. And then we can find nearest stood directories inside this one, sharp Bush one and brushed. And this also has a fiber which is called greet me that fixed. Then this walk method goes into each of these directories. So first it goes into one. So this is the current directory now, Raj one. And then it has no directories inside, but there is a text file inside it. And then it goes back to the second directory here of the root brush to. And then it also doesn't have any directories inside and it has only one finds. So this swap method is very useful in many cases where we have two iterates over the whole directory tree for a specific root directory, which is in this example, this directory. And it could list all of the files and directories and subdirectories and so on within the direction. So it is a very useful method that could be used in many different applications. So this is for the first two modules that we have. No didn't to the datetime n. And that'll us. So let's look into another module which is the random ones. So this module is used to generate random numbers. And they performed some brown to mix experiments on data. So let's look at an example. So first we have the myths that cold random, random and dismissed. This method returns a number between 01 but 20 is not included. And this number of course, would be a floating point number. So if we tried to sound, We can find that at this dinner generating a floating point number. And this number would be a number between 01. And each time we run it would get a different number, most like. Okay, so this is the first method of generating random number. You could also have a random number within the range. So we could define the range using a method called uniform. So it chooses a uniform distribution to draw number. For example, if we want to have the number between 110, we use this uniform method and we pass these two numbers as arguments socially around the venue or print the value here. We can find that too also have in a floating point number between 110. So every time can be a different number, different floating-point number. Also, we could also limit the numbers to ensure using. Now there is another method which is called ran into. And then we could also generate numbers and arranged. So let's say we want to generate a number, the range one to ten. But this time we needed an engineering, we used their medical doctor undone. For foreign debt will get one, gets a different number every time. And of course then is included. And so on. So these are like three methods to generate random numbers. So random generates a number, floating point number between 011 is not included in any form. Miss a juris floating-point numbers between the numbers in this range and the less than we're regime included. Surrounding generates only random integers in this range. And the last and the first one will be included as well. So let's say we have the list. Let's see, we have colors. Visiting fellows at cigarette, blue, green, yellow, orange. And we would like to get to a random color every time. So one method would be to generate a random number or undetermined. So we have, let's say, or an idea and that would be on. And of course the value here will be 0, Lynn winners S1. So this is generating a random number which fairing them integer between 0. And here we have 012345. And we could use this number as an index. So we could simply prints. But ours ran idx. So this, this number is random integer. It would be a random index nor case. And then we continue this index two index into this list to get a random element each time hurts shrunken. And first time we get to yellow, blue, and so on will get a random color every time. Actually, there is a simpler method in Python that you could directly use, which is called choice. So free, just men, that's out. You have something called choice. So it's cool. And then color equals to bend them the choice. And we just use the color or the colors list as an argument within we can run Ferran that also gets a random color each time. And basically does the exact same jogs have debt, it's less good. It's a method that's already built in random classroom, the random module. And we just need to pass the list network drawing random values. Okay, so we also have some weighted drawings numbers. So they don't always have to be or having the same chance of getting the same color every time we would have this weighted random values in something called choices. So it's saying waited and waited trunks color. Here we'll have a method called choices. So within this time. And then we couldn't use, we best sellers list has used before. We'll have something called weights. And these weights will be an array or a list numbers defining the width for each of these colors. So let's say that we would have for it that way the font, so each element here corresponds to one element in that list. And for black, let's say we want to have a weight of two, so we like black a little bit more. For pure, it saves Huang for Green. We like green very much. And then 4n or let's say it's 11. And we could also like cribbed this experiment several times using the parameter called k. So foreigner like draws color every time or number of times. We could do this in a simple line using this. We don't have toro rear under quote every time, let's say we're withdrawing five. So five times or drawing colors. And then we can just print the way to drown pillar here. So that should be a list because here we are. Does five times social F5 colors. And we have the weight for each color he is here. And depending on the preference in this piece missing. So foreign that we'll find that we've got five random colors. And we can find that we use the same weights here. So as you can see here, the green has high sweet beer twice and five times. And we'll also see that we have these five elements event done on the value of K here, that that's specific. So choices have a very powerful method. We assign weights to each of these elements for each of the vendors that we're drawing from getting a random value from. And we could also have repeated the experiment several times using this parameter k, instead of just straining their code over and over again. Okay, so that sounds good. Let's try something else. Let's say that we want to, we have playing cards and we're gonna draw and we're gonna get out a cord every time. So of course, if we are stricken a card out, discourage is no longer there, right? Because in this case, if we're just using choice or run or choices, we might be able to get the same item over and over again. But in some cases, we would like to have unique random values because, for example, on the deck of cards example were taken out the court. And we're not replacing it back to the deck where we're just thinking it out and it's no longer there. So that next time we draw out the cart, this garden that we just draw, it wouldn't be there anymore. So in order to simulate this unique random value generation, we could use a method called sample. So it's also under random fast. There's a method called sample. And we could use here the list or the pivotal population that we're sampling Forum and the number of times as. So let's use this deck example. And let's say this is arrange. And of course we have 52 cards. So whenever this range to 53. And then we have these random shards would appear random sample. And let's say it's out of this arrange. Pennies could also were all could also repeat this several times using J and K. We couldn't do k equals ten. So every time we should expect to see a number or a unique number that hasn't appeared before. So footprint and Kurtz. And see the output terms here. We could actually see here that for each of the ten times, no numbers or visa twice every number here is unique because we use the sample method of random blips. And this is, this could be useful in many applications. For example, in a game like that, where you check, you take out some elements and you would like to see into probability or the UK eke out some other card from the existing or the current list that we have with the current range that we're. So that would be it for this video. Hope you have enjoyed it and see you in other courses.