Transcript for:

Python is one of the programming languages most versatile out there. They use it from small developers to gigantic companies like Google, Facebook, Apple, YouTube and many more. In fact, even scientific organizations largest in the world also use it. For example, NASA itself. If we talk about the present and only the present, Python can be considered the language of general purpose programming, if all in the top 1 programming language Worldwide. used to develop e.g. pages web, mobile applications, desktop systems, CRM, systems artificial intelligence and many others stuff. Even in science we can say that Python It is the most used language. So yes, Python is that language. Once you've mastered Python, you're not only going to understand in a much easier way any other programming language, but you are also going to have in your stack of knowledge one of the languages ​​of high most powerful level created so far. That's why I, programmer and creator of the courses top ranked web development all over YouTube, which actually helped thousands of people to find work and millions to enter the world of programming, I invite you to stay. Cause this is the course for you once and for all by all learn python from scratch. Welcome to the definitive Python course. Well, to begin with, although we already understood that Python is a very powerful language, that have many uses and such, before that we should let's talk about the features of language, since if we are going to work with a new technology, we have to know what are its characteristics, and well, In this section we are going to know the characteristics of Python so that we understand what is the technology we are working on. To start, the first feature that Python has is that it is a language of general purpose programming, that is, yes, your language is general purpose. It is said to be general purpose because can be used for any activity, that is, there are languages ​​that are inside all limited to web, others for mobile, but Python, for example, is used to everything, it's not like it's a created language especially for the server, I don't know, cell phones or specifically programmed to work with electronic boards, no, It is a language that we can put to many uses. from game development to websites, applications, artificial intelligence systems, data analysis, or many other things. The second feature is that Python is a high level language, let's see, we have low level languages ​​and high level languages level, low-level languages ​​are languages with a structure different from that of language natural, and high-level languages ​​are the ones that most resemble natural language, that is, the lower the level of the language, the more difficult it will be to understand it when we read it, since it does not resemble the the way we communicate as long as it is a higher level language, it will be easier to understand when let's read What we are now seeing on the screen is a clear example of low level language, we're just saying hello world and nothing more, for that all this code, that in fact if I explained it to them, they would get dizzy, and that it is only to print a text in language assembler, yes, that language is assembler, a low-level language, while this is a high-level language, because we can understand what it does without any difficulty, that is, when we see it, we understand it, because that's more or less the way we might be able to communicate Let's see it, first it says that A is equal to 4, then says that B is equal to 2, then says that C is equal to A plus B, and finally prints C to me, that is, it is showing me display the value of C, then the question is the following, what are you going to show me? which is the value of C? If your answer was 6, you are correct, because C is A plus B, A is worth 4 and B is worth 2, 4 plus 2, 6, so C is worth 6, when we show it, it shows us a 6, it is really very simple, and in case that it does not seem simple to you, I would rethink the possibility of going back to primary school, just kidding, don't be offended, yes, we already started with the jokes, well, if I like that, sorry that Let's say, we're going to make jokes throughout the course and they will laugh while learning, not bad, maybe a person of 30, 40 years does not like jokes, but a person who is just starting the world of programming, a joke in the middle of the course can make that person out there have fun and choose to stay and keep learning, then You have to understand the purpose, right? The Python's next point, the third, is that it is easy to learn, that is, despite of being such a powerful language, so used for such complex things, it is the language with the easiest learning curve of all, that is, it is the fastest language to learn, And if I explain it to you, dear, a lot more, because I'm not going to take anything for granted, that is, the course will explain point by point everything, it will not leave anything loose and unfinished, because even if you already know how to program, you I assure that something new is always learned, and more when we review the new standards, that's why the course is very complete, they couldn't have chosen a better place to learn Python, in fact, not even the fact of that it be paid, since the fact that you have that paying does not make it better, that is, if I had grabbed this course and would have uploaded it to Udemy, it's not like it's just better because You didn't have to pay, not at all, I got it here, it's free and you should take advantage of it, really, they found the best place to stay to learn, I assure you that when finish the course, if you know someone who wants to learn python, they will recommend this course, and if you come why they recommended it, it is a clear proof then that the course is excellent. Returning to the point, I told you that it is simple to learn because of its similarity with language human, also because there is a community such a large number of programmers that any problem they have, they will be able to solve it, basically they are not going to lock because when you have a problem, that problem that you have, many people do too they had before you, they published it in forums and we already have a solution for you They can also go, see it, and well, solve whatever problem they have so be it whatever your problem is that arises, yes or yes the solution is on the internet. It's easy because of all that and why do they say it the statistics. The next characteristic, from here I put a bit more technical, is that Python is dynamically typed, if they know how to program they will to understand what we mean, but if not, let me explain it to you. Basically we have two types of typing, dynamic and static. What do we mean by this? Well, let's see it with pictures because it's the best we can do. This is how Python is, that is, if we want to say that the name be Roberto, that is, name Same Roberto, we just do it that way. If we want to say that Roberto's age goes to be that, we do it that way, it's so simple as shown there. But nevertheless, they are different data. Notice that one is a text and the other is a number. what python does is figure out what datatype is and defines it automatically. Now, in a language like Java, for example, which is what we are seeing now, we should tell the program, look, I'm going to create a variable that will contain a text and just there to say that it will be the same as Roberto. Then we have to tell him, I'm going to create a variable that will be equal to an integer, int is integer, is integer which is integer, number integer, that is basically we say that will define a numeric value variable and then we define it, that is, we say what will that number be? This is because in a static language, the type of data that will contain the variable What we are creating we have to define before, that is, we have to tell the program what type of data we are going to create. On the other hand, in languages ​​like Python it fits automatically. As we can see, the type of data does not depend of the variable, that is, we have only pass the data to it and Python understands it automatically, knows that a number is a number, a text is a text and so with each type of data. In short, then we can say that in a statically typed language the data has to fit the variable, while that in a dynamic language the variable is adapts according to the type of data that we pass to it. That's why it's dynamic. Before continuing, I want to tell you that obviously the course will not be only images, It's obvious, I'm going to code, we're going to write things and so on, only at first so that you understand the examples we use images. In fact, here I was already talking about variables, of types of data and concepts that we are going to to see later. That is, this if they did not understand it well because they are very, very beginners, that is, they are very beginners in all this, do not worry because we are going to have to see the same. The only thing that happens is that sometimes we have to explain concepts that only programmers understand, because if not, we can not explain language feature. That is, in programming the technologies They are created and over time they are modified because problems are arising or we have to do new things, then they become in language features. And when we have to explain them, what are they? the bases of language, they will not understand if they don't understand some programming. That is why it is normal that when I am explaining some things, for example, from databases Python, you say, ah, but variable, but datatype, which is a datatype, which is a variable. And if they understand, great, but if not, do not worry that the same, I repeat, we are going Let's see in the course, but since we're talking of Python's features, have to understand it into account. In fact, people who know how to program this types of sections you always see since they they are usually very useful. Let's go, for example, with the following example, which is one of what I have been telling you now. In other words, if they know how to program, it will work for them. to be much more useful and if not, well, I'll have to explain them to them and when they get to that point and mix it with what I explain now, they will understand. The following feature actually applies that, so let's see it. The fifth characteristic is precisely that It is an object-oriented language. Like I said, I got technical. But basically any programming language that implements concepts of programming oriented to objects, which is basically a style of programming where we write code and develop thinking about the parts of the program as if were objects. It's like a way of programming. That is, we can create classes, methods, objects and other things that we are going to see when let's get there to that point. But now stick with the idea that Python It is a programming language oriented to objects. As I told you, still, don't feel bad if from time to time they don't quite understand everything. Because sometimes, as I told you, this happens having to name things a little more advanced to explain basic things, since those basic things were just created for sort out other more advanced stuff, then it's like a kind of circle, like something rhetorical. Don't worry anyway. When they finish this course they will not be escape nothing. That can rest easy. So let's review everything very briefly in a minute. Python is a general purpose language, because it can be used for anything, from a high level, because it looks a lot like the human language, that is, only reading it we can half understand, this makes be easy to learn, it is the language with The fastest learning curve is dynamic typing, that is, we don't have to tell the program what type of data we go to use, but recognizes it on its own, and it is object-oriented, because it allows us to work fairly with programming oriented to objects, which is something we are going to see more forward. And finally we will see the last feature, and is that Python is an interpreted language. It is an interpreted language since precisely there is a program that interprets instruction after instruction and executes them. Here, for example, we have a language with several lines of code. What the interpreter does is precisely read line by line, each line interprets it and turns it into a machine language, this is for any computer or device in which we are running Python, precisely can understand it, that is what we are saying to the computer. Here as you are seeing in the example is line per line. While we have another kind of language which is the compiled language, i.e. not does not have an interpreter but rather has a compiler, while the interpreter interprets line per line and execute, the compiled compiles all just once and that generates a file that it is now ready to run. It should be noted that, for example, one of the advantages of interpreted languages like Python is that they are easier for fix errors. It is easier, let's say, to replace parts whole parts of a program, add new modules and else. since in the compiled ones you just have what to do like everything back, compile everything back, which is like a kind of rendering, It's like when you import a video, you have to wait and wait and wait, it's the same. Then the interpreted being line by line is easier to correct and change Let's say in the interpreted ones we can go testing code by code and see how it is being interpreted, so we can find bugs. But the bad thing is that the languages ​​that are interpreted, for example, are usually a little slower than the compiled ones, precisely because they have the need to add one more process, which is to translate the program while it is being running. That is, while the program that is already compiled executes, the program that is interpreted interpret and execute. And that was the last feature of Python, an interpreted language, such as JavaScript, PHP etc By the way, we have a JavaScript course completely free and very complete, it has 30 hours and you can go see it, it's available In the channel. And well, we're basically done here. After looking at the features of Python, let's see now why use it. Well, so far everything is very nice, everything is very beautiful, but with so many programming languages. Why should we learn Python? Is say, why should I use python? There are many reasons to use Python, let's go to see them one by one. For starters, any python developer can read and understand very easy most of Python programs, since it is a language, As I told you, very easy to understand. And if you know English, even more, because has a syntax very similar to what would come being for example the grammar of English. Python also allows developers be more productive, since they can for example write in Python a language with many Fewer lines of code than in other languages. That is, Python is a language that summarizes the code a lot. There are even languages ​​in which it is extremely important use curly braces, brackets, signs all weird, and in Python this saves us, we use the indentation, which is a way of leaving spaces in different places of the code so that do certain things, based on the structure of the program. This even forces us to be able to order better the code and when we do not work with languages like Python, have it sorted the same, since by default we would be programmed to order them So. But yes, in other programs there are languages What do we do in 20 lines of code? while in Python we can do it with 4 or 5, that is to say, it is really interesting. Also as a third quality we can see that Python has a great library code standard, which basically contains lots of code we can reuse, and we can use them for almost any stuff. What does this mean? Good. This means that we have an excellent quality, because developers don't have to write code from scratch, since we can use bits of code that Python gives us. For example, if you want to work with time from your computer, or if you want to work with artificial intelligence, or if you want to work with web, python is obviously not going to load you by default all the functionalities that it has, because the program would become heavy. Imagine calling all the functionalities that he has in a fart program. Let's say, it depends on the program that we have, we are going to use a function already it is or another I mean, why are we going to call everyone? the functionalities that allow us to understand the battery of our computer if in fact are we not going to use it? It's using, let's say, modules that don't really they contribute to us, but they subtract from us, because precisely performance detracts from the program. Basically that is, you have little bits written of code so you can do anything task you want. So I mean, look, I'm going to work with the time or with the battery or with this or with the other and you extract the bit of code that allows you to do what you want to do. Another positive thing about it is that we can mix it with other languages programming. In other words, we can easily use it and mix it. We can mix it with Java, with C, with C++, that is to say, it is not a language that runs only on your own. It is not a language that is unique and that does not we can mix with any other. There are languages ​​that kind of close and only serve for their own environment, but Python you can even mix it with other languages. Another thing that I think is one of the most Python's strengths is its very strong community. It has an amazing, recontractive community. We are talking about millions of developers around from all over the world who always lend their support constantly to help us solve any problem we have. Let's say, we teach new things, there are thousands of tutorials, thousands of videos, it is excellent the truth. Because on top of that it's free. Another beautiful thing about Python is, thanks to God, the multi paradigm. That is, we can transfer a program made in python to different operating systems such as Mac, Linux, Windows. It's not like it only works for Windows or only for Linux or only for Mac. Before, if we did, for example, a program for Linux, we had to make another completely different for Mac and a completely different one for Windows and so with each of the systems operatives that were We made a program for each language and we reused part of the code, but we did like different programs. We didn't use part of the code, we used logic actually. In other words, the logic that served us to build we used that program but in different languages ​​or in different ways. With Python, bye. One code, multiple platforms. And finally, if we are going to talk about economics, Another advantage of Python is that to Python they say the increases wages. Not only because Python is a language of the best payouts in the world, that is, only with Python and on your own you have a excellent job opportunity. Here I am referring to the statistics average show us that a developer from Python earns an average of about $100,000 annual. In first world countries a little more, in countries third world maybe a little less. In third world countries working abroad, a little more, a halfway point. In short, I mean that not only I say it for this. Taking out that he has an excellent job opportunity, knowing Python is a very powerful skill in any job. Lawyers, doctors, etc. Python really is a wage raiser for flaw. That is, let's say, come to a company, apply and say, yes, I'm a developer in Python, I know how to create programs in Python, i work with python i know python i am a beast in Python. It's really the factor increases wages. If you are an accountant, lawyer, doctor, scientist, scientific above all of any kind of biological or medical science, say, that is, any kind of natural science actually. That is, I know Python and that's it, you upload two or three entry salary steps. So keep in mind that it is very important. And those were exactly the characteristics and some of the most important things for which use Python. Each case will be more specific and depends of the objective that you want to give to your own learning, right? But the truth is that I feel that learning Python should be, let's say, something that we serve in any kind of situation. It works for us for whatever we want. Let's work, let's not work, let's be entrepreneurs, let's be of any profession. Learn Python and you won't regret it. Well, now we know that with Python we can do of everything. Well, what does it all entail? What is it most often used for? Because it's not like Python is optimal for absolutely everything. Yes for the vast majority of things, but it's not like we can use it for really everything. Let's see what we mean by which is general purpose. Let's see it point by point and why is normally used. So okay, let's start with the first. To begin with, it is used a lot as a language to develop web pages on the side of the server. I mean, yes, for web development. A lot of video, image also usually runs here. There are two great frameworks called Flask and Django that are to be able to develop websites with Python. This is excellent because yes, we will be able to use Python to make pages Web. I mean, it's very useful. since web development also has a excellent output. It also helps us to develop applications Mobile, obviously. It also helps us to develop applications desktop or desktop, obviously. We are talking about programs such as, for example, Blender, Vitorrent. We are talking about a large part of Google, for example, was developed by Python, much of it many more. desktop programs, programs that you can open as Premiere, as After Effects. Only if I'm not mistaken, Blender was developed with python and Vitorrent too, so don't say the examples. It is also widely used for automation of scripts, For example, to monitor the battery, battery health. We report battery information on devices and other things. For example, we report the amount of energy that the device must have to be healthy. We are talking about the level to which it is charged. Also with automation we can detect, e.g. Log4j files to basically see where we can have Log4j active. For those who don't know, Log4j is just a java library that a security bug was recently discovered very important what would make... Oops, this is a bug. I don't know, man. As I was saying, it is a very important library that a security bug was discovered and that this put many systems at risk. So what needs to be done so that the system be safe is to update the version. With this, what we do is detect revisions previous to start and understand what are the We have to use. Basically to avoid security breaches. We can also use it for, for example, perform data science tasks and Machine learning. Python is reputed to be the most used for Machine Learning. Which is precisely a branch of Intelligence Artificial. And also one of the most popular for data analysis together with R. Python for these jobs is very useful. It has libraries like, for example, NumPy and Pandas. And well, they are among the best known, among many others more. In fact, we are going to take an Intelligence course Artificial after this python course. So if you want to learn Intelligence Artificial It is a mandatory requirement that you watch this video. Why the Artificial Intelligence course that we are going to give is going to be with Python. So if they finish this course they will be ready to start with Artificial Intelligence. In fact, if you come from that Intelligence course Artificial that will already be in the future, I congratulate you. Well, well starting with the basics. It never hurts to have solid foundations. Then it will be more difficult for you to fall. We can also use it for development of software. That is, we can develop software like such. This is simple. We can program, for example, gadgets like the Rapper and the Arduino. Create management programs, not many others more things. Companies that used Python for almost everything its development were Pinterest, Panda 3D, Dropbox, Spotify, Netflix, Uber, Google, Microsoft, YouTube. And well, I could continue nominating a list very long It is also used for automation software testing. This is basically for testing QA. In other words, functional tests and see if a program works. We're not going to go into that much detail, but is that. It is to verify that everything is fine, let's say. Everything works. You can also do game development. Yes sir. Although it is not the best language to develop games, that is, it is not like the best to develop games, yes you can. In fact, we have libraries for that, like for example, Pygame. And we can create games like, for example, Battlefield 2. Battlefield 2 was made with Python. Summary, Python can be used for everything or for almost everything. In fact, there are cases where we cannot use it. The only thing we can't use Python is, for example, to access hardware logs, What do we want that for? When we work with Python, since the purpose of Python does not go that way. Cannot create device drivers. I mean, we can't we can't create drivers, Let's say. And very low level bullshit. Give instructions to microcontrollers and that kind of specific stuff. That although there is a way, it is like which is not native, but you can. But it's not native, so technically with python only no. But they are things that really do not interest us. I mean, I really don't think that unless you wear to program video cards or program micro controllers and so on I don't think they need to. In short, yes, with Python we can do everything. We are not going to say almost everything, because it is like limit a language with an almost that is actually absolutely everything. So yes, Python can do everything. Everything other than those things, Python will can use for everything. Even for hacking it can be used. Yes, for hacking. Yes, gentlemen, that's how it is. useful is language. Well, not for a reason it is the top 1 and one of the most important in the world, right? Well, the truth is that the people to whom like the story will kill me, but never I was really interested in the story of these kinds of things, unless they affect somehow the performance we have, right? That is, if it somehow affects me like developer, great, but usually It does not happen. But, since it is a complete course, I have to explain them to them because it's not bad, and this It's a story like... that it contributes, so I tell it to you very quickly, it's very fast, very fast and very short. Guido Van Rossum, the creator of Python. He published the first version of Python, the 0.9.0, in 1991. It already included some types of data and, well, functions to handle errors, right? His philosophy from the first moment always was the same, and it was to create a programming language that is very easy to learn, to understand and to write, but without that precisely curb your potential to do anything kind of things. Normally for a language to have all these features lose a lot of potential, but Guido managed to make Python not like that, that is, we can use everything and it is a language very powerful. Python 1 was released in 1994 with new features such as, for example, to process lists of data in an easy way, such as assignment, filtering and reduction, that is, power filter, be able to reduce and even be able to assign. Python 2 was released on October 16, 2000. with, well, useful new features for programmers, such as the support for Unicode characters, what are these characters we are seeing here, and shorter forms, for example, of traverse a list, which is a data type which we will see later. Python was released on December 3, 2008. 3, including new features like, for example, the print function, that is, being able to print things, and more support for number division and error handling. Later, with the advance of time, they were outputting the different versions of Python. Python 3.6, 3.7, 3.8, 3.11, for example, and they were dating It is said that Python 4 will never come out, there will always be different versions of Python 3, Python 3 point something, but Python 4, obviously, will never come out. For me, a Python 4 will come out. But now, we probably have many plus years with Python 3. The latest versions, 3.8, 3.9, 3.11, 3.2 and so on are basically, shall we say, fixes to the problems they have, they fix the bugs, optimize the language to make it more useful, even faster and others, and they are giving tweaks, let's say. In fact, in this course we are going to see all this and much more. Let's see the updated ways of working with Python, including the latest more recent. Like I told you, you can't be in a better place you are to learn Python. Now yes, let's get rid of the chatter, enough to talk, we already saw the part, let's say, theoretical for now, let's install python and get started. Ok, now let's start with the important thing. which is to go to the code once and for all, but before going to the code we have to install Python, so let's install Python. Here I created a specific Windows user and I left everything very clean so that we can do everything right step by step, that they continue me and doing all the courses. So I'm going to open Chrome, notice that I even created a personalized account. I'm going to look to download Python and here I have python. It is the first page that jumps, if you look now you see, it's the first page that jumps, literally is the first one that jump. They go in there and here they are going to say Download Python and the version. you guys download the last version. In fact, what it does is detect automatically the operating system on the that they meet and well it makes it a lot everything easier because, let's say, it simplifies giving us, if it's for Linux, Linux, if it's for Mac, Mac, Now it's for Windows, so we download python for Windows. There, click. No, bolude, we get off this file and indeed I am not going to say I don't I download it because I already have it, but I'm going to to unload with you, because literally I you create your user for that. That's not how I do classic to say, well I don't download it because I already have it. Before I put it down, I'm sweating in a way, It's almost two in the morning, it's hot, brother, a heat, 35 degrees in Argentina. We are at Argentine temperature today, look, 34 degrees to now, 34 degrees, humidity 54%, which is crazy, I can't stop sweating. So if they are in winter or are they with air conditioning or something, grab your coffee, drink your coffee, enjoy it calmly. Now yes, come on to continue. We open Python, a nonsense, and we give Install Now, and yes, I'm going to install it too. Come on, the first one who says that too install it with you. While installing python I want to tell you that I don't know if you could fix that the scene is literally a little different and it's because, well, I want us to focus in this, then nothing, like I hit a light stronger in front and I lateralized it to hit me from 45 degrees so that, well, it can be more dramatic everything, right? Because I need look over there, then from where I see, that I hit the light. My questions, silly. ok there settled python. We close it, a boludez, that's it. We literally already installed Python, like that easy we install python. so we can shut it down and now we are going to look for Python, here we have python, and we can now interact with Python. Now we are going to say quotes, hello, hello, ready, that's it. Of that way we can explain what works and that we are already with Python. Now we are going to put 1 plus 1, tells us 2, good. Well this is here basically it is to give instruction by instruction a python. Here we literally have a console of commands, just as CMD has it, they saw yes we put Windows, for example, we can move through the folder, we can for example put, If I put Exit here, for example, come, let me close the CMD. If I put Exit here too in Python, nothing happens. Why? because they are interpreters different. One thing is Windows CMD, another stuff it's python. Python has its own interpreter. Do you remember that I told you that Python had a interpreter? Was it an interpreted language? Well, this is the python console that is run of this form. That is, this is not the interpreter as such, but it is the console that, say, is responsible directly to the interpreter pass the instruction per instruction. So now if I put Exit, the function and closes. there it is, come on to open it again to have it clean. and here we are working with python. we literally can tell you, as I just showed you, 4 times 8 and he is going to give us result. We can say 10 plus 5 and we going to say 15. Nonsense. But what what if we we had to do a lot of things? Many instructions. For example, what I told them before, A equals 2, B equals 3, C equals A plus B. And now I tell you, show me C. What are you going to show me? A mistake, because I capitalized it. Let's go back. Print lowercase C. There it says 5. Because to is equal to 2, B equals 3, A plus B equals 5. So, if I tell him to show me C, he shows me c. is really nonsense. So far we are all good. But again, what if we wanted to make programs complex? With complex programs we can write or put everything this. Does not have sense. You enter a program made in Python and the program opens by itself. You they do not have to open the console to run a Python program. No. Open the program in the game .exe or now in the program.ud and it opens by itself the program and it runs automatically. Then, how do we do this? Well this is because we do not write the code here. We wrote the code in something called a code editor, which basically is a program in which we can write all the python code and then execute it all the same time and we don't have to make line per line. There is no developer that uses this to program. Does not exist. Really does not exist, because there is no way It can not. Then what we do is use a code editor. So let's download it. Let's close this python. Let's go back to Chrome and we are going to look Visual Studio Code. I finally downloaded Visual Studio Code because in previous courses used Sublime because Visual Studio Code weighed a little enough for what it was, for example, a notebook of the government of the kids. so not all could be downloaded Visual Studio Code and that you flow completely fine. But nowadays it is already very optimal. It's excellent. The requirements of the computers that go higher, since it is a minimum requirement for installing Visual Studio Code. So there we installed it. Same thing, we go in to the official page. Too easy. we seek visualstudio Code, we click, simple. we give install for Windows. Same thing, install. I do I'm going to install too. Everything you install with you, I'm going to install it with you. There it is downloading here. We open it. I accept the agreement and of course, If you don't let me, you don't give me many options either. Next, next. I will create an access right on the desktop, why not? Next, Next. There is. That's where the download ends. Ready. There we end it. we give finish Y automatically opens. Let's use Echo on Google and here we have this complete. All right, Here we can choose what theme we want. Yes we want contrasted, light, another version of light or dark. We are going to use the one that comes perfect, which is dark, simple. And before we are going to start creating a pair of Projects. So let's go to the part of extensions and here we are going to look first python. First we look for Python up here and we this extension is going to skip, which is to be able to to run Python from here. So we install it and we will be able to make it work from here. We are not going to having to go around making all the code run separately here. With this we can to run to do as a kind of demo of what It will be our program. We write the code and we show a demo of our program below in console. We installed ourselves as the interpreter of Python below. There we are, we already installed it. Now we are going to install Prettier. This is basically to format the code, so that for For example, give us some things of one color, other things of another color, so that it has a format like must be. There we install it. and then by last let's install the Python indent, which is to indent the python code. Do you remember how I've told them that did the python indent work? Basically everything fits us in its place. There you see how works. We write something and automatically we it identifies as it should because that's how it works python. This by default it works in Visual Studio Code with the Prettier, but it doesn't matter and anyway form we are going to make this run well because we want to that we have a code that is indented. Then To avoid problems I recommend installing it because it automatically identifies us so that works in python. So now we close it and we are Now we just give you the explorer, as we were at the beginning, and we are going to give it Open Folder. But first we are going to take one folder in the desk. So I'm going to come to the desk and give him... Well, we are going to put this here, to the side I'm going to open up everything. There goes. Here in the middle I'm going to create a new one binder. New folder. Dalto Python Course. I go to put it well Dalto, very big. and this it will be the folder in which we are going to work. so i go to this folder drag it and bring it here. here I have it open. Here we give you trust in the authors and give it Yes. I trust the authors. That is to say, In Myself. And here we have the folder. Very simple, the TRUE. Very simple. And finally, if you notice, me here for example I will make a new file. Let's put it helloworld.py. Let's create a file. This is he first file we have of all files. Here we have the first file. and it's important the .py because just like an image is.png,.jpg, a video is.mp4,.wav,.avi, an audio, sorry, is.wav,.mp3. The Python format is .py. For that is important that you in the file put .py. And if you don't get this, always try find a way to see the format of the files. In this case it is.py. if I here suddenly I put print helloworld, if I run, you can press F5 if you want. down here I It actually says hello world. if i for example here I tell him print 2 plus 2 and suddenly I give him F5, down here it will tell me 4. The result of 2 plus 2. Here we are already running and making functional python. Simple as that. There it goes, if you write clear, for example, put any thing, right? Anything. and then they put clear, The console cleans itself. Simple. Congratulations, They already made their first helloworld in Python, They already wrote code, that's it. okay there let's do one more time. hello world, thanks Dalto for teaching me python. and we go to press F5. There is. Hello World, thanks Dalto for teaching me python. Ready, spectacular. I congratulate you if you did this, I congratulate you again. leave me a comment showing me how you feel right now. Strange. But they want to be programmers, right? Well, all right. Now that we have this ready, now what already We have everything finished, I want us to start with the first concepts of python, ok? Because if, we can talk about programming concepts, Programming Fundamentals. But what happens is that Python, for example, has its own, let's say, implemented programming concepts. As I told you before, programming oriented to objects, we have variables, we have loops, we have conditions, we have functions. All These are things that we are going to see. are concepts of programming, but they are concepts that Python implements. So that's why I tell you that come on Let's see Python concepts. That is, they are concepts. programming, but they are in Python. So At the end of this section, I give you the official welcome to the code part from Python. Now let's see code all from scratch and here begins the real course. let's start with the basic concepts. To begin with, you know that there are types data, right? Simple. Type of data. A number, for example, is a data type. A text is another type of data. Why? Because I can already a number multiply by 3. 3 times 3, 9. 4 times 4, 16. 5 plus 5, 10. They are numbers that can be operated. On the other hand, if the numbers were texts, 5 plus 5 would be 55. 10 times 3 would be 10, 10, 10. So we have to find a way multiply numbers and not as letters. 10 times 3 is not 10, 10, 10. It's 30. That's why we have data types. This allows us to understand what are the different, Let's say, inputs that we are going to give to the program, what are the different data that are going to handle. We have four simple data types. What are the singles? They are simple data. Then we have composite data, but what we will see later. Simple we have four. So let's get started. First and foremost I want us to create a new folder. We go to the new folder and we are going to put types of data. And here we are going to put in here, we are going to move it in here and let's rename it. Let's put .Py data types on it There we are. The first data type that Python has is text. The first simple data type, text. How is the text written? Well, to write a data type that be text, we use quotes or single quotes or triple quotes. Now we are going to see well what each thing is for, what are the cases, etc. But let's show them, okay? Let's show them. The strings are... I'm going to increase the letter a bit at the beginning so that you can see well. Then I reduce it, but at first I go to make a little bigger so that you can see it. This is a string, okay? It's called string. Text, the type of data that is text, allows you to we say string, What does chain mean and does it come from chain of text. Because if we have, for example, a single character, it's a chain Many characters are text, so string of text. So we can write a string. So we can also write a string. And then we can make it triple, with quotes triples. That is, like this or, for example, like this. These are valid ways of telling the program that data type is a text. What is the difference between this and this? Well, the common ones we can't do this, for example. You see? We can't do this because it's wrong. It has to be in one line. That is, if we are writing text in a single line, we have to use these that are the simplest, the simplest. Double quote, single quote. If we want, for example, to say, your data are two points and below continue writing, for example, no HE, name, lucas, last name, dalto, we can't. Note that my color changes. Why? Because he is telling me, che, this is not text, the text goes in orange. What is text is orange here. So here anyone is squeezing me smell, it doesn't make sense. How can we do this kind of thing? Simple. Well, here I am going to leave a string so that no we forget In this case, here I am going to replace and paste it. Yes we can do it, okay? If you know JavaScript, it's like backticks in javascript. So we can, for example, come and put this that is every time, your data is and here we have this. So this is valid. This the program allows us and also allows us here. Look, I paste it and there we have it. This is valid. Why is it valid? Because it allows us to write multiple lines. Here it starts and here it ends. This is to say, look, the string starts here and end here. But we can't do line breaks, or I mean, we can't go down and leave a space. Here yes, here we can leave, for example, one, two, three and so on. No problem. This is the limitation we have, isn't it? So it's important. In fact, we are going to leave it like this for you See it. Which is the complex or the simple? That is text. Then we have another type of data that is data type numbers. We have the numbers, but in Python we have two types of numbers. They are not common numbers, they are two types of numbers. The first type of number which is int, which they are integers. 2, 4, 5, 20, 527, 455, integers. Numbers that do not have a comma, integers, round. And then we have the floats, which in English is float or float. They are numbers with a comma, simple, with a comma. For example, this is an integer. This, in this case, is written point. Instead of comma, point is written. If we mean 4.4, it is 4.4. I clarify it for both of you. So this is an integer, this is a float number. So, if I, for example, wanted him pass an integer 40, I pass you an integer 40. If I were to pass you an integer 40.2, in this case is 40.2, this is float. This is an integer, an int, int of integrate, fully This is a float, float, floating number. And then, on top of that, don't forget that these are two different data types, just in case This is not that they are two numbers. Yes, they are two numbers, but they are not two integers. One data type is int, another data type it is floating. That is important to highlight. And then we have the other simple data type, what is boolean Simple, boolean, true or false. That is, it is something that is divided into two, only it is something that is two, two possibilities. One is true, one is false. They are the two possibilities of Boolean. In Python we write them with a capital letter, False or True. If we want to write something in Python, the first letter is capitalized. For example, you can see that I put false with lower case, I didn't take it. It is because it is capitalized, false. There he took me in blue. This is an already true word. This is a boolean data type. So, false is boolean data and true is another Boolean data. We have these types of data. So we have strings, which are strings text, integers, int, integers, numbers whole. Float, float, floating numbers. And booleans, boolean values, let's say, are boolean data. True or false. This is useful for tomorrow to tell him, look, if this condition is met, execute me this code. Yes No No. For example, if it is before 7 in the morning, do this. How we do? As we know? Well, if that's true, if this is true, we execute. If this is false, no. It's an example, right? But it helps a lot. These data are very common and will see for What are we going to use them for? Because you out there the numbers understand what to use them for The numbers, either floats or integers. The text also understand what to use it for. They understand that here they use it for things simple. They use this for, let's say, extra things of a line. We can multiply numbers and so on. Floaters too. But what do we use this for? Well, we'll see. But they have to understand that they are two types of data more. Sorry, it's one more data type than just has two possibilities. True or false. Nothing more. Well, to this file I put simpledata.py. I replaced it. Instead of being composite data, I put data simple. Now what we are going to see, basically, they go to be the variables. Because before looking at the complex data, to understand complex data well we have than to use variables. So let's see what variables are. ok, the variables we are going to create in fact here another folder that will be variables since we are going to create a file that is variables simple as i told you before variables if fixed and this is interesting if you pay attention and you write a lot of code and suddenly nothing appears or appears the python format puts true and does not change them nothing use quotes and do not jump in orange as they should jump well what happens is that not so with him python format then I give it rename and I add the point py and now if I know come add this to me the quotes add me orange the text so now ok ok now yes the variables basically are spaces that stored in the memory of our program because the data we we have to reuse them that is to say any data we reuse what I did before and they notice that I put the same 2 b equals 3 c equals plus b what is here are variables we have one variable another variable and another variable because here because it is a variable because this can vary simple that is here instead of being 2 it can be 5 this can be 8 ok it's simple then I, for example, execute this that is here I tell it print c and run it with f5 here 13 is going to be executed but if I suddenly I change the 5 to a 15 when f5 will not be 13 it will be 23 because 15 plus 8 come 15 plus 8 is 23 of done I can do this I can for example Put the same name Lucas Dalto and when I say show me name show me by screen name yes I run, it will tell me that the name Lucas dalto and if I erase the dalto the dalto remains that the name when he of f5 is lucas because it is a variable we are asking it to display a only thing then in this way for example we can tell you look at the name of user with which registered was such and we called a database data then the database will change if the user puts dalto is dalto if the user puts pepito it is pepito so that's what the variables are for storing information that is useful so in this case we can also put numbers for example 40 we show 40 I can put 40 plus 20 what we execute it gives me 60 it can be operated in here too then those are the variables not now well if we have to talk about concepts variables are declared when i do this same name and there I leave this for example I put Lucas here I am declaring a variable and here I am defining it the variables are declared and they are defined I told the program I am going to create a variable that is going to be called name and here I am telling you che look at that variable that I already declared is going to have the value of Lucas here I am defining these are concepts for us to go having the variables declare and then define then also We can modify it if I example here I put the same name Lucas if I I execute it as I told them, it will show Lucas but if I come down I come and put no now the name is not wrong Lucas now the name is dalto even if it is a surname name is dalto if it I execute it, it will tell me dalto and if I down here under I say no the name is neither lucas ni dalto the name is pedrito when Update it will tell me Pedro because variables are modifiable common variables can be modified name can be equal to lucas and after in the following line in this case we are redefining the variable because declared it's already declared ok the variable has already been declared and we already declared it we declare it only once then we are redefining it and look at the variable is the same name but not now It's going to be more the same as Lucas, it's going to be the same to dalto and in the third line we say and now it will no longer be the same a dalto now is going to be the same as pedrito then we are redefining because we don't tell you to the program will have a variable called name because we already said it before I take out the first account others are definitions if they can first put one thing and then another does not do They need to put a name 1 the same Lucas name 2 equal dalto cannot be modify and can walk along of time, for example, I put now for example I put number number equal 10 since I'm going to show you my number and I give it f5 here it will show me 10 I can then tell you a number equal to 10 plus 1 and now it is going to show me 11 but there is other ways to do this instead of doing in this way a very common is to say that he looks more the same 1 and there if you look when I give it f5 he tells me 11 also because because the most ahead of equal means che look at the value that already has more than what is after equal if the value of before it was 10 is 10 plus 1 gives us 11 I will I put 5 and run it gives me 15 because it is 10 plus 15 I go down for example I put number more equal 3 easier another 5 5 back when I run it will give me 20 because because 10 plus 5 equals 15 and then 15 plus 5 equals 20 then it is good that we begin as well we can arm we can also challenge since I put more to put less and when update gives me 10 because because 10 plus 5 15 minus 5 10 back after of something called concatenation concatenate is a word we use when we want to refer to that they join two strings I one this with this but we do not say join we say concatenate because just from the chains strings we concatenate them then it is concatenate we put them together what if suddenly I did this I do not say for example name or I'm going to say welcome no welcome is the same as hello and here I want say the name hello lucas or what whatever the name, for example, I came to put name the same something not name the same lucas hello lucas how are you? as I do to do this? well we can do two things we can say for example hello more name more how are you how are you if we show it we will welcome it to show us welcome if we give it to run with f5 hello lucas how you are but here if they look at us displays everything together because because each character count the space is another character so it's important to put it and here also the space is different character then now if we update and we reproduce and run back to the program here is now is working if I suddenly put hello here Mario also throws us this hello mario how you are changing it depends of what we put then the user has another name will tell us username for example and this as I told him it can be single quotes double quotes triple quotes this can be whatever updated and me still working no problem but this not very useful because sometimes when we have let's say numbers and others like that this is really we complicates and is not optimal then if this, for example, were to be not I know a 5 if we update it we have an error because it is a numeric type so what happens here how could we concatenate 5 and others good first let's leave mario there it is working let's go to give it down in the console we are going to give it clear so it was cleaned and the other way is using the so-called .format .format but we are not going to use format because he is very very rancid format so we're going to use the one I I use that is leave the space quotes are complete hello how are you and here we are going to put keys simple keys and here we put a name so if you look I update f5 and f5 and f5 and always I get the same hello name how are you indeed there is a good mistake what happens is that this is called f strings that is, they are the f strings for concatenate this way we simply add a def forward and now notice how i change the color is updated now it works hi mario how are you and if there suddenly instead to put mario I put a 5 se I update now it does not throw me an error and it concatenates it and now the 5 became text because because what this does is even if I put true or false or what that it is updated and it tells me hello true how you are because this what it does is take a piece of data and convert it to text like this simple if we give it a boolean data converts to text if we give it a numerical data converts everything to text converts to text that's why I use this I use this normally no no I always use this because I know that sometimes can you generate me some problem with numbers and this is the best way to integrate a number into python before let's say that using the percentages to concatenate was very ugly the truth since python 3.6 in the f strings are available in javascript can also be and is doing this in javascript we do this without adding the fy it works and is valid in python not in python it works so we simply add the f ahead of the data is because the data is a data of type text then in front of the text we add the f it's that simple to do this is the truth that it is very easy I recommend doing it this way then if we wanted to make a variable is not more declared we simply use the welcome operator for example and there we update it tells us that look at the truth that welcome is not defined that is not we never define welcome that is to say is a data is an error has us a program error because it is not defined the variable because because the we delete with del is an operator to delete data we can also tell you by example save name but if i update with f5 says hello true how are you what was this if i deleted name why is telling me true if the name I deleted it, well, it tells me because the name I deleted after declaring welcome welcome is going to be equal to this then here automatically when you We said this has already become and this has become in this it is already so that I deleted the name, the variable is there list then nothing changes if you let's do before and put the before now it gives me an error why because we still couldn't create welcome so what we do is let's put it down and now if we put it below when we update it there It still works for me, we update and it follows me working hello true how are you is an interesting operator with this with this operator we delete data that is stored in memory we delete them later of the variables also by example what we can do is operators membership and operators of identity I, for example, put I che show me hello, welcome, right? if I I give f5 it will tell me that this is true because because this little piece of text He's here if we tell him to find me this one text here it finds it for me because it is here this that is here is literally this I told him to look for me, for example Pedro is not going to find it for me so I I give it f5 and it tells me false because why not it is and if I I say not in and update it finds it for me because it's true that che pedro is not here welcome no and if this is true this automatically becomes true if this is not in here and it is true Pedro is not there and I put here for example hello with a capital h and update tells me that it is false because because if it is hello no you are welcome if you are then tell me false because what I am is a lie saying it's a lie I tell him with a lower case it even tells me true because why hello no this but as if it is here not because this is hello with a lower case and this is with a capital letter is a case sensitive language as I told you is sensitive case sensitive They are a character type lower case is another completely different type of character these are we membership operators want to see if this belongs to this indeed is a form interesting because I, for example, choose look at the truth the name is mario por example I'm looking for Mario here, no, so I'll update and it tells me false because mario is not welcome is false because if I am, for example, che mario che mario is welcome if you are here this This is what is here and it is Lucas in welcome update no it is not lucas no let's see let's go give him Lucas ok now if he tells me he is as well as this works that there is very simple that we are seeing now very very basic if you did not understand take a look at it but so far that's all very simple I am going to leave notes for that you are having everything that we are going doing ok annotations in python the annotations the we can do with with this sign that is the hashtag the cat the slash is not the slash is the hashtag It is the trend and here we put for example operators of belonging in and not in and this that is here is something that the program does not interpret for me that is, the comment is something that only the developer can see only I can see it if I I write This here is something that only for me I can see if we go to any website for example we enter to google let's see that google has comments for example this that is here in html is a comment see this that is here this is not it appears because it is a comment come if we go to give it you edit html this is a comment well the same thing exists in the languages ​​that not we can see how the python that is here is just a comment this in fact yes it I execute with f5 it does not interpret it for me it tells me true and does nothing more than that because because is something that only we read and that the interpreter python does not take it into account does not execute is something to the developer so that when the developer see it understand it this is very common because when we have super code long is good to document writing Y writing down what each part of the code does no then I want to lift this no print Luke not in welcome then this will give me false false and this will give me the operators the operators give us true or false this type of ok operators the membership operators give true or false simple then let's get up this that is here we are going to remove it we are going to leave it below and this is what we are going to call concatenate concatenate with f strings there it is, let's put concatenate with more and below we put can be welcome same hello space more space how are you then let's leave this backwards now yes a lot best and this other space here we put defining a variable and there we have all the code commented defining the variable we define it concatenate with more we concatenate concatenate with f strings we concatenate them membership operators ok they are these and we show it on the screen now it's simple there it is that simple so if we execute with f5 it returns true and false because because first it returns us this lucas in welcome Cash is true because Lucas is here in welcome and then he tells us that Lucas is not in welcome and Lucas if you are then return us false the of above is true the below is false if they execute both remind me later if you look at me for example here you could use welcome to the user no user or how to write two letters welcome I gave the user an error welcome the user Or is it easier, look, let's put it up Name complete because we mean that he gave us a full name full name and we put Luke dalto but it's wrong so the way can be like this or it can be to separate them with hyphens put this down it has a name the name is camel case yes we do it with the first letter of each new word in capital letters it is called camel case ok while What if I, for example, is defining a variable with camel case is more I'm going to put it like this for that we understand camel case camel case ok is when we do this full name of your master uncle this here is camel case because because we are using that is like a hump ok camel case the more the beginning the name complete we have 1 2 3 4 5 6 words the beginning of each new word is capitalized is a form of separate them and put several words but that is suitable for example for javascript in python the official recommendation that python gives us is don't use that use something called snake case either just the style of the snake is not does with an underscore full name and now can put your uncle's master's then this is define a variable with snake case there it goes camel case snake case i actually played around with this because camel case is good because the first with capital letters come in the name and here snake case did the same all lowercase and here This in python as i said the best developers they use snake case because it is precisely the recommendation that the official python company it gives us then we are going to pay attention to it later also here we are going to give it clear and we are going to lower it a little there it goes later until here more or less the first section of variables we are going to have another section of variables because we are going to do another kind of thing with variables but for boot this is all you need to know on the variables are just spaces where we store data, ok? in a variable we store a piece of data that's all each variable has a data inside can have a single data a complex data What are the next data that we are going to see? now so before i go on with all this we have to see what the complex data is with these python data a lot we can't do like this that we should work and understand each other data types so we go with the following guys data is complex data That is, they can be exchanged and it will be all good. Well, now we are with the complex data, it is simple. We have to... in fact, here they saw that yes Look, it's like the dot here. Well, this point means having an error In the code. So there is an error, I give it F5 and there Already... Ah, there is an error here, you see? Name. It is not defined. It is defined, full name of your Uncle Master. Update and there it is. Now yes, if I update, it throws me True and False. Perfect, now it's more than fine. Well, here we already have this and you can understand it all right. Buy it, now we go with the next thing that are complex data. We are going to come to data types, as they are types of data, and we are going to give it in here, New File, and we are going to put data-composites.py. Not complex, compound. Why? because they are composed of others data. Composite data is data that has inside other data, simple. They are data that does not... a single piece of data does not make a complex data, but are like several data together. Can you have only one data? Yes, but they allow To have more. Now we have simple data, these that we saw, variables and composite data. I'm going to close these two so that we have left only this, and now we are going to work. The data-composites, very briefly explained. Just as I told you, these are data that inside have simple data or other data-compounds, but that we can group them. The first type of data is precisely the list, so let's create the first list. Let's put a list, the same, and we can create it with brackets. So we have a list. So, for example, I can tell you, look, the first item in the list is going to be a text string. The following can be, for example, my channel from YouTube, SoyDalto. Later it can be, for example, if I am with a lot of desire to learn, true. Then it can be my height, 185 centimeters, or 1.85 meters, it can be. 1.85 is fine, let's leave 1.85 meters. And here we have a list, because it is a set of data. Then I suddenly tell him, che skinny, let's see, show me with print that you have in the ready. Print is precisely a function that allows us to display what that value contains. So if we put print and inside we pass it something, it will show us in the console what it we passed. Then we give it print list, f5, ms che, it's a list. Well, but then you're not showing me nothing. And of course, because it is a list with a, it is a. The data type is list, as I told you, but it's a list. We update, and that's how it shows us, look, Lucas Dalto, I'm Dalto, but if I wanted to access one of these data, Put it that I want to group data. Well, this is not for that, to group data, because if we want to access any of these data It's as simple as saying che, look, give me element number one and returns me Soydalto. Because if the number one element is this, Well, welcome to the world of programming. Here we do not count from one to ten, we count from zero to nine. Basically the way this works I am going to simplify them very simply. What you are seeing now is a simple array, a simple array that has various data. If we tell him, for example, to pass us the data zero, the first element is passing us, because we count from zero to the last element. So we have zero, one, two, and three. Those are actually the data. Yes, this is the first element, it is the element number one, but the index is the index zero. Element number zero does not exist. For what? Because it is the number one element, but element number one is hosted at index zero. So when we refer to index it is what position is he in, right? Because this has positions. zero index is the zero position. Index one is position one. Then, the position is the index. And then there's the item number, right? Because it is element one, then has element two, then the three and then four. But when we count it it goes from zero on forward. So, suppose we want to call I'm Dalto. Simple, we say list one and that's how we call. What is going to be displayed on the screen is SoyDalto. If we call element two it will display True. If we call the element zero it will display Lucas Dalto. And this is how the list works. Between square brackets, everything in brackets, the number in brackets is that defines which element is going to show. You see, it's really very simple. It's like that easy and it's really simple. A list is just a type of matrix. Then we have another matrix that is similar to this which is precisely the array, the arrangement, the famous arrangement. but this is another matrix. That is, arrays are other types of matrix that we have to do other kinds of things to work with these. It is widely used in Python, arrays, the arrays. But for this specifically, apart we use this type of matrix that are the lists. A matrix is ​​just a data set. A list, for example, is an array. Let's see, I'm going to clear because I don't like it nothing of this. Now yes. Then we have another composite data type which are precisely the tuples. They are the same as lists. I can say here for example, tuple. It is the same as the list, only instead instead of using square brackets, we use parentheses. And here we can do the same. We grab and copy. Is the same. And it works, huh? If I, for example, here I say tuple, zero. When we give it f5, it works. Says Lucas Dalto. Here I put a list, zero and update. I do not care. What are the differences? ok the difference is that the tuple cannot be modified. Do you remember that I told you that the variables could they be modified? If I, for example, put the same name Mario and below it put the same name Lucas. Name is now Lucas, no longer Mario. Well, if I, for example, take this and say, I come here and make a list three, for example, will now be equal to other data. I don't know, Lucas, just Lucas. Or not, look, machinola, for example. If I press execute, we are going to say, print list three. There it goes. She says, well, look, che, now suddenly ready It's machine. Well yeah, okay, it works. machine, machine. But if I suddenly say tuple, update and it no longer works. Why? Because the tuple cannot be modified while the list does. This is the good. With tuple we know that we can have a data set that will never change. Never. Always These are going to be the ones we read. While the lists can be changed, touch, remove, modify. So that's the good stuff, right? If I here as I say, I mean, well, look, list we made again. There it is, it's fixed. and back to me it shows. Machine. So we are going to put a comment that says creating a list can be modified. And here below creating, we leave a space, creating a tuple cannot be modified. And here we are going to put, this is valid. and them I will show the first example of commenting code. Because until now we just make comments for the code, to explain. But we don't comment code. A way to comment code is the same. We come here and we put the same sign ahead. So in this way we comment the code. This is not going to run. if we want run, we simply uncomment the code. It is the same as making a comment. Only that conceptually we say that we are commenting code. Because here we are commenting text. I mean, we are not commenting any code, we are commenting. While down here make this pass to this is commenting code. Because already code that can be executed we are commenting Now we can say that it is a good program. It is well created and it is quite good. We have this. And here we already have two types of composite data. What are lists and tuples? Simple. They are data sets. Easy. We call it the same, we do everything same. All equal. It is important that you see that the tuples go with parentheses. But when we show them, this is invalid. They go with brackets too. As much as the let's do tuples with parentheses and lists with brackets. Everything to show it always goes with square brackets. Those are for now the two types of data that we have been seeing Let's keep going down now. this that is We are going to discuss it here as well. Then we have the next, let's say, data compound that is the set. Or the, say, set. To create it we now have than to use a function that is the set function. Let's open this. And we are going to put set. Creating a set. Set. And basically the characteristics of the set. Well, we believe it the same. I now come here, copy this and paste it. And here, for example, I put the difference that to create it we do not use brackets or parentheses. We use keys. We create it with keys. And here we are separating precisely from this form the object. But here we come and put, in this case let's put together Now yes. In a set just the differences it may be that, for example, they do not have a fixed order. That is to say, they are disordered elements and that can change. I mean, let's say, Lucas can be tall suddenly where is SoyDalto. Later we will see the use of sets, okay? But basically they are almost the same as the ready, okay? That is, the set can be modified, only the elements don't. It's like tuples in this case. We can not modify elements. If we say, for example, set 1 equals pedrin and we execute, it will throw us an error because it cannot be altered. I mean, can we redefine it? Yes. I can suddenly come here and say, look, set the same and suddenly create a new ready. Haha machine, I screwed you. We execute it and well, works. I mean, no problem. This works because it's okay. It works. But if we wanted to modify any of the items, that is, it is something that we can redefine and reconstruct no problem. We can rebuild it, but each element we cannot change it in particular. Just like tuples. We're going to try it. If we come here and put a tuple and give it Likewise, we create another tuple. Haha machine, I screwed you. If we update, also works. So we can modify it. What about set, differences you have just with the lists, for example, is that we cannot access by the index to an element of the set. For example, if I put print set and I put 1. If I run this, it won't let me log in. That is the topic. It won't let me access the index. Then no I can access by an index. But I can show it as such. If I run and pull out the entire index, it's going to allow to show it. There is. He shows me the whole thing. In fact, an interesting feature is that it does not allow me to repeat values. If here, for example, I put soydalto. Solidalto is a repeating value. Yes, is repeated. So if I show it, it doesn't show it to me. Now, what if I also add this to it? to a common list and a tuple, right? The tuple, if we execute, shows it to me. He showed it to me twice. The list, let's see what happens, show me twice. But the set does not show it to me. Why? Because in a set it cannot have duplicate data. This is a fascinating way in Python to remove duplicates. Sometimes we have many duplicate things that we want to delete And an interesting way is, well, we create a set and then we return the set to convert to an integer. So you can iterate, yes you can iterate a set, but it cannot be accessed by an index. Not every element in the array can be accessed for an index. It is accessed in another way. To access precisely the data of a set we have to use a loop. That we will see later, but for Now understand that you can go around saying, we can understand and see what each one is of the elements, but we have to use a loop, which already we will see later. So let's put features. Elements cannot be called by their index. It does not store duplicate data. Elements are not called, are not accessed by index. There it goes. And it does not store duplicate data. Also, another feature that they are messy. I mean, it's not like they have an order. It's literally messy data. You can be there, then you can change the place. That is important for you to know. In fact, I'm going to put the same thing here. Print dupla three, which shows me to see what what is inside Set 3. Here I am going to put cannot access the element. And finally we need to see the last type of composite data. The last composite data is the dictionary. Or if it is not dict, the data dict. So we are going to give it creating a dictionary. And it is created this way. Same dictionary. For those of you who know JavaScript, it's literally a JSON. Literally. It's this file, see? Let's see, what I recommend doing is, when they will create it open the keys It also opens with keys, yes. They give him space and let him start at the top, that ends below. And then in the middle we write something apart from us I explain? And there we write. And here we simply give you a piece of information and a worth. It is literally a dictionary. For example, name, colon. But name goes with quotes. Name, colon and value. For example, Lucas Dalto. We separate by comma. Same thing up here. YouTube channel, colon, I'm Dalto. Below we put, do you like programming? Or not, he is excited, easier. He is excited, colon, true. And finally, height, 1.84. There is. Note that the data is the same. Lucas Dalto, I'm Dalto, true and 1.84. Here we are going to add one more. Duplicate data, two points, I'm Dalto. There it is, to do it right as it should do. Same thing, we separate it with a comma and it works. This is the same, it is a dictionary. Why? because the name... Notice what we call this. In a list, this that is here is this. It is literally this. Zero, one, two, three, four. Why? Because when we say show me to a list the third element, shows you the third element, which is 1.84. Or not? Well, here instead of saying, che, look, show me by number, the dictionary displays it by the associated name. In this case, instead of telling it print dictionary three, like here above that we ask for list three, we ask dictionary name. So, che, what do you have in the name value? I mean, inside your name, what do you have? This. And it's the same, only we are creating the way to call that element. So if we update it, Lucas throws me Dalto, because name is Lucas Dalto. Che, let's see, and what is the channel? Luke's channel. And it's I'm Dalto. Ah, look, and the height? 1.84. It is literally the same as the height It's item number three. So, the list, I put list, list, three, because this is what is here. List three. List three is going to be worth maquinola. But hey, let's get this out here. To boot, let's get it out. If I update this, you see? 1.85. Well, here it gives me 1.84, it tells me 1.85. Let's put 1.85. There it goes. We update. There it goes. 1.85, 1.85. Why? Because what is here, this list, the ready, it is as if we did the same as if we said. Zero, two points, this. Comma, one, colon, this. Eat, two, two. Only instead of putting this, this already the program is coming So, we are left with the list like this, without having what to walk we and defines it by default. saying zero, one. It is done automatically. Well, like this that is here, it is not done automatic. That is, like the name, we are going to take this out, that's how it changes There it goes. Like the name, it does not become automatic. In fact, if we now update, notice What does machine tell us? Cannot change because the tuples are not can modify. We did not have to uncomment this. We had to uncomment the other one, the one that says lists. Now yes, we update. And now it works for me. Now yes, this is valid. We had to put a list is the same machine. This is so that an example remains for you, nothing more. What can be changed If we update now, it tells me machine. There it goes, because the third value replaced age by machine. In fact, we're going to talk about it too. So those are the differences, right? I mean, what I was telling you, here instead of there is an index that is defined by default, we say how we want it call the element or name, for example. This doesn't have an order either, huh? Nor does it have an order, everything is ordered, only that we do as we want. The programming term for this is key, value, key, value. So, the structure of the dictionary is key, value. So, key is key, value is value. So this is technically key, value. Here what goes is exactly, sorry, here what goes is the key. I explain? This here would be the key. All of these are all key, so you understand. So when we call here, we have to call key. In, for example, a list, the key, the key, the key is 3. So automatically 1, 2, 0, 1, 2, 3. This would be 3, 2 points, this value. It's the same, only I'm explaining it more so that they understand it. If they don't understand, my advice is always the same. Retouch the video so that you understand it again, but it really is very simple. In fact, I, for example, say, look, tell me the height and also to the height, add 2. Let's see what throws us. Update, 3.85. It's perfect. Done, this works and it's 10. I want a dictionary. The structure is key, 2 points, value. And we separate with commas. It's also separated by commas, OK? If there is no comma at the beginning or end, that is to say, if the dictionary had only one key, worth, that is, a key, value, this goes without a comma. If you have more than one, it is put. There are as many commas as there are elements, minus one. If there are five items, it's four commas. Here are five elements and there is one, two, three, four commas. If there are three elements, this comma is also I delete it. And well, these are exactly the types of data Compounds in Python. This is very important because we are going to go to work throughout the course. So I hope you have understood them by now. that, as I say, they are really important. And well, these were the composite data types in Python, As I say, they are very important. So I hope you understood them because we are going to be working throughout the course. Now yes, let's go with what would be the operators arithmetic, which is something very simple, a very section easy. So let's go with what is important and we are going to use enough. So let's go see it. Well now let's see what they have been the operators. We are again another day here suffering with the temperature. It seems that I am dressed exactly the same but it's the day Next because yesterday I stayed until 5 in the morning recording and it turns out that nothing was recorded and I know He lost everything that I recorded two hours to fart, It doesn't matter. Temperature today 34 degrees. Now same It's 34 degrees back I'm, let's say, no Just kidding, I'm burning up. in fact today made 36 degrees, 37 even, if I'm not mistaken. I I burned, I burned But hey, here we are and now we are going to begin with this part of the course that I am very excited that it can be carried out. Why? Because it is the one of the operators arithmetic which are basically operators mathematicians. Simple, it's mathematical operators. We actually have an image here, this one that it's here, I found it and it can help us. operators arithmetic in Python are just these that we have here What are they? addition, subtraction, multiplication or product, division, modulus, exponent or division low or double division. Now let's see what does each one do? Let's create a new file that will be operators. Well, no folder, sorry, which is going to be operators. Just operators. And we're going to create a new file that's going to to be op-arithmetic.py. And here we are going to start with the first one and we will discuss everything. Addition and remainder, plus and minus, which are the signs, and off we go. Add, equal, let's put 10 and 5. Or not, let's go to put 12 and 5. 12 and 5. 12 plus 5 is addition, subtraction is equal to 12 minus 5. Then we have others that are, for example, multiplication and division. Then the I put multi to make it easier. Y multiplication this is used, which is the asterisk sign, the famous asterisk, bar or slash for division. then i will put and then This is the universal sign of the division, in fact. One of the things represents the fractions. The same sign as the fractions. In fact, fractions are divisions. There are people that does not know. She is studying university and not You know that if I say 3 fifths it is 3 divided 5. If I say 4 means is 4 divided by 2. So 4 means is 2 integers, because it is 4 divided by 2. There is people really don't know that and are literally graduating in engineering and you can't believe it. But well, nothing. If you just learned it It's okay, I'm not going to criticize you. Welcome to the world of discovery. And we will do. Multi equals 12 times 5. Division equals 12 divided 5. Until it is It is important to note that division returns us a float data. That is, the division us returns a float data. As much as the division gives us an integer, even though I put 12 divided 6, this is 2, it will not return an int 2. It will return a float. And now what we'll see. there we have divided by 5 as we put it before. and down Let's see what empowerment is. Empowerment, it would exponent. And the sign is this that is here. So there we put exponent equal to 12 exponent 5 is How to say 12 to the fifth. It's simple, 12 to the fifth. In this case it can be 12 squared, 12 to cube, 12 to the fourth, 12 to the fifth. In this case is to the fifth. Then we have the division short. Division low, which is basically double division. That is, as the common division only that with double, double sign. low division equals 12 bar bar 5. And then we have the rest, which is remainder or module or remainder. I tell him remainder or module y is remainder equals 12 and the percent sign 5. Let's keep them apart as we come doing it so far so that it can be to appreciate better. And if we go to the images only we have these signs that are here that are the that I showed you Let's see how it works each. Let's put print, sum. if it we run this returns 17 because 5 plus 12 equals 17. Then it shows us 17. Here we can see it the result, 17. If we tell it to show us the subtraction, we sample 7. We ask you to show us multi, it shows us 60. Ok, subtract 7 because 12 minus 5 is 7 and multiplication gives us 60 because 12 times 5 is 60. If we say division, it returns a 2.4. It is a floating data, that's why I put a data floating, because it returns a number with a comma. remember that there are no integers that have eat, that is, the dot. If it is 2 point something already is a floating data. In fact, let's see that if I here I put 6, this will tell me that it is 2, but it doesn't tell me 2. I changed it wrong. It is here 6, now yes. It is not going to tell me 2, it tells me 2.0. The result is 2, but here it is a float data and it is not 2, is 2.0. In fact, there is a function that is call type, which is to see the type of data, what for see that if I here for example tell you, to see, let's see the type of data is the same a type. If I for example I put 5, if here I show type of data, returns us what type of data it is. And here we put data, it returns type of fact. If I put type 5, for example, when i run it It tells me int, because it is an integer. I here I tell him, che, let's see, and what is this? Hello teacher, It should tell me that it is a string. Well, let's execute, str. Str means string, It's like the abbreviation. See what happens If I give you a list? Hello teacher, 52, 55, 23. I update, it should tell me, oh, ok, it's a list. Well, let's see, if you I put parentheses should tell me that it is a tuple. Done, it's a tuple. if i pass a floating data, like this, it should tell me float. I mean that if I pass division, no matter how much we give 2, because 6 divided by 2, 12 divided by 6 is 2, we says that it is a float data. But if I He passed low division, even if it is 2, notice that what will return me is an int, because low division returns an integer. So here we go to put, returns integer rounded up bottom. Why rounded down? good, because if I give it 5 here, I give it 5, instead of showing data type, we are going to show low division, What is this data that is here, it will show 12 divided divided 5, that is, the low division from 12 and 5. What we use will return us 2. And why? if it gives us 2.4, well, what it does is, if it is 2, something, what is after the comma delete it and converts to an integer, rounds it up bottom. Even if it is 2.999999, it rounds it up down, forever. That's why it's called low division, because it rounds down. and then we have the rest, rest. That the rest is simple, what does the rest is, shows us the rest. 12 divided 5 is 2 point something. Well, how much do we have left? we have plenty two. In 12 the number 5 enters twice. 5, 10. Then comes 15, but it happened to me So there are 2. From 10 to 12 there are 2. I would put here, for example, 7, the rest will be 5. Why? Because 7 in 12 only enters once. From 7 to 12 there are 5. So that, it's a rim, It's remainder, basic math. Rarely I usually use the rest myself, but sometimes I do know use more when we work with data, right? But it's not very common to use it. Is it used enough? Yes, but it's not like more common. There we have everything written down, everything clever. In fact we are going to put this up, here, there it goes And here we have, let's say, everything. Here we go to put type of data so that we are ready, kind of data. And there we more or less understand what the arithmetic operables have been. Very simple, really quite simple. Y It's good that we see them because they are the with which We are going to work a lot, right? So It's fine, I think it's good that we can understand them to go to the following, that now we have to see other types of operators, ok? and already here we're entering into concepts that have been concepts more practical, right? because everything let's see from now on, they serve us and allow us exercise. So when we try the next concepts we are going to be able, let's say, to work directly with exercises. So let's go with the section precisely of some concepts practical. In this case we will see what are the comparison operators. That is very important, very important, because it is very useful, we use it a lot and the comparison operators It helps us to compare two values, it will a return true or false and use it throughout programming, in any language even. So that we are going to see them We are going to see the operators just for comparison and they are the ones we have in screen are only six ok they are very simple we both have the same they say it is the same as the one below it is different from follows is less than is less than or equal which is greater than or is greater than or equal to this it's very simple we were in mathematics when we saw equations they agree rather what they come being the inequations because with this we do inequality with equal and with the other than we make inequations with the last four below we do nonsense inequations but it's good let's see it ok let's see it because it is very simple let's just create ourselves here inside operators another one that is operators op_comparison.py operators arithmetic, comparison operators first operator equals ok we simply compare how the operators already know we put a value before and a value after value operator value a operator b so let's start by putting let's clean the console so that it is not so ugly and let's go to say for example is the same as ok this operator of is the same as is the of two equals the first equals is assignment the prime equal we are assigning we are saying that this variable is going to be equal to but we are not comparing for compare we use two equal so we put For example 5 is the same as 6 times example and the answers no 5 is not equal that 6 then it will return false or true the comparison operators return us or true or false that is to say or true or false that's what we get back it helps us a lot for just the conditionals that we are going to see more ahead we have for example this that it is going to give us false then we are going to put in fact it is not even necessary comment because here we have is the same as and the name of the variable already says so below we are going to put it is different that it is different hence we put equal 5 is other than 6 and this will give us something else below we say look we are going to put We are going to take him out, he is the same as different from greater than greater than is simple 5 is greater than 6 then we have less than is 5 is less than 6 now let's see well that gives us each value then we have less than or equal then we put 5 better put greater or equal greater or equal 5 is greater than or equal to 6 after we have less than or equal to or equal to 5 is less than or equal to 6 and here we have the six comparison operators that grab the first value and compare it with the second the first value in all cases is 5 in all cases and the second value in all cases is 6 then so that we have a good idea how it works so let's get started let's show it print let's start with equal to if we put equal to it will tell us false why because 5 is not the same as 6 5 is different from 6 then here we put different that is going to be equal to true if this is true and false if this is not true if 5 is other than 6 because here we have this is if 5 is other than 6 this becomes in true so let's see it we execute I got confused here is different other than update is true because because 5 is not equal to 6 5 is other than 6 then this is true after we have greater than 5 is greater than 6 not 6 is bigger so it won't come back false greater if we update false why and why 5 is not greater than 6 6 is more big less than good 5 is less than 6 if 5 is smaller than 6 is smaller then if we put less than us should return true indeed it is true because 5 is less than 6 is a is a valid comparison holds after we have greater than or equal to 5 is greater than or equal to 6 well let's see it greater or the same if we execute it will not say false because 5 is less than 6 not is neither greater than or equal nor equal is less that 6 then is not greater than the same if we say che 5 is less than or equal to 6 true because it is either less than or equal is equal is not less if then it is fulfilled the condition is has to be or less or has that it would be the same if we put here a 5 would still tell us true but if here only this was less than already now it tells us that it is false because it is not minor would be the same in this minor case the same there are all the values ​​like this simple works as simple as really is very simple in fact here we can make simple easy operations like example, notice that now suddenly I'm going to do an exercise let's put combined calculations we will not say that a is equal to 25 b is let's make a smaller number a is equal to 5 b is equal to 10 c is equal to 20 times example we say result is equal to for comparison comparison is going to be equal to plus b are equal that we are going to that returns us we are going to put comparison to how much is 5 b how much is 10 so this gives 15 15 is not equal to 20 then it will not return false che this is less is less than 20 this is 5 this is 10 this then is 15 and this is 20 everything has to do with what is true minor we are going to see effectively tells us that is smaller and so we can do many things ok in the future we will see examples and practical uses that we can give the comparison operators since we use them a lot believe me they are one of the most used operators not in all programming only in python but in programming in general although minor the same are also widely used but the most used of all is this since no define compare checks if two values ​​are the same for example there is a user registered our platform not a user registered our platform So we say look, let's compare the names ok then we have user for example we are going to put here compare users then we put database user for example is the same a lucas dalto this is not the user of database is this so let's go say user written user lucas so here I go ask him what to look, let's see, I'm going to tell you ask the user who wrote why I now put a text field and someone puts to see tell me what is your user and my username is lucas good yes That's your username. I'll let you in. Let's see. same database user desktop user to see if they match if they match jewel is over let's do another thing we are going to put stored password the stored password will being dalto maestro is going to be the password stored dalto master and here we are going to put password password written the password written I wrote Lucas let's see let's ask him password stored is equal the written password let's see fake me says false so we don't leave it pass if the password typed false us let's see let's see the user of suddenly typed the correct password good wrote dalto teacher wrote dalto teacher ok now it tells me that it matches Because, why dalto master is equal to dalto master and if I write it with other quotes with single quotes for example the result the same result and if I write with triple single quotes come on Let's see, he's going to give me the result does not change the way we believe the string what matters is that is a string a text string is a text then the texts we can compare and the stored password is valid is equal to the password simple written we were able to validate it then then with something called conditionals that is exactly what we are going let's see now we will be able to act consequently because we are going to go look if this condition is met if this is true then we generate a code if it is false we generate another code are like conditions two possibilities so Let's see what the conditionals are, let's go to that section Well, let's start with the section on conditionals. This is one of my favorite sections because here we notice a progress, ok? We are going to be able to notice a breakthrough and like it. I like it because to start and do things interesting with python we have to see yes or yes the conditionals, because they are everywhere. So let's see what a conditional is. I am going to explain to you very quickly what is a conditional in a voiceover. Well, conditionals are basically bits and pieces. of code that tell us, hey, look, if this is true, this code will be going to run If this is false, it will not be executed. It's just that. In addition, we have the possibility to tell you, look, if this condition is not met, that is, that is, if the bit above is false or fake we are not going to execute the above code, Let's run the code below. These are the if and the else. If this condition is true, we execute this code. Else, that is, otherwise, in case that this condition is false, We run this other code. For example, if age is greater than or equal to 18, we are going to tell him, you are of legal age Else, we are going to tell him, you are a minor. And this, in a nutshell, is simple. We are saying, che, look, if you are older At 18, you are of legal age. If this condition is not met, it is because basically not greater than or equal to 18, that is, you are under 18 years of age. So we tell him, you're a minor. That simple is the explanation of a conditional. Let's see how it works in code. Let's come here and put a new folder which is going to be conditional. Let's create a folder with ifElse.py, because they are the first two conditions that we'll see. There are several, but these are the first two. Actually there are three, but let's start with this. the code is the following. If, condition, colon, action. If, condition, action. This is the structure of a conditional. A conditional works like this. If, condition, action. If this here is true, for example, 2==2, They saw that the comparison operators this is returned to us, for example, as true. This would be true. Now, if I tell it this, it returns false, because two is not greater than two. So this action is not executed. So ultimately, if this is true, the action is executed. Action is executed. Now, if false, let's capitalize it. If this is false, the action is not executed. It is so. If this is true, this entire block that is here, this, this, this, this, all those who are here are going to be executed. If it is false, it will not be executed. How can we make this useful? Well, plain. For example, let's create a variable that be age. Age equal 17. And we say, look, if older. I killed a super mosquito with one blow. If the age is greater than or equal to 18 years, we say print, you can come in, okay? So, let's check it out. Let's see, we execute it, f5, and it tells us, we don't He says nothing, because he is not of legal age. If we put 19 on it, it tells us, you can pass, because indeed, 19 is greater than or equal to 18. If we put 25, 25 is greater than or equal to 18, He also tells us, you can come in. But if we put that he is 9 years old, we don't say nothing. But how do we do? Che, look, let's see, if we put 18 on it, How we do? Che, look, let's see, how can we act if the code is not met? Well, now we are going to say, if we put it Here we are doing it wrong. We gotta get off the block, 'cause remember that this is a language indented. If we're writing code in here, everything we write here inside It's part of Python, see? It is part of the condition. So if I run it, see? It is not fulfilled. But if now I put 19, for example, it throws me. You can pass, it's part of Python, because this that is here, It is part of the conditional. If we want to get out of the condition, we have than go down the block, which is here, go to another level below the table, that is, here. Here we put else, a colon, and here we put no print you can't pass. So, let's check if it works. You can pass, because he is 19. Let's see, if he's 16 years old, you can't pass. Why? Because he is underage. So basically this works like this. If the age is greater than or equal to 18, we say you can pass If not, we tell him you can't pass. Everything that is in here is part of the if. Everything that is inside the else, is part of the else. If we put it out here, here it no longer forms part. Print is not part of any condition. If we run this, we'll see that you can't happen, is part of the else, is not part of any condition. Why? Because what is here is going to be executed whatever happens. In fact, if I, for example, take this out and this, see? And update. This here is executed no matter what, because it is out of all conditions. If I put him here, that he is 30 years old, now not It will say that you cannot pass. We update, see? you can pass But the one below runs the same. That is, it depends on this condition, it will run. Either this or this, one of the two. If it doesn't run this one, run this one. If we remove the else, it executes this or none. But if we want to do something otherwise, we put an else. The else is for that. For example, I give you an example. Here we do what we wanted to do before, not? What is? If, for example, the password, right? Password, let's copy the variables that we had in comparison operators. Let's copy this. And we are going to paste it in the else if, here. Password stored, password written. So, here we can make the comparison. If the stored password is the same as the written password, We are going to tell you by logging in. And voila, start the session. If not, we will tell you wrong password. Try again. Let's check it out. We come here and it tells us logging in. Why? Because they match. I gave him the same password that he was stored in the database, for example. Because what is here is what we wrote us. But in the future the ideal is to connect it to a database and extract the data that is hosted. Because we are going to give the user the option what I know register, write your data, that those data is recorded in the database and then compare them. Che. Let's see, he registered me a password that is this, right? That we removed it from the database. What you are writing to me matches the password that I register. If it matches, we let it go by logging in. And there we created a whole process to start session and actually make it work. And if not, if it doesn't match, we tell you the password wrong. Let's see, let's put anything else. Put that I screwed up for a letter. I was wrong with a letter. We updated and wrong password. Try again. Well, I try again. dalto naestro, that's it, but I messed up on one capital letter. It doesn't let me through either because it's key sensitive, It is case sensitive. If you're wrong, try again. Well, I try and put master with M. Done, logging in. It no longer works. Perfect. Now we are going to create another file that calls elseif.py. The elseif is another extra condition. For example, if I say here, look, if we go to put, Let's create a variable that is. Let's say silver equals $10,000. There is. Or silver 100,000 dollars. $100,000 per month. Let's call it monthly income, right? If your monthly income is $100,000, We are going to create a little program that is. If monthly income is the same, no, it is higher at 1,000 dollars, we are going to tell you print you are financially well in Latin America. But suppose now I want to create another thing, right? I'm going to put another if. If monthly income is greater than $10,000, let's put print you're fine anywhere part of the world. And otherwise, in case it is not fulfilled nothing of this, print you are poor, for example. Well, let's see if it works. We run it and it throws an error. The error is because I did not put the colon here. Okay, we update back, we run. And he tells us, you are financially well off and you're good at Any part of the world. It's okay, but if I suddenly wanted to tell me just one thing, because I don't want you to tell me you're well financially in Latin America and you are fine anywhere part of the world. I want you to tell me one specific thing. Because if I suddenly put here, for example, 5,000 dollars, What's up? With 5,000 dollars I am financially well, but not well anywhere in the world. So I update. Are you doing well financially in Latin America? you are poor, But how are the 5,000 dollars going? Well, for this we use the else if. If. If monthly income is greater than $10,000, we put it up, you're fine at any part of the world. You are fine anywhere in the world. And it is that we put else if, that is, otherwise, 1,000 dollars. Monthly income is not $10,000 per month. Well, let's see if the monthly income is of 1,000 dollars per month. In case it is 1,000 dollars per month, we tell him, you are fine in Latin America. In case you're not okay anywhere, there we do tell him, you are poor. We update. We have an error, because the problem is what else if in Python is not written like that. It is spelled elif. Else if is written as elif. What does elseif mean? That is, if the first condition is not met, we don't go to the else. Let's give it a second condition. Well, let's see, if the monthly income is not 10,000, it's 5,000, we are not going to tell him that he is poor. Let's see if he has more than $1,000. It's okay, 10,000 does not reach. Let's see if it reaches 1,000.
If it reaches 1,000, we tell you, you are in Latin America. And if it does not reach 1,000, then we do tell you, you are poor So, we update. You are fine in Latin America. Good. If you have 500 dollars a month, you are poor. OKAY. If you have $12,000 a month, you're fine. in any part of the world. Why? Because here first he asks me, income monthly is greater than 10,000? In case it is greater than 10,000, we execute this and this does not run. Neither of the two. second condition, which is this. And if this is true, run this. But this doesn't run it. Now, if this condition is not met and this condition neither is fulfilled, just then we execute the else. And the if, we can put many. For example, we are going to come here and we are going to put, I don't know, for example, you are fine in Latin America. We are going to put 500 dollars and here we go put, you're good at Argentina. And we're going to come down here and put the same, but with 200 dollars and say, you're good at, what do I know I, Venezuela, for example. I understand that with 100 dollars, better one is fine. So, we come here, update. It's not that it's right, but within everything one is fine. We update and there we can see, okay anywhere of the world. Let's see, let's see if with 1,000 dollars, what does it tell us? With 900 dollars. With 900 dollars it should tell us, It's fine in Argentina. Good. Yeah, because we didn't get to $1,000, but we have more than 500. If we have more than 500, we are fine in Argentina. Let's see, suddenly, if we have 300 dollars and with 300 dollars, you are fine in Venezuela. And with 90 dollars per month, what do I do? And you are poor. Good perfect. I am poor with 90 dollars per month. This is how else IFs work. This way we work with conditionals and it is very useful and We are going to see it now in practical cases that let's go to work later. Conceptually, there is something called IFs nested, which is an IF inside another IF. That we also do it a lot, that of putting an IF inside another IF, but hey, we'll see when we have to work them. Assuming we had to meet two conditions to At the same time, we can use a nested IF, which is what I just told you, which is to put an IF inside another IF, for example. If monthly income is greater than $10,000, but also the expenses are less than 5,000 Dollars, for example, or less than $7,000, we will We say, you're fine. And if we don't tell you otherwise, then we say, IF the monthly expense is less than 7,000 dollars, That's where we tell him it's okay. I explain? There we say, for example, print, now yes, you're fine. We are going to put the else, the else here, because if we put it down the else, ya is the else of this IF, not of this one. If we put it at the same hierarchical level, along the same lines, is the else of this. If we put it here, it's the else of this. That is, the other else IFs would never be executed, Let's say. In fact, notice that if I pull it back, I throw an error, because this is incorrect. Why else IFs can't go after an else, they can only go after an else. So now yes, I tell you, in case not work, I tell him print and pa, you are spending a band, a band. You have to see if it reaches you. F5 and now he tells me, you are poor. If I, for example, give you $8,000 per month and I tell him that the monthly expense is 2000 dollars per month, let's put it, he earns 12000 dollars per month and spend 2000. Well, he's going to tell me, now yes, you're fine. Now, but spend $8000 per month. And pa, you are spending a band, you have to see if it reaches you But if the guy earns $70,000 per month, he's going to tell him, you're wasting a band, you have to see if it reaches you. Yes, you are spending $8,000, but you are earning 72000. So there is an error. Instead of putting monthly expense, we are going to put monthly return. That is, IF monthly income minus monthly expenses is greater than $3,000. In other words, if the difference between what you receive and what he spends is 3000 dollars, We tell him, now yes, you're fine. So now yes, he tells me, now yes, you are all right. If the guy spends $80,000 per month and he's going to tell me, and you are spending a band, you have to see if It reaches you. That's more or less where we catch it. I explain? This is more or less how it works. In fact, we can make a condition that if the guy spends more than he earns, is in deficit. How do we do it? Simple, here we tell you, if the expense is lower, that is, if monthly income minus monthly expenses is less than zero We are going to tell him, you are in deficit. Here we are going to put an else if. The if monthly income minus monthly expense is greater than or equal. No, greater than zero. The same, you are spending a band, you have to see if it reaches you. Here it is. And in the else we say, no, easier, we ask if it is greater than $3000. We tell him, fine, pa, you're fine, fine, pa, you are well. And if not now we tell you what to see if it reaches you Why? If the monthly income minus the monthly expense is less than zero It means that, let's see, if you win 72 thousand and we subtract what you spend, is at 8 thousand dollars of loss. So we tell him, you are in deficit. And he tells us, you are in deficit. OK, but if suddenly I happened to win 72 thousand at 92 thousand dollars per month, and you're fine, pa, you're fine. And if now I spend, I earn 81 thousand and I spend 80 thousand, and he tells me IPA, you are giving a band, there is to see if it reaches you. Here we have a well-worked program. Let's leave it as an example to move with if and else if. In fact, this is an example of else if e if nested. Let's put nested if and else if elif. Remember that it is always elif. In fact, we are going to change the name and instead to put elif, Now we do know it, we are going to put elif. Then we have other operators that are the comparison operators. OK, this is important because we compare and if we wanted to put two conditions, For example, we can do it. Since we can do in many conditions, we can do as combined calculations, let's say, but seriously combined calculations. Because it was what I was going to do here when I put comparison operators. They saw that I put combined calculations and was going to do that here. But no, we are going to do it now in the operators... logical. The famous logical operators that are or, and not. Those three, simple, or, and and not. There are more, but for now let's look at those three that are the most common. What are the singles, huh, so let's go to see them. Well now if we are going to start to see what are the logical operators, for that we go to give in operators Let's give it new file, here we go to put logicalOperators.py And here we are going to work them There are three logical operators, which is AND, we have another that is OR and we have another that is NOT AND is an operator that compares one and the other. Well here I am going to put a little table for let's see, all one by one Let's put result 1, let's put result 2, 3, 4, let's put 5, 6, 7, 8, 9 and 10 There it goes, let's run one by one, print, result In the first case, note that we pass true and true If the first value is true and the second is true, will return true Well, so far everything is fine, he tells us true, perfect Now, the second result, let's see, result 2, according to this it will return us false Why? Because false and true, for more that one of the two conditions that we pass be true The same AND has to be both true, so if we update it returns false Same with result 3, result 3, result, I put, ah, ok, result 2, there, now yes, all right And now it should work, result 3 we had put, let's see now yes, false, good, because This is false Result 4, this is false, so we can see for the AND operator, which is this that is here, this sign It returns true, the two conditions, that is, the value A and the value B that we pass to it, both have to be true As long as one of the two is false, it already returns us all fake We are going to try the OR, we are going to start, result 5, which is this one here The first one returns us true, well, let's go Let's see with the second, what happens if we pass it one true and one false It also returns true, let's see what What happens if we go through the same thing but in reverse, different positions Ok, it also returns true, and now what happens if we pass him the two false data, if we pass the two false ones, it returns us false That is, in one of three cases, in one of four cases returned false, what does it mean that? That the OR operator, which is this sign that is here, it will only return false if the two conditions are not met That is, it is like the opposite of AND, AND we returns true if both are true, else not OR returns false only if neither It is fulfilled, it is like the other extreme, right? OR is either one condition or the other, it's easy, will only return false when both they are fake, it's simple Che, the first condition that happens to me, is it true? No, huh? And the other? If then we return true As long as one of the two conditions is met, it returns us all true Now, if the two are not fulfilled, there we return false And then we have NOT, which is one of negation, which basically inverts us the value If we give it a value of true, it converts it to false, if we give it a false value, it converts it in true That is, if we pass true, it gives us false, yes we pass it false, it gives us true That's why for you you have such an intuitive language and at a high level, because we say NOT TRUE and if it's not true then it's false That is, it is false, NOT FALSE, that is, if not is false is true, that is, it is true So let's see, result 9 returns us false, because if it is not true it is false And we are going to try with result 10, result 10, true, it is not false, it is true In other words, if we suddenly happen to him, for example a value that is, I don't know, let's see, 2 is the same to 2, this is true 2 equals 2 is true, because 2 equals to 2, so if we tell him, let's see, tell me 2 equals 2, NOT 2 equals 2, to see that returns us And it returns false, because 2 if equal to 2, then this becomes true, and this is going to invert the value That is, if we pass true it gives us false, if we pass it false it gives us true Now, what if I tell you 2 is greater than 29 for example, 2 is greater than 49, this is false But if this is false and we have a NOT ahead, NOT FALSE is true, so technically will return true Because this is false and this gives us back what contrary to what we return here, so that we are going to put true so that they fit time And nothing else, I challenge you to play With this, everything we are doing I recommend that you write code Don't leave me alone, you download yourselves, for something I unloaded with you until the code editor Download the code editor, program with me, do the same exercises, every time you finish an exercise put pause the video and play for a while Play, try, grab, trade numbers of place, if something has an error, look for it, search in Google, that everything will be in Google, they will find everything Try, play a little, until you find logic, because that's the way they are going to learn You learn to program by programming, and here we are with the code, yes I are at the dance, let's dance So I'm teaching you something, learn and write it down, code it up, play it a little bit, figure them out so that even with what we learned now they can do things For what, and that is my advice, so that everything what we see so far stays with them Because if you see things only one time, according to science the possibility that remember it is 10%, the possibility that they forget it is 90% And if you review what you see for a little while after they saw it, they review it up to date next and review it a week later And then they review it a month later, most likely they will never forget, is most likely What does it mean? What if all you they go over it after a while, do exercises and put it into practice, they have double or triple the possibility of not forgetting it That is why it is so important to put into practice because if your chances of remembering they are 1 of all, when they put it into practice they are 2 or 3, which is a lot So that's why my advice is, until this point of the video pause and start to play a bit with your code editor, okay? If you already did, I congratulate you, you are done ready to continue with the following, with the next concept, which is precisely the theme of the methods In this case we are going to see string methods, of the strings, let's see what a method is and why chains, etc. But we're going to get into everything, so let's go with the next section Well, now we are going to see exactly the methods of chains. Methods are these functions that we use fairly applied to what has been an object. As I told you, in Python most things can be considered objects. So if we, for example, a variable, a text is an object. An array, sorry, a list, is an object. So, when we talk about methods, methods are functions applied to objects. One function is, for example, print. Functions have this structure, they have function name, function name, they are followed by parentheses and inside sometimes we can give them parameters, which is how the function will receive to convert or do things with it. So, in this case we have the function print, what it does is shows us on the screen what we are going through. Then we have the type function, too, for example, that what it does precisely is give us back the value we give it. If I give it a 5, check what kind of number it is and returns it to us. If I give it a 15, it tells us what number is. This, for example, returns the float. This returns us a string. This too. So, what it does is verify the data that we give him and he tells us what he does. Functions have that purpose, right? They analyze pieces of code that we we give to give back or do things with them. So, the text strings have their own methods, their own functions. So what we're going to do now is see what are the functions that python gives us default to do with the chains. What things can we do with a text, for example So let's come create a new folder and we are going to put, not in here, but outside of everything. The new folder will be called methods. Easier, methods. And in here we are going to put, now yes, new file and here yes, methods-cadenas.py. Here we create the file. I'm going to close the others if we do not intervene. And basically we're going to play around with it a little bit. What are the chains? Let's put string 1. It will have, for example, a text. Hi, I'm Dalt. Chain 2. It will have, for example, another text that is welcome, machine. those two texts. I am going to play with these two texts. Well, for starters, what we are going to do is to be see the different methods that exist. Here I put together a notepad with some what are we gonna see. There are many more, but these are some that they are interesting. The first, if you like, is one that allows us see all the things we can. Returns all the attributes of an object. So if I'm going to pluck and put, dir chain 1 and update, here this is what will return me if it is fixed when you run it. Let's run it. It doesn't give us anything back. Why? Because dir runs something and it's a loose value. If we want to show on the screen what we are doing, we have to wrap it in a print. Print. And now we are going to see what it does. Now we do update and here it tells us, look what did this give us This that he gives us here, this that he gave us back. We're just going to go up. This that he returned to us are all things What can we do with this. We can give you dir, we can give you ends with, encode, is digit, lower, join. Let's say, we can remove prefixes. There's a lot of things we can do with this, precisely with this object that we pass. If I, for example, put a number, I put 4, any number, it gives me other kinds of things. They are similar, but they are different kinds of things. Why? Because they are just different data. We can make a number behave like form, we can operate it in a different way than The texts. In fact, if I want a list, for example, I'll give you a list with anything and update, notice that now he gives us something else. Because lists have other methods of their own. What we are going to see now are precisely the methods and the properties, the things we can do with a text. In this case, string 1. So let's check and see what's up. We are going to try the different methods. Ok, let's get results. Result and it will be the same as everything we do. If we put the same result here, dir. Chain 1. If I show the result here, for example, prints, result and run it, we have the same thing. So what happens here we will store it here. We are going to go then removing that with the first method that we are going to see. What it does is converts all uppercase. If we put upper here, what this chain does, that in fact the strings go with the beginning capital letter, This is exactly what it does is convert me this data to a capital letter. If I update now, they see that I have a error. I mean, it won't be working. Why is this? Well, this is because the methods normally We don't work them this way. Methods in Python are followed by. That is, dir, for example, was not a method, was a function, is a Python function. To be considered a method, it has to be executed as follows. And it is to put chain 1, point, upper. Now what we do is execute a method of this chain. So if I come and update it, let's go to execute it, is going to return HolaSoyAlto. What he did was he took this text and turned it uppercase A. In fact, I could directly do this. Hi, let me show you how you're doing. Notice that all this is going to do is if we tell him to pass it on to us, It's the same, but I capitalize it. This is how the methods work. The methods are the data, point, the name of the method and the parentheses. This is the structure of the way in which works. Data, point, method and parentheses. In case of putting some parameter, we will have what to put it We are going to see when to use parameters and when do not. But there we just made a function of this form. Chain 1. we are what you have in here, turning it to uppercase. Everything is converted to uppercase. Just as we have the function upper or upper, which is how to convert to uppercase, we have the lower, which is to convert to lower case. So, if I come here and put him in place from upper, I put lower, if I update. Now I'm going to convert everything to lowercase. Notice that I had the H and the D with capital letter. And now I already converted it to lower case. Why? Because the lower converts to lowercase. So let's leave it noticing everything. We're going to come here and put this like this. Let's capitalize, convert to uppercase. In this way we convert to uppercase. Let's put upper. Now yes. Let's copy and paste. And we are going to do the same and put converts to lowercase. And instead of upper, put lower. So there we have written down well what it is what's happening. Here it is finished. Let's do a little smaller. There we are. Better. So here we convert to uppercase and here we convert to lowercase. There it goes. Then we have another one which is just another type of text that is to convert. We do not convert all uppercase or all lowercase. We convert only the first letter to uppercase. First letter capitalized. So we put First capital letter. Same. Chain one. Point. Capitalize. And here if we update it and tell you. Let's see, show me this. First capital letter. Let's see what it shows us. Tells us. Hello, I'm Dalto. If I, for example, put any other stuff and I put the H in lower case, for example, or I take that out, I update it, it converts it to me uppercase A. And it not only converts the first to a capital letter, but what it does is First he acts as if he were a lower. Converts everything to lowercase. And then it takes the first letter and converts it uppercase A. Because notice that Dalto was capitalized. And here he left it in lower case. So what it does is first convert all lowercase and then in the first letter leaves it to capital letter. This is how this chain works, let's say. Let's see, I put the text as it was before. Then we have another method that already here we do something else Here we are already returning other types of values. Returning a value means giving us back. Because when we execute a function, that is, we execute a function and what we execute returns something to us. That is, lowercase, this variable becomes in suddenly this. Saying this and saying this is the same. Because this, what is going to return to us is this. So to return a value is to return us a value. The function, the total of the function, the total of this code It's like it gives us something back. That which returns us is the result that damage? It is like the result of the execution. So in this case we are going to leave it as was before. What we do with this other one that is precisely find is to look for a value that we ask for. For example, we search for a string in another string. It is simple. We'll see. search find. search find is going to be equal to string1 point find. And here we are going to say, for example, we want search hello. We want to see if in this text string we find the string hello. Search find and here it will return zero. Why did it return me zero? Because it returns me the position in which find what we ask for. Let's see, find me the letter A. Where will you find the letter A? And look, I find it in position three. Why? Cause this is like it was, As I told you, it's an object. It does not stop being an object, an arrangement or the you want. So you have positions. A text string is a set of characters. This is the one, two, three, four. But how is the four? If A is in fourth place, why? give me back the three? And because, as I told you before, on the lists we counted from zebra one. An array is counted from zero onwards. We do not start counting from one, we start to count from zero. So this value is not one, it is zero. If this is zero, this is one. If this is one, this is two. If this is two, this is three. So we have zero, one, two, three. It's true, the position you're in the letter we told you is in the three. The third position. So it actually works that way for us. form. Let's see, where do we find an S? In what position do we have an S? Well, in position five. Zero one two three four five. Effectively. Let's see if you can find me a D. Let's check it out. Oops, it gave us back minus one. There is no less one. There's no way it's minus one. What happens is that here it returns us less one when one finds a value. Because remember that Python is sensitive to upper case and lower case. It's just key sensitive. So here we put a capital D. If we had put a capital D we would I would have said it was in position nine. Zero, one, two, three, four, five, six, seven eight nine. Yes, because spaces count too like numbers. This is also a space. This does exist. It exists and is one more character. Then it counts. Zero, one, two, three, four, five, six, seven eight nine. It's okay. Meet the condition. If we say the small D it shows us minus one. But then why does it show us less one? Well, because minus one is the value that we returns when it doesn't find something. Because since there is no position minus one, that's what it would be, shall we say, returning in case you don't find anything. If it finds nothing, it returns us minus one. So we put Search for a string in another string. If there are no results or matches, if not there are matches, it returns minus one. Then we have another function that is the same. The difference is that it is index. We look for a string in another string. Search, index and equals. Chain one, index point. If we pass the D, for example, the capital D, let's put search index. This is going to give us back nine. It's okay. It works exactly the same. We pass him the A, he's going to give us three back. Ready. It's working the same. Zero one two three. Works. Ready. I mean, it's obviously fine. But then, what is it made for? find or index function if they work the same? Well, the difference is that in one, if not finds nothing, returns minus one. But in another, if you don't find anything, let's go to put a nine, for example. We don't have any nine here, so we should return an error. As for example here, in the small D. Let's put the lowercase D. It throws us an error. Throws us an exception. Later we will see what are the exceptions and how to handle them. Because in the future we have to learn to handle exceptions so that in case of that throws an error in the middle of the program, we know how to handle them and know what to do with the program so it doesn't get stuck. Because if not, if there is an exception, the program it gets stuck there and doesn't go any further. And that can't happen. So we have to learn to manage them. Well, in the future we are going to learn how to do. But precisely the difference between find and index is that index, in case of not finding a coincidence throws an exception. So let's add it. If there are no matches, throw an exception. And there we have this that is important. So it's good to keep that in mind. So let's give it D and lowercase D. So there yes, if you pay attention, if we update and we run the code, nine. It actually works. Then here I noticed another function. If you notice, I'm separating them. The first is a function. It's not a method, it's a function. That is, method and function are not the same. Because all methods are functions, but not all functions are methods. Precisely, because the methods are functions object specific. If it is not a function of an object, it is not a method. We put dir data. We do not put data point dir. So it's not a method, it's a function. Let's see later which ones... When we work with oriented programming to objects, let's understand it well. Because we will be able to create objects. And when we create an object to that object, we go to be able to apply its own functions object. For example, a dog can bark. But we can't say what to bark if there isn't a dog. We cannot tell the program to bark. Nerd. It has to be an applied function to an object. So there we can say barking. I explain. We will see it later when we go to object-oriented programming. But let them know that a method is a function applied to an object. Nothing more. And here what I am doing, I am separating methods by different types of methods. These methods precisely make us the value. These methods search for a value. These methods query something else. That is, they also return data to us. But they just ask us if they are numerical or alphanumeric. These here are doing something else, let's go Let's see. And those who are here do other things that we are going to see together with these that are here. So we're going to stick with these. This is simple. IsNumeric is a function that allows us to see that if it is numeric it returns true. Easy. If it is numeric, we return true. If not, we return false. It is numeric. And here we put chain1 point isNumeric. And there we execute the code. If it is numeric, we will return true. Let's check it out. Let's see. Is it numeric? Let's remember it and see what it tells us. False. What happens if I suddenly put numbers on it? We'll see. I threw numbers at them. They are just numbers. I run back. Well, here I throw an exception. We are just going to put some number to see if you find it. I throw an exception for this reason. There it goes, now yes. We use it and... Well, no. There is just no 1. We are going to put a 5 that we know there are 5. Now yes. True. It returns true. Why? Because it is numerical value. Even if it's a text, this is crazy. It is a text, not a numeric value. For it to be a numeric value, it has to be this. But what isnumeric does is check if it's a number. Because let's see, yes, it's okay. It is a text that has only numbers. Well then let's check it out. isnumeric. If it is numeric, it will return true. Now let's check if it is alphanumeric. If it is alphanumeric, we return true. If not, we return false. Is alphanumeric equals string dot is alpha. And there we run it. Let's check it out. Why are you pulling us? Is it alphanumeric? It tells us that it is false. Why is it not alphanumeric? Is it numeric? Not alphanumeric. So let's add a letter to it now. Let's see. Let's add as. Let's run back. It tells us that it is false. Let's see testing with any other text. And yes, period. And a special character. Let's see now. Let's see what throws us. We update. It tells us that it is false. Ready. It tells us that it is false, that it is false. It's perfect. Is working. Now let's see if we can get the numbers out of it. Let's see. Let's run it. Well. There is always a problem. Let's put the F. That we know that he has it. There it goes. We run it back. False. Why don't you say it's fake? Because we have special characters. Let's try with just one text. Hi machine, I'm Dalto. Let's get the comma out of it. Hi machine, I'm Dalto. Let's see now if it tells me that it is alphanumeric. Let's check it out. Well. We are going to put it because we know that there is one A. We update back. False. The issue with this is that they are only valid characters from A to Z. A, B, C, D, E, F, G, H, up to Z. The letters of the alphabet. The space is not alphanumeric. So we have to get it out. Let's see what happens if we remove the spaces. Well. We remove the spaces. We update again. And now it tells us that it is true. Because spaces are not alphanumeric characters. They are special characters. Special characters are, for example, space, slash, periods, commas, etc. So only if it is alphanumeric, this condition it will give us back This method will return true. This property is interesting. So nothing. To take into account. Then we have count. What count does is return the number to us of occurrences of a substring in the string Dadaist. The same as before. Instead of finding a match, we tells how many times a match was found. Up here, for example, come. We look for a string in another string. If there are no matches, it returns 1. Ok, let's copy and paste. The difference is that we search for a string in another string. Returns the number of times it matches. If I, for example, put, count matches. Easier. Count matches. String 1, point, count. And here inside I have to give you a piece of information. Right now I have to ask you what it is what we are going to look for Well, let's find the letter A. How many times is the letter A? We'll see. Count matches. We run it. Four. Ok, the letter A is there 4 times. We'll see. 1, 2, 3, 4. Indeed, it is 4 times. Let's look to see how many times it is the D. For example, the capital D. Once. Indeed, it is only once. And to see the small D that throws us when it will throw an error. Let's see what throws us if it is not found. And if it is not found, it tells us that it is zero. Why? Because it is zero times. Count the number of times that there is what we pass it here, up here. I could calmly put now, hello. As is well. And he is going to tell me that he is once. Because so the text as it is, hello, in this order is here Once. But if I put hello machine. Hi, I'm Dalt. When I update. Now he's going to tell me that he found himself twice. Because this text, hello, is over and over again time. Even if I put, for example, mine. I should throw myself like once upon a time, right? Let's see, let's check. The MA. Because here is the machine. Hello, finish with the. And machine starts with ma. So it doesn't work there, right? The MA. Let's see if it works. We update. And it tells us that zero. Now, if we put it together. We update. And tells us that one. Because mine is all together. If we separate It tells us that now there are no matches back. If we separate it again here. We update. There is a match. Because this is a text as is. With special characters included. All text as is. It has to be somewhere in this chain. Then we have Len. Which also counts. But what Len. It is the number of characters that a string. So let's check it out. Bring back. Let's change the definition to this. Because it's better. We count the matches of a string. Inside another string. Returns the number of matches. There it goes. Now yes. It is much better. We count matches of a string. Inside another string. Returns the number of matches. Perfect. Now yes. And here in the second. What is the method Len. We count how many characters a string has. So we put Count characters equal string one point Len. This Leon is widely used. In matrices too. We are going to see how we use it in matrices. Now we put for example. Count characters. We update. And there we actually see that he has us a error. Why do we have an error? Good. Because Len is not a method. Len is a function. So we have to put Len. String. String. One. So now it's working. We update it. We see if it runs. And now it works. It doesn't say that string one has 27 characters. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27. It actually has 27 characters. Okay? Easy to count. If I suddenly stop this. It is going to tell me that it has only 3 characters. Well. We update. Okay. Let's put the H. We update and it tells us that it has 3. He actually has 3. If we leave we only put hello. Let's see how much he has. We update. It tells us 4. So it works. What Leon does. The Len function. It tells us how many characters a string. Then we have two that are very interesting. What are ends with and starts with. These are already methods too. And they are also to verify. So we come here and put. We check if a method starts... If a chain Start with another given string. If so. Bring back. True. Starts. With. Is equal to. Chain 1. starts with Here we ask. Let's see. This string starts with H. For example. And indeed if it starts with. We should return true. And it effects. It starts with H. Che. Starts with. EITHER. It returns true. Starts with. Hello. It returns true. Che. Now. Starts with. lowercase h. It returns false. It starts like this with h. capital H. capital I. Not. It's false. Because it starts with a lowercase H. Forgiveness. With a capital H. I lowercase. Then. What it does is verify. Let the chain begin with what we pass on to it here. It's very interesting. This, for example, will return true. Not? It starts with H. There it goes. And then the same. Let's copy and paste. Why? Because instead of starting we put. Starts. Ends. And here we are also going to change it. Ends. And here instead of putting starts. We replace start. by end. There we have ends. With. We check that the string ends with. Let's check it out. Let's put an end Ends with. Chain. It ends with H. Not. Ends with. Let's see what it ends up with. With the. Well. It ends with a. Effectively. Hello. End with the. Or not. End with the. Well. Let's check it out. It ends with the? Yes. End with the. Ends with. Hello? Yes. Ends with. Hello. Effectively. It ends with the H? Not. It starts with H. This is how this method works. And then we have these two that are already more interesting. Okay. We have. The first replaces us with a value. If I, for example, have this string that says. Hello. Let's replace it. Replaces a piece of the given string For another given So we say for example. New chain. Oh yeah. New chain. It will be equal to Chain one. Point. replace. And here. Here are two parameters. The first parameter. Is he. Ancient. That is to say. Let's replace. The. Let's replace for example the. For. Lu. instead of hello Let's replace it with. hello. That is to say. End with the. And this the. We are going to turn it into a . Lu. Let's see if it works. Let's tell him to show us. hello Effectively. Instead of replacing Hello. Now I want to replace the entire string. Instead of replacing hello Machine. Let's see what's up. hello Machine. And now we are going to replace. Hello with a small H. See what happens. Nothing happens. Returns the previous string. Why? Because if you find a match. This is so. If you find. A coincidence. In the chain that we pass to him. That coincidence is going to replace it. For what we happen here. In case you can't find. coincidences. It will return the previous string. If the value 1 is found in the original string. Replaces the value 1 of it. For the value 2. That is to say. If this value We found it. In the original string. That is to say. If this value We found it. In the original string. Replaces. This. Inside this chain. For this. If I for example I would tell him. that replace This. This will find me. It's here. Then you will find it. There is a match. What are you going to do. He's going to replace me. Where do you find this? He's going to delete it. Then. What I would do would be Hey look. This is going to replace it. For. What is here Then. I would replace it. For this. And this is how the string would look. Let's check it out. Let's see what happens. Let's update it. And let's see. Effectively. This is what it gives us. It basically replaces A chain. For other. For serving us. Well. If I put you Hello. Machine. What. These. I have. All words separated by commas. What I can do. I have spaces. A whole chain. Which is made with spaces. When we want to see the new string. We have the string without spaces. And now for example. To new chain. String. New. Two. We are going to convert it. Only for the first letter. Have a capital letter. New chain. Two. It will be equal to New chain. Point. Capitalize. Capitalize. And there if they look. Here it is all capital letter. Well. Let's run the code now. And now only. Oops. What happened there. Well we are showing new chain. Let's show new string. He showed us. The string with all caps. At the beginning of each letter. And now as we gave him capitalize. to the new chain. What is this here? He showed us. All with lowercase. Except the first letter. What is capital letter with these methods. We can just work. Not? The chains and Play around with these. So I'm going to delete this. So that we don't get mixed up. And there more or less we have. The functionalities more. common. Not? Than the most common things. That they are possessed with chains. Inside Python. Then the last method is special. Because the last method. Which will return an array. Or a list. How is that? Good. This that is here. It's going to separate us. Chains. With the chain that we pass to him. Simple as that. For example. Separate chain. The separate chain. It will be equal to Chain 1. Point. Split. Well. Why do we want to separate the strings? Well. Let's make each comma separate us. Or let the words separate us. By commas. Here we have a chain. Here another. Here another. And here another. By commas. We want to. Every time there is a comma. The chain separates us. Let's see what it returns. Separate chain. If we update It returns a list. Effectively. If we ask What type of data is it? Type. We'll see. It returns a list. Because indeed. What it does is. Create a list. This method. Create a list. In which separates Everything we've been through. And adds it. That is to say. Create a list with This value. Separated. This separates her. This separates her. I mean. How we pass it In this case. We pass him a comma. Then it separates me. The string in commas. Here are. The chain 1. Chain 2. Chain 3. Chain 4. And adds them all to a list. that we can find it Here. In fact. if we want We can tell you. For example. Let's see. show me. Separate chain. One. What do you have in separate chain? One. And tells us Machine. What do you have in separate chain? Zero. Tells us. Hello. So. It is the first string we added. What is it. Hello. So easy and this method works. The truth is interesting. And I highly recommend it. Why. Aside from string methods. These are things we can do with strings. Later we will see other types of methods. Even that they are more complex than these. But now we're not really going to need them. But later yes but not now. What we are going to need. They are methods to be able to work with lists. Because these are just string methods. But now we have to see what the Methods for working with lists. That we also use them a lot when we are programming with Python. So. we leave you with the list methods. Go. Well, just like we saw string methods before, Now we are going to see methods of lists, that is, methods that we will be able to apply to lists to operate them. Well, first we will come to methods, where we had just the methods file strings and we are going to create a new file that let methods-lists.py . There we are. To start, I also made a list with any of these methods and we are going to start with the first one not being a method, it's a function, as we previously saw dir. We also have this list function, which list just creates a list. We already saw it in the course, but precisely if we say list equals list, Here we pass parameters, for example, hello, dalto 34, here we say print list, We run it and it returns an error. In this case returns an exception. Why does it return an exception? All right, because this just takes as a parameter Really a list and that way now we do create a list. We can see that when we update it Y we run it, we have the list created. What there is no point in doing this to create a ready, is rare. As we work, for example, with tuples and so on. Well we can use it but it is not the most common. But nothing, what know that with list we can also create ready. Creating a list with list. Ok, now yes Let's see the first method of the lists, what is lion Also len, if you look closely, len it was when we worked with the characters. In a text string, for example, string the same, hello, if we tell him to tell me chain or result, easier. result is the same to chain point len. This didn't work because not it was a method, it was a function. if we put len, chain and we execute it, we are going to search result, let's run, see what you got in here. Well, he returned us the amount of characters that the string had. But what What if we do it with the list now? Go let's see. If we do this with the list, it returns us the number of items in the list. I, for example, here I put another element, another element and another element, for example. Now I'm going to return that the list has six elements. One two, three four five six. This is true, for what we will return six items. It's perfect. Quantity, elements, equal, len. Then of this form we say returns the amount of list items. then we have another more, which is precisely what it does is add elements to the list. In this case we are going to say by adding an element to the list, adding elements, not the same, adding with append. Because we have different ways to add elements, with append, with insert or extend. So let's go to put adding with append, equals list, point append and we're going to add an element called hahahaha. Let's see what this gives us. First, if we add that element, the list has other element more. We call this variable we call the list over and now the list it was modified. What we did here, if you notice, it was not modify to this variable that we are creating, but it was modify directly to the list. So in this way, to the same list we add this element. Hahaha. And the we show here. So it worked. Go let's see what throws us The variable. If we update, this returns us none. Why? Because it is not a value that us amount. So let's delete the variable and now yes, we only work with the list. Of this way we just add a value to the list. Now we also have insert, which too adds an element to the list, only that with extend adding an element to the list in a specific index. That is, if I say for example list.extend, here first I put the position. For example, I want it to be added at position 2 and in position 2 we are going to add the element. Here, mom, here, mom. Let's see what shows us the list. Now if we update the list. Ah, well, it's not extend, it's not insert. Forgiveness, It's not extend, it's insert. We were watching insert. There it goes. Insert what it does is precisely add a list. Let's see if we update if we update and we run the program. There she added it to us. Come? In index 2 he added take us, mom. 0, 1, 2. That is that after 34, that is, before 34, sorry, before 34, because this is the element one. That is, index 0, index 1 and the Index 2 is going to be this. I mean, basically Yeah, man, Look, I want index 2 to be this one it's here. In other words, that the one who was previously the index 2, now it's going to be index 3. See? Before it was 0, 1, 2 and now it is 0, 1, 2, 3. Why? because index 2 is this. That's what insert does. in append we can't do it. In insert we say, che, look. It's basically that. We say, che, look, I want this element to be in index 2. And if it already exists an index 2, run it back. That's how it is how does it work. And then we have the last What is it extend. What extend does is add several. With extend we can't add one. We add several. Adding multiple items to the list. Ready. point extend And here, for example, we can add false and I'm going to add a 2023, 2030. There this. We update. And if you look, this throw a error. Why? Because this does not ask me. That is, we do not add the elements of the list So. The we add as above. Did you see that this parameter asks us for a list? well we got him to also pass a list. That is, we add one list to another list. so we have to just pass him a list. A list with items. Now we update. and now yes works. Because we have to pass you a list. And not a list is added. The list divides us and we added as individual elements. You see? False, 2023. We just added these two elements to the ready. But we don't pass the separated elements to you. Here we pass separate elements. we can pass a 5 if we want. we can pass you a true if we want We can use what we want. But here we do not have it loose. We passed it inside the brackets. because this means that you we are going through a list. then we have pop. That contrary to adding, we are already removing. So we are going to delete it. Removing, rather, a list item. For your index. Why? Because pop asks us for the index. List, point, pop. Let's delete the element 0, for example. So if we are now going to update the list. List now has no element 0. The item 0 was hello. Come? Before it was hello. But now it no longer has element 0. The element 0 now it becomes dalto because the one that was before element 0 removed it. and now instead That the list have. notice. If before we put, for example, before we do this. I tell him, show me in screen. Ready. Forgiveness. LEN. Ready. That is to say, If I ask you to show me the size of the list and I ask that you show me the size of the list. You are going to see this, which is quite interesting. What is? He shows me a 10 and a 9. Why? Why before the list had 10 elements. I show it onscreen. And I show on the screen that the list has 10 items. Then we remove an element. The element 0. And when we ask him again how many elements has. He tells us now he is 9. So 10 items. It shows us the 10. We delete the element. We show back and now we sample which has 9 elements. That's how POP works. It just removes an item from the list. If we put for example, the 4. We would remove the element 4. That element 4 was 0, 1, 2, 3, 4. We delete the 23. But no. Why? because the element 4 is not 23. It is 56. Because the element 4 is 0, 1, 2, 3 and the fourth. After 34 came the 56. Which now disappeared. Because here, look, that we added the element takes mom. Plus we added the hahahaha element. then to add these items, the list changed. Then we have to take that into account too. Even a technique to remove the latter. Why you will say che de dalto. But listen, i want to delete the last element of the list i. If he last item what is it? the last item it's 2030. How do I remove 2030? well, i What is done is put minus 1. If you put Minus 1, the last item in the list is removed. This is an interesting technique, huh? Why this way we made him look. Index 0 is this. Ok, 1 back. And 1 backwards does not exist. Then reboot from the last one. if you we say minus 2, we eliminate the last one. Come? Us remove the false. Before the latest was 2030. I eliminate it. The before last is false. and here He disappeared. The false is no more. It is a technique that I throw them that it will serve them in the future. I I particularly use it a lot. In fact, Let's clarify this that I specified. we remove a list item. And here we are going to put minus 1 to remove the last one. minus 2 to delete the before last And so on. oh That's how the mark is left. there we put 3, for example, and item 3 is removed. What was the item removed? Item was removed I think 34, right? Yes, 34 has been removed. Perfect. Then we have remove. which also removes removes. Only remove. Stir by removing a element of the list by its value. I mean, Now we are going to remove an element by its value. That is, we are looking for the element. List.remove. For example, take mom. Now we have to search What is the element called? If you find it, removes it. So if we now look for it, you see? She deleted it. Before she was here. Take it. now already is no longer on the list. If we pass him a parameter not found, will not remove nothing. And not only that, but it throws an exception. That's why it's important, let's say, to handle this exception. And in this case, well, pass it on a parameter that we know it has. Then now if as found tomamama, you can delete it. And he doesn't have any more tomamama. if we ask that delete 56. Well, delete me 56. There ok, 56. Look it up and there it is. I delete the 56. Perfect. Let's put tomamama so that just like added, removed. And then, finally, we have the clear That this is already Manasi. This delete everything. Deleting all items of the list. List.clear. just like that list.clear and removes them all. That's why we're going to leave it in the end. Even if it's something that eliminates, it we are going to leave at the end because we do not want to to eliminate us the list. In fact, if we look at how it is this list and we show it now, it will say it is an empty list. He passed us an empty list. Because all the elements were removed. As well as we want this, let's comment on it for now. Perfect. Let's go with the next one. notice what like the we comment, update and it no longer runs more. Sort is a function that sorts the elements of ascending shape. Let's see how this is. If I, for example, say lista.sort, let's go Let's see what it shows us now. what happens here is that notice that this does not work if the list has text strings. So what we have What to do is delete all the text strings. So Up here we are going to erase all the chains of text. We delete the text strings. Y here too there is this lol Let's erase and go to create an element that is for example a 65. And here the false we are also going to delete it and we are going to remove it. Now we update. effectively can we tidy. So let's update. Now yes he could order us. Even if there is a true, the true go first. Why? Because if they notice me I add a true. The true is at the end. I I add a false. Let's see what happens. false. Let's add it false. Let's see what happens now if we add two false. The fake ones come first. The true come seconds. And then come the numbers. From minor to major. To this we can also give a property that is reverse equals true. if you we added this in here, notice that what happens is that they are reversed. I mean now the we order but we order them backwards. In reverse. It's like we grab each other of the elements and we would invest them. how we say them back automatically. So that's how it is how does it work this. He turns them over. What was previously the element 5 is now 1. What used to be 1 is now is the 5. And so. Let's put now ordering the list. If we use the reverse parameter same true lo sort in reverse. There it goes. let's take out this parameter reverse equals true. Now Yeah. So upward. I mean, up. as a minor to major. If we put it in reverse, that is, order it in reverse, sorts it in descending order. From the oldest to the youngest. And finally we have reverse. what a reverse does not do the same as sort with the parameter reverse in true. But what it does is precisely invests The elements. reverses them. That is, if first the we order and then we give it in reverse inverting the elements of a list. List.reverse. How do they I mean, if first what we do is order the list, then eventually it will be yourself result. It gives us the same result. There we have. It actually gives us the same result. Yes we update, it literally gives us the same result. Order us from oldest to youngest. For what? because sort what it does is order it. If we put it here reverse equals true would do the same as this. But if we took out the sort, this is what it does is the string that already exists. just the change of place. Notice that the default element, We're going to delete this one. The default element it is so. 34, 56, true, false, 65, false, 2030. If you we add the reverse, it is completely inverted. So the reverse works for any ready reverse it. Only that the sort, that this that is here, what it does is first it orders it and if we pass the sort parameter same true, by the way you can also do it the other way around. Only that the reverse does it without ordering it. In other words, the list that it reverses it anyway. If you look, the one that before It was him first number is now the last one. Which before it was the second number now it is the penultimate. Y what used to be the last number now it is the first one. What was once the penultimate now is the second. This is how reverse works. And there more or less we have each and every one of the items of the list. So we've already seen Let's say, what the methods have been from the lists. In fact, the tuples just and the sets, which are the sets, also have their own methods. But they are quite different. Is say, if we now, for example, were to show say list, is going to show us all the things that we can do with a list and we can watch. are all are. Whereas if we looked for those of a tuple, we are going to put a tuple and we are going to put any value, for example, this is a tuple because we created it with parentheses, we says that the things are different. If you notice, some things are similar, like the endsWith, as he is numeric, like the upper, the join. But for what? Because it works almost like a string. let's add any other element more, that's how it works as list. There is. Now it works like, say, a list. And if you notice, we have values different. We have almost few features. The only thing I know can do with tuples is count them, count how many elements does it have and use the function index. Do you remember that the index function also Was it to search for an item? Those are the only two things we can do. index to search elements and count. Just as index looks for us in chains, if you look at methods when we were here of chains, index, to see if we have index over here, here is index. Just as index was looking for us precisely letters and returned us, let's say, the position it was in, returns us also the position in which the element is that We are looking for. It doesn't work here anymore characters, here it works for the element complete. We are going to see him. If I, for example, put index here Checking if an element is in the list. If I put the element found here, it's the same list.index. I want to look for, for example, the 56 that we have in the list. I update and if I ask him to show, we're going to ask you to show it to me, element found, what is going to give us back is, ah, what happens is that 56 did not find it. Well, not, because I forgot a parenthesis. Now Yeah. We use back and there we have two. Why? 'Cause the position you're in 56 is 2. Up here we can see it, come? The position is 2. 0, 1, 2. If we ask you not to find, for example, 34, or easier, we ask you to the true is not found, we pass the true to it, let's make a prediction. there it goes, one prediction. 0, 1, 2, 3, 4. He has to throw us a 4. We update and he threw us a 4. That's how it works. But what happens if I, for example, tell him to look for me 5. Is 5 going to find it? No. There is a 56, but not there is a 5. Even though 56 has 5, this looks for complete elements. 5 is not 56. This basically He grabs each item and says, what does this mean? He passed? Is it equal to the element of the list? And good, if we go to the top of everything, equal to this? Not is. Like this? It's not. Yes it has a 5, But it is not the same to 56. The index is looking for exactly in lists is if this element is equal to any of those of the ready. And 5 is not equal to any element. 56 contains a 5, but does not equal 5 to 56. That is good that enchanted him on the web. And yes, too it throws us errors. So let's give it 56 for what find. Now yes. There she found him and gave us back the index. what i told them it's exactly like that tuples work. If this that is here, instead of being a list, it was a tuple, what I tell them is that what we can do with the tuples it's just looking for items and counting them. Just because let's try to be a tuple, reverse it, reverse it or alter it in any way, we cannot. Why just the tuples and sets are immutable. We can redeclare them, but we can't change no element. We cannot change the order, for example, of no element of the tuple. But if we're going to for example, what a dictionary can do, for example, we put dir, and here we put a dictionary, sorry, no dictionary, a set, that we make the sets with set. Not they forget. And here we are going to add, for example, a value and another value. So we update and here tells us, set does not stay like this, it stays with the same too. A list and here we go. Worth 1, value 2. Now we do update and we have the set created. What it tells us is this that can be done. Now yes, what we can do is remove elements from sets, remove elements from sets, but we can't add elements. That is to say, we can't use the append, we can't use the appendix, we can't use the extend. we can only remove items and remove items. Not even we can use index. Take a look, see if suddenly we use with this the index. Go to make a list Set, let's say, element found in set equal set. We will take out any element. And we are going to put a 54. Point index 54. Let's see if it finds element 54. We update and we has an exception, because it cannot be used index together. if you want to see which are all the things they can do, they have here. They have to just use dir and lo come how we just saw It's definitely interesting that we can see this and no. not really It can Let's say use the index in sets. in the tuples we can only search elements and use the index. While in sets we can do everything we saw before, which is for there copy them, clean them. That is, if we can eliminate all the elements of a set, we can copy them, we can remove them. And if you want to see that perform the different functions, I recommend investigate them, but they are only the ones that we have seen so far. What yes, then we have methods of dictionaries that also have their things. I mean, yes, yes, we can't do that much either as with the lists, but we can do other things interesting. So let's see some dictionary methods. Well, well, here we are in another day. Evidently there you will see that it is a much more advanced day. And yes, Argentina won the World Cup. my predictions they were correct. Later they will see that I made predictions And I hit all the predictions. Now we are at 29, but when I did the predictions I made the month. It happens that this video was deleted from me, like this what did i wear... I mean, in fact I had had other clothes, but I put on these clothes to do and be consistent, okay? That is, I am recording this on the 29th of 12, December 29. Just because when I was editing this course, yes, I said, look, the truth is that a little bit of the video was lost. Why? I don't know, it was a PC error. Fantastic! So this goes it all back. But basically we are going to see the section of Inputs and Dictionaries. But start let's see what we came watching a few minutes ago. That for me it was an eternity, but for you were a minute and a half. Well, here I handled a couple of methods, ok, What are these five that are the ones that normally we use when we work with dictionaries. And we have Keys, Get, Clear, Pop and Items. We are going to give for each one, but we start with Keys and basically here I created a dictionary, okay? So that we can start exercising and it is a simple dictionary. And basically it's a dictionary with three items. A name, which is the same as Lucas, a surname, which is equal to Dalto and the number of subscribers, which is a million I put a million followers because it's a very special number This year something very important happened for me and unfortunately, that is, something happened that That's why I didn't expect it. This partly made him see more the need to get this number, that already in the future he will find out why, but he has a very important meaning. It's not just a million people, who we would be a million programmers, if not which has, let's say, a much more background, at least personally in my case. So when we get to a million probably find out why it is so important to me this number. And nothing, I hope I can show them to you, already probably 2023 is going to be the year you can see it. It will be very important for me to be able to show them to you, So nothing. We are going to arrive, I am completely determined and that's how it's going to be, and when we get there you'll understand everything. So, we send him, let's say, keys, is going to be equal to dictionary.case, there we are. If we now show this in a print, let's go Let's see what it shows us. We give it F5, well, we are going to give in Transfolder in Continue, it happens that I opened all laps. Additionally, as the folder you now believes is more advanced, what I had to to do was create a new folder and delete the previous ones so that they do not see what followed. But here I morphed and left the input because I forgot, but hey, forget it, so I have to restart everything from scratch. Python file and now we are running it. Ok, this returns us dict.case, which are first name, last name and subs. What use are keys for us too? Well, it also helps us to iterate. They will see later what it is to iterate, but this way we can iterate the keys, okay? I repeat, they are going to see what it is to iterate and how we must iterate, but precisely, as in the future they will Let's see that we are going to be able to iterate with items, we can also iterate with keys. So far we didn't see a case to iterate it with keys, when in time they will see more Go ahead and explain this. I'm not going to explain keys to iterate, but yes We will see it in examples later. So nothing, they will understand it well how use it in the future, but to boot, this It is a very common method and it is precisely, allows us to iterate these elements in the future to be able to have, say, an array with all the elements, with all the keys. Then we have get, which get is very simple, Here we give it a name, for example, that is a value, with get we pass it a value. And when we access it, it will return the courage, Lucas, name the same Lucas, I'll give him For example last name. This is very simple to return dalto, If I give you subs, when I update it will return a million Why does it work like this? It's like basically in a list, do this and put element 0, item 1, item 2. In fact something interesting here is that we we can call the elements by, say, numbers as if it were a list. So we can literally do this, it works, that is, if I now suddenly come here and I say 0, oh right, because there is a 0, let's leave it as if they were numerical values, there it is, Now yes, I update and now they are fixed. I update and it shows me Lucas, because this that is here is as if it were literally a list, only that it is not a list because it is not a list type object, that is, it will not behave as list. We can call it as list, because we say dictionary 0 and looks like such a color a list, shows us the element this. As I told you, a list is literally a dictionary, only that the index already It comes by default and is auto-incremental. that is, it increases for each element that we automatically like. But in a dictionary we can also do, we can add the numbers as if was a list, but for that we created one ready and that's it. The dictionary has other uses, it has another way to work just with key or value and that's why it's a dictionary, if we would not make lists, if we would this way, that is precisely why it is important differentiate it. Each object, each element that we create has to go according to the type of data we want work and context. So it would be stupid to do what I just just to say, this is correct. And get, you may wonder but then, what do we use get for? yes we can do it calmly like this, we come here and put subs. Well, what happens is that if I now for example I do this and say dictionary and no It finds it for me, this is going to throw an exception and it is a k error. But if I pass him get and here I pass him a name that is not, this does not throw me one exception, but it tells me noné. That is, while one throws me an exception the program stops completely and does not continue, the other tells me, look, that is, if I can't find it I'm going to return noné, no, I'm going to give you a error. That's the difference, so the program continue, if I put print here for example hi dad i update this and he says hi dad, none But if I put something here for example it will not find, the program does not continue, it gets stuck there and it ends there, he throws us a error. So that's the difference, not that with one, the program continues with another not. Besides get, we can already work it and understand which is a getter, which we will see later what is a getter, but a getter is basically a method who can access a particular property of an object, but we are going to see well what the objects are, relax your ass a little bit, don't get upset, dad, the cachooteos, ta, ta. So good, here we are going to put, obtaining an element with get, here in parentheses Lets put, does not throw an exception and if it does not find nothing the program continues, if it does not find nothing the program continues, easier. And then we had the other one, keys returns us a dictItem object, dictItem is a type of object that allows you to iterate. Keys the same dictionary dot keys and here we are going to put value of an element, Let's put value on it, easier, value from cas, because that's what you get, it's getting the value of this, so that's why I put it like this to be well, more in line and let it be, it's fine, it's alright, it's the right way, because variables have to be intuitive, when we create a variable, the variable has to actually be something that describes what it contains inside, you know, what it contains inside and the value of cas is indeed that, so I told you. Hello dad, the program continues, we update and there we see that it works, everything is 10 and here we have what we need to obtain. Well, now yes, well now let's continue with the following method which is clear, clear removes all items from the list, that is, if I take it and put it, eliminating all from the dictionary, no, it does not delete from the list, sorry, delete from the dictionary, sometimes when I speak I swallow, It happens that it's 4 in the morning and I'm here like a retard recording, It's almost 30 degrees back, I have a heat here because it's a little less hot outside, that is, the heat outside is much less than in here, it happens that in here like I am with many acoustic panels, many things and so on, the heat is overwhelming, I mean, you literally go outside and have a little cold already at this time of night, but it's hot inside here, it's impressive, I mean, well, now yes, eliminating all the dictionary and we say dictionary clear point, and now we are going to see the value of the dictionary, let's check it, dictionary, let's see what there is nothing inside It is an empty dictionary, here we can see, that's what clear does, it removes everything from the dictionary, that in fact we are going to leave it to the last, because, well, we are going to comment it so that don't delete it, actually the whole dictionary, let's put another comment that says deleting a dictionary item, because then we have another function that is pop, that with pop we delete an element from the dictionary, just as we remove pop, we remove elements of tuples, of lists and others, with pop as well we can remove items from the dictionary, For example, here I put a dictionary period pop and here for example I want to get the name, well, that's it, ah, Lucas no, sorry, it's a name, I said name and I put Lucas, come as I am at this time, I run the program and it says last name dalto subs a million, if I now suddenly want get the last name, because there it is with the name it seems to me enough, the last name is not necessary, well, I say this and now it returns my name, name Lucas and the subs, and if I now of suddenly I want to take out the subs, I take out the subs and there it is, first and last name, I'm not interested in subs, and assuming that I want to get more elements, I put the comma and element, comma and name, subs, name, Now it takes me out, I update and now it takes my name and subs, and finally we have items, which items returns exactly the dictionary, that is, if I come here now, for example and I show dictionary, it returns this, and if I now suddenly tell him, getting an iterable dicItems element and I set iterable dictionary equal to dictionary.items, Let's see what returns me in dictionary is this while what returns me in 3734 02:38:39,130 ​​--> 02:38:40,811 iterable Dictionary, it is something else that is this that is here, then in one situation it returns me this, while which in another situation returns me this, because we can't iterate this, basically to iterate is to go through the element, we are already going Let's talk later when I explain it, but we are looping through the element to be able to access each of the elements, here we can't, while here we can, Now when we see loops we will see it, like this that in fact the next thing we are going to see after of the inputs and the exercises and everything that let's do, is the loops, that is, inputs, exercise and loops, and there we are going to work again with this, but before you see that, they have to understand well how the inputs are, how they work so that we close this cycle and let's start with the first practical exercises What are we going to do during the course? so here I leave this section of dictionary methods, and now we continue with the inputs. Well, to boot, create a folder that is called Inputs and a file called Inputs. So if you want, do it with me and let's do the same, okay? Create the Inputs folder and create the file Inputs. input.py. So now we come here and put a comment what are we going to say Ask the user for information. Why do we do that with Input? It is a function that allows us to ask you for a data to the user. Simple. How do we do it? Easy. We say, well, look, let's see, names, right? And we call it Input. Che, teacher, give me your name. Colon, Enter. So when we update, now it leaves us a space here for us to click and let's write. I can put Lucas and now nothing happened. But what happened? Now the variable name is going to be equal to Luke. I mean, all of this is going to turn into Lucas. How can we corroborate it? Simple. Now we are going to leave a space because another interesting thing is that when we do not stop spaces we put it all together. But if we leave a space, update and now it leaves us a space and allows us to write sparingly So that's what we're going to do. Let's come and show down Print, showing the data. And here we put Print, name. We update and now look at what it asks us the name Lucas and below shows it to me. What's more, we can concatenate it. I can do this and say Tucson. Tucson again. The name is colon and I select this and I put it in square brackets. So between keys, sorry. I update and now it tells me Che, teacher, give me your name. And Lucas. The name is Lucas. This is how we ask the user for data. Now, what if we ask you for a number? Okay, we're going to ask you for a number. Give me your name and I'll give you 11. Because he comes to me to do Stranger Things and He paints me to call me 11 because I think I'm a guy with magical powers. So I flashed rainbow and hit enter and It tells me the name is 11. Well, this although it seems is not a number. The data that Input will always return it is a text. Do not forget that always the functions, when we use functions, we use Print, we use Input. All the functions that we have been using They're going to give us things back. Just as we were using string methods, list methods, each method returned us a data. They gave us back numbers, they gave us lists, texts were returned to us. What Input returns us is always a text. In fact, we're going to rename InputNames. And we are going to create another file that will be InputNumbers.py. We are not going to ask for your name here. Let's tell it to ask the user for a number. Number equals Input, give me a number. Colon space and wait for him to give us the number. If I suddenly say multiplying the number by two I come here and put result equal number by two. So now I come down and show it, show it the result. Print, result. This is a super intuitive program, super perfect and we give it F5. Give me a number, captain, I'll give you a two, a six and it tells me 66. Why? Uh, here's a problem. Doe times six is ​​66. Clarify the account. Here is an example that explains it better. Ok, give me an example in Paint. As always, a tall beast creating everything in Paint. Why do we talk about while it is the person? I don't know. But here we have exactly six. Here we have a text. Do you remember that when we grab text and we add it The characters are simply added. They grab and join. As we could see here. In other words, here we have a character. If we multiply it by two, we get two times the character. So we have this result. Now when we multiply a number by two. We have another thing. Here it is as if we multiplied twice. We are telling you there are two times this character. Well, that's it. I join you and if I have twice the character. Now the numbers work differently. When we tell him to multiply them by two times. It does not give 66. It doesn't give 12. Because this is an arithmetic calculation. We are working arithmetically with this fact. Not by concatenating them. That is the difference. So we have information that is. and dalto, you are giving me a piece of information that is a text. So what I have here is that I have a text. I'm telling you that this here multiply by two. And it gives me 66 because I am multiplying the text six for two That I have to do? Convert it to number. How do I convert it to number? Well, the int function, as we saw before. Int number two. Now I converted it to number. When I update, now it says give me a number captain. I pass him the six. It returns 12. Why? Because I converted it to number. And this data is an int type. I converted it to integer. So now I say. I convert the number to integer and multiply it by two. There we are. This is what we do. What's more, later we can come here and copy it. And here to tell you, I convert the number to float. Float and multiply it by two. And here I put float, which is the other function. With one function we convert to int with another float. And float is a number with a comma. Now they are going to see. I'm going to comment on this and I'm going to update. And now I'm going to give you a number. I'm going to give it a 4.5, for example. I give it a 4.5 and it tells me 9.0. But why does it show me the zero point? If the result was nine. Remember that when we work with numbers floating. If we have 4.5 times two and they give us nine. It's not nine. It's 9.0. In other words, it is a floating number. Even if it is an integer. If we convert it to integers with the number int. I explain. In other words, we could do this in any case. And put to the int function of the result. So the result of this. What is this going to be? We convert it whole. If we update it and give it 4.5. Now it does convert whole. But it's to fart. It is like... It depends on what we want to do. It may or may not be. But what if here? For example we had the int. Let's leave it as int. And to this int I will pass another data. For example, I would like to pass you a number with comma. Well, I update and give it a 4.5. Oh. What happens is that we are passing it to int. A floating number. And int converts integers. So when we know we're going to work with numbers with comma. Okay. If we are going to work with numbers with commas. We use float. And now this works. And we can work with numbers with commas. I try the same. from 16.23. It multiplies it for me. Ready. You have the result with a comma. And if you say later Well look. I know that the result is going to give me floating. Because I know that they are that I 0.5. Then you can convert it whole. But if not and you need it floating. You leave it on float. And that's how we work with data. With numbers. But we can do even sums. Thus. We take a number and add it. But how can we add two numbers. Well first we convert the two numbers to integers. And we add it. What Input does is pass us data. So and so simple. Like this that we are actually going to use it much. Because input. It is a tool that allows us to ask data to the console user. In other words, to work with other types of data. We use other functions. But this is the main one. Literally what we do here is ask to the user who gives us information. And in programming everything is that. It's all asking for information. process it. And give an answer. Is that how it works. So now we are asking for this information. He gives it to us. And we process responses. Instead of us giving the program the information. As we have always done. Now we ask the user for it. And this is exactly the way to work with numbers. In Python after using the function input. In fact, here we are going to put the entire result. And here we are going to put floating result. Now we are done. And here we are going to put floating result. Because if not, then it will throw an error. And I don't want us to have mistakes in the codes that we already left written. Perfect. We have it ready. And I tell them that now it is going to be beautiful. Because we are going to go with the exercise section practical. The practical exercises section is a section that will allow us. Create things with what we have been learning. In other words, everything we've learned so far. We are going to use it to create things and create projects. There will be three practical exercises. Practical exercises 1. Practical exercises 2. And practical exercises 3. These three practical exercises will allow us to reinforce everything we already knew. And put it into practice. To see what problems we're up against in real life. When we create things with knowledge that we already have After practical exercises we are going to have two other tests. Which are like practical exercises. Apart from that we are going to investigate. There we are going to learn new things and we are going to develop with what we already know. And learning new things. And then we're going to do a final project. What is a project to collect everything that we learned and new extra things. But to start we go with the three exercises practical. What is practical exercises 1, 2 and 3. Now we go with practical exercises 1. That we are going to pose different problems that we have to solve. So let's see if we can figure it out. And how do we deal with problems? What are they going to ask us? Come on! Well, since we just advanced in level, I said, well, since they are here, I'll put on another Camisuli to change the look a little. I am the same grumpy, but with different clothing. Well, let's start with the section on practical exercises 1. Well, for starters, I grabbed and had a few 10 Python courses, which are among the best known and even the most recent. We are talking about, let's say, free courses and payments, both, and I basically looked at quite a lot each. And I have spectacular information for you. The other courses, to reach the same knowledge that you have now, that is, to explain everything that we explain until now, it took between three hours to seven hours approximately. That is, what we learned in less of an hour and a half, the other courses They explain in three hours to seven. There was one that took about nine hours, but i really left it off this list, since obviously we are not going to take it into account counts because the average goes to the dung. So, I got quite curious and said, but why we, or me precisely, I can explain in an hour and a half what in other courses it takes about three to seven hours? Well the answer is simple and basically are two things that are two factors that made that this is possible. And the first clearly is the speed at the one I speak, that is, I more or less speak a 1.3 of what other people talk about, that is, 30% faster. And the second is the edition, the courses are amazingly edited and the amount of garbage that is reduced and spaces in silence, that do not contribute anything, is very high, what makes for today a four hour video finish lasting one and a half or two. Ok, how is this? Well, to start handling this speed and speak faster than others, which other people can explain in four or five hours, I can explain it in three or four or so. In fact, up to this point, the amount of hours that I recorded were three and a half hours, that is, what people on average take in explaining, about five hours, I managed it explain in half past three. This basically, as I say, for speed, only input the speed made let's buy time On the other hand, those three hours of video just turned into an hour and a half or so less when I edited it, that is, I took more half of the material. Going from the average contest, you record five hours and you have four left, I recorded three hours and a half and I had one and a half left, we are talking that the optimum, let's say, of this is very high, but it's amazing. Same concepts, also extended explanations in detail, motion graphics and animations, it's even a 4K video. I am telling you this so that we can do the first exercise and is to dump all this data into a program to perform the first of all these exercises. Go. The first exercise consists of the following. The timing to see the concepts seen in Python in a continuous course is 2.5 hours minimum, 7 hours maximum and 4 hours on average. This course was accomplished in an hour and a half. How much difference in percentages is there between the current course and the fastest of the others courses? Slowest of the other courses and average of the courses. b. Given that the amount of crude the average of the other courses is 5 hours and with editing they make it 4 hours, and the raw of this video was 3 and a half hours and it was reduced to 1 and a half hours, what percentage of useless material, empty material in Ultimately, it is reduced from crude oil in both cases? And finally c. Watching 10 hours of this course would be equivalent to see how many hours of other courses. And see 10 hours of other equivalent courses how many hours of this course. Well, this is the first exercise we have to solve with the data we have below. Another fact that I did not mention, which obviously not relevant to this exercise, but What is good to mention is that this course It is also available in English. It's good because if they have friends who want learn Python and speak English or speak others languages, this is not only the best course for people who speak Spanish, but also for people who speak English. Now yes, let's start with the first exercise. Well, the first thing I'm going to do is create a new folder that will be exercises1 and here I am going to create the first folder that it will be exercise1.1.py. Why? Good, because 1.1 is exercise 1 of the set of work practical exercises1, as well which exercise1.1.py. Well, first what we always have to do when we start this type of programs it is write down the data, so let's write down the data we take into account. I recorded the data here. Good. So, let's create an annotation, durations, the variable will be average duration, and then we have the other, dalto curso that lasts 1.5, that is, in other courses to see all these knowledge takes 2.5 hours, at least, at most 7 and on average Four. We achieved in 1.5. Those are the data through which we have the duration. Then we have to take the average of raw. Well, what the exercise asks us you already know which is basically show the difference. For that we are going to create a set of variables Show us the different differences. Duration variables, difference with min is equal to well here we have to get a average easy. First what the dalto course lasts, dalto course, divided what lasts exactly the other courses, other min courses and this for 100. Well, let's see what it shows us this, print difference with min shows us 60, that is, that is, the high course lasts 60 percent of what the others last courses. This 60 is a false data because let's say no represents nothing real to us unless here Let's put 100 minus this. Why? Because this remember that it stops in modules. First 100 is executed on one side, then all this is executed because let's say this is Like math in real life. Divisions and multiplications are executed first. in this order and then subtract, that is, is not 100 less than high course and after the result of this divided this by this. No no no. This is executed in this way, that is, it is run like this. Without parentheses it works the same. All this is executed first and the result From all this we subtract 100. It's basic math, that is, first basically it is dalto course divided others courses min. That is precisely what it gives us when multiplying it by 100, 60 percent, but if we subtract it this is going to tell us the difference and the difference is 40 percent, that is, this is the difference of duration, that is, the course of dalto lasts 40 percent less than the fastest. So let's say, let's add a F here, an F here in front, let's close the string and let's say the course of dalto lasts a, here we say the percentage, here we add the percentage bar less than the fastest, that is, the course that most quickly explains it is this, because if a course the least it takes to explain everything that we explained is two and a half hours is because is the fastest, if another takes seven it is because slower, so here we say that is the fastest and what it shows us in screen is as follows, the course of dalto lasted 40 percent less than the fastest, that is, we managed to explain 40 percent faster what the fastest course it I will explain and so we can create others differences, that is, just as it is difference with thousand it can be difference with max and difference with average, it is here we are simply putting max and below we are putting average, then we update and there it will tell us, not here tells us nothing, we simply have to copy this right here, ok, and here we are changing, max average, now we update and it tells us, the dalto course lasts 40 percent less that the fastest, the dalto course lasts 78.8 less than the slowest, it should be here that is slower and 62.5 less than the average, we update and there we are well done, the point is that of course here we have a 78 point something and we went to the grass number, how do we do this? Well, for this remember that we use the double division, then we update and now it tells us 100 percent, why? Because this do not forget that they return us numbers that later end up harming us when working with decimals, why what? Because they don't return us floating numbers, So what do I recommend doing? First we multiply it by 1000, this to have more numbers after the decimal and then instead of multiplying it by 100 simply We divide it by 10, so in this way we have like a comma in the decimal, do you explain? And if we update now they will see what it tells me 78.6 percent, why? Because what I'm doing here is giving it, ok, three more zeros, that is, if you remember that the division, the double returns me a number that is integer, that is, if it tells me which is 0.7 is going to round to 0, if I says it is 1.2 rounds up to 2, instead if I multiply it by 1000 what it was before 1 is now 100, what used to be 1.4 is now is 140, so when we divide it by this is not going to give us such a low number and then We subtract that number by removing this and that shape is like a shape in math to get this, it's easy, if they were they will understand it but it is nonsense, it is precisely Let's say if we know that everything that is after from the comma is deleted, well, let's make it what is after the comma, skip the comma so that everything that is in the comma is erased and then we add the comma again and that way we already have the same decimal number, not in this case instead of move it to two places we move it one, if we wanted to two places we would do it this way, 1000 and there and that way we already have the comma moved to two places, it's like an interesting way to do it, I'm going to leave it like that, remember that in this case the hierarchical level of the order in which the form is performed is the same but it is not the same to do this than this, don't get confused because this is not mathematical but as it rounds down it changes, it is not a common division, then in this case numbers are not canceled with numbers, they have to understand that and in this way we have the exercise A done, we have A ready, that is, we are already showing the difference with each of the courses, B asks us that we show you what is the raw material that is removed, that is, what is the material that it does not work that in both cases we take out and we can obtain that with the crudes, like this we are going to create the raw variables, crude average or easier duration, duration of crudes, we have just put average crude is equal to 5 at most of the courses, the raw, that is, when we talk by raw we refer to the unedited video, If I have a raw video of 5 hours, when I edited it lasts 4, more or less, why? because it is the crude, it is the material that we extract when we edit it, the raw is the video unedited and my raw, raw dalto is 3.5 Now what we have to do is calculate the difference, because we know that my course until this moment this lasted and until this time this amount of time was recorded, while in the other courses this is what that this was recorded and remained until now, So we have to calculate differences, so let's do it, fact we can copy the same formula, we copy the one above, we go down and put calculating the percentage of empty time, and now if we calculate the empty time, empty time average, calculating the void time removed, the average empty time is equal to the same, We paste the formula above and here we put from dalto curso, sorry, it would be other courses average and here it would be average crude, and more or less if we ask how much is it, how much gives us this, we are going here to add another comment which will be entering the duration differences, down here we are going to say, showing the amount of spaces and those that are removed, exercise B, and here we simply put print, time Average vacuum, let's see what this returns us, well, here it returns us that it is 20%, like this that we are going to copy this, paste it here, here I am going to add a bracket and a closure and close the string, an average course removes a percent of empty time and below we put this course eliminated the empty time, and here we put empty time of dalto and now we create that variable, we grab here and we create it from dalto and here we put dalto course and here we put dalto crude and there if we update we have the same, an average course eliminates a 20% empty time, this course removed 57% of the empty time, that is, we eliminate more time empty than the others, if a course of 10 hours eliminate 2, a course like this of 10 hours delete 5.7 hours, which is really crazy, everything so that it is always more optimal, not it's good because I do marketing while I teach them to program, good but now the exercise is missing B. which is the last exercise of all, the D sorry, the C, I'm half stupid, the C us He says, see 10 hours of this course to how much it would be to another course, that is, see 10 hours of this course equivalent to watching x number of hours of others courses, so let's create it, showing differences if the courses will last 10 hours, print and add F, see 10 hours of this course is equivalent to see, here we are going to make a calculation, other courses average divided course dalto course by 10, because this is how long it lasts on average and we multiply it by 10, then see 10 hours of This course is equivalent to seeing hours of other courses, we update and it tells us, see 10 hours of this course is equivalent to seeing 26.6 hours of other courses, ok now we have to round it up, come on to do the same, let's round it up, how do we round up? well we do the same thing we did before, this We double division, we multiply this for 10, no easier, for 1000 and this we divided for 10, now yes, we update and we have left same result but with, sorry, we split it per 100, this is to give you two decimal places, then in this way 26.6 hours of other courses, let's subtract a decimal in both cases because decimals are not useful for us, it is equivalent to seeing 26.6 hours from other courses, that is, if we see 10 hours of this course is like watching 26 and a half hours of others courses and seeing 10 hours of other courses equals Let's see how many hours of this, let's calculate it, seeing 10 hours of other courses is equivalent to seeing, and here we invert this number, that is, here we put dalto course and here we put other average courses, here it goes, seeing 10 hours of this course is equivalent to seeing 26 hours of other courses and see 10 hours of other courses is equivalent to watching 3.7 hours of this course, now let's separate all with lines because we have a little left ugly, so let's separate it all with lines and we are going to put print, we are going to put a line, there goes, and we are going to repeat this in all cases, we update and we have all the data, in fact here I recommend make a print, do it here too for pull apart everything, here we go now yes, we have all the lines, there we are, the dalto course lasted 40% less than the fastest, the high course lasted a 78, oh no, easier, look what we are going to do, the course It's so that everything looks more beautiful, come on to put another print, the dalto course lasts two points and here below we put all the other information, space, hyphen, space, and I copy this and I paste it, space and dash Space, Space And Dash Space, saving and leaving all this, this is like for make it cuter then we update and we have this, the course of dalto lasts 40% less than the fastest, 78.6 percent less than the slowest and 62.5 percent less than average, below says a course average and 20% empty time, this course decreased 57.2 empty time, see 10 hours of East course is equivalent to seeing 26.6 hours of other courses, seeing 10 hours of other courses is equivalent to seeing 3.7 hours of this course, that is, in all senses this is much more optimal, much faster And go to learn, basically if you say no because how in less than 10 hours of Python course of dalto you will learn what this course teaches you of 25 hours, well it is possible that a course that there would be 30 hours do not teach you the same as this course in 8 for example, it is important to highlight it, because sometimes there are people who speak with this speed and if we speak with this speed and also we do not edit nothing and me For example, I have an error and I keep thinking let's see how long this can last, let's see not the error It's not this I think, well that's how to talk not editing it and others makes the courses last so much So that's one of the things that we let's grab and break it, we take it out, bottleneck broken, a lot of information in one video and on top of that it's good because you can stop doing it pause, everything is very centralized, they don't have what to go through, this is not the average level, it is not this one is the intermediate, not this is the advanced, It's all in this one, but it's already here we have the first solved exercise if they got here I congratulate you, let's go with the second exercise The second exercise consists of the following. 4264 03:02:19,130 ​​--> 03:02:22,250 Assuming that each person on average speaks two words per second A. Ask the user to say any text real and calculate how long it would take to say that phrase and how many words did he say. B. If it takes more than a minute, tell him Stop, skinny, I'm not asking you for a will either. And C. How long would it take dalto to say it, taking Keep in mind that you speak 30% faster. Well, in these exercises I am evidently quite present, that is, I speak of myself in the third person, things that not many can do. Oh my gosh, how sad. Well, basically it's because it occurred to me that idea, right? Taking advantage of the fact that I speak faster than others, we can use this variable to play around a bit on the way. Ok, let's do the second exercise. We create a new file and put exercise 1.2.py, get it? 1.1, 1.2. If practical exercises 2, you have 3 exercises, then it would be exercises 2.1, 2.2 and 2.3. This is the last exercise of the first part. First, you know, sentence. The phrase will be the same, the phrase will be equal to input. Tell me something, teacher, and I'll calculate how much you would take time saying it Tell me a sentence, tell me a sentence and I'll calculate you how long would it take if you had to say. We leave two points and a space, there it goes. We update and this is working, fine. Below what we are going to do is use the function splits, remember? That allows us to separate the words. So now we are going to put quantity of words, will be equal to sentence split point, spaces, why? Because the only thing that separates one word, another word, is space. So if we leave a space here, a space here, a space here, and we are going to calculate the number of words what's up, why? Look, one word, two words, space, three words, space. And so we can understand the number of words which has a sentence So we calculate it and here we put that the number of words is equal to the sentence split point. Here we are going to put total words, words separated. And below we are going to put amount of words, will be equal to len separate words. And all we have to do now is calculate how long it took. And for that we can do the following. Print, F, you said a lot of words, words and you would be late Here we open another and close another. Number of words divided by two seconds in saying it. So we update and here it will tell us, He's going to ask us to see. Hello teacher, how are you? What's up of life, king? Ok, we have to update it, good. We don't update it. Now yes, well, same thing. Hello teacher, how are you? What's up of life, my king? We update and it tells me, you said 12 words and it would take you 6 seconds to say it. Fairly good. The question is, how long would it take me? to say it? Well let's see. Print, F, Dalto would say it in, and here we do the same. Number of words divided by two by 1.3, which is 30%. Seconds to say it. And if we update, there we have. We say a sentence and I calculate how long it would take if you had to say it What are you doing, teacher? What are you counting? You said 5 words and it would take you 2.5 seconds in saying it. Dalto would say it in 3.25 seconds. Well, Dalto would say it in seconds. Ah, this is too much. Very simple and there we have the program. Even here if they want they can do the before which is to round and generate an integer, not? By 100, space, double division by 2 and then we multiply it by 1.3 and then we divide it by 100 back. Now yes, if we update we would have the program well to two decimal places. Well, now yes, now we are going to put an if. If number of words is greater than 120, let's go to say print. Stop, skinny, I didn't ask you for a will either. Why? Because 120 words is a minute. If the guy talks for more than a minute, said 120 words. So we have word count, 120. If you say more than 120 words, we tell you this. So we run the program and go to check if it works. Ok, let's write 60 words. The truth is that I put together a retext, I put together a re sentence, but in this way you can not be lowered, chabón. Ok, let's see now. You said 128 words and it would take you 64 seconds in saying it. High they would say 83.2 seconds. And downstairs he tells me stop, skinny, I didn't ask you either one testament. Spectacular, very good. The program is left, it is functional and we are going to explain part by part how it works. In fact, we are going to put the if, there it goes, for so it works. There you go, now we do have the code completely commented, functional and we already have everything ready to be able to say that We solved exercise 2. Even A and B together, that is, we didn't even take long, we didn't even have to separate them because more or less we could do it all on one only. And we already have the first section of the exercise ready. of this Python course. I'm really happy, I'm really happy because we made it finish. Now yes, people, we can go with the second part of python course, which is, say, an intermediate basic section, because we are already advancing a little more go ahead and that, What we are going to see now is basic medium intermediate. It's basic passing intermediate, ok? So let's see it. well now we are going to see just the second variables section which is a section in which we are going to learn a little more about variables and we will understand things that before we did not understand why we are on a level a little more advanced so since we are at this point I recommend that if they did not make and did not take to practice everything we learned before do it, put it into practice, have your code editor and stay tuned for write and do everything we are going to do then Pay attention and we begin, well first what I will do is create a new folder variables 2.0 variables 2.0 and we are going to get a file let it be unpacked and we will keep it as unpacked.pyton there we are What is variable unpacking? all right It is a way that a technique that we have here in python which has so many languages pronunciation also for basically assign values ​​to variables in a way quite particular how is that? pretty simple let's create for example a tuple data, data is going to be equal to a tuple that is going to be Lucas what is it unpacking? well it's a way in which I repeat we can create new variables taking the data from for example a tuple how do we do that? quite simple, we put first name comma last name same data that's simple how do we do that? that's simple name comma surname, what will the name be equal to? will be equal to the first value of the tuple What will the last name be equal to? it will be equal to the second value of the tuple if i even put a million a million and here I could put for example also your subscribers we don't have a million but is the big goal then this would work too What happens if I, for example, say print Name? Lucas is going to show me if I tell him print surname is going to show me dalto and if I say print subscribers it will show me a million why? because this is the way in which we unwrap variables have to pretend that each value we put will be placed in each of the elements of the tuple So it's important that you understand that the encapsulation works only if the amount of variables that put is equal to the quantity of data that the RAI has if the RAI has 3 data creates 3 variables if the RAI has 2 data creates 2 variables in this case like so This is how the decapsulation can work. unpacked let's say right? Let's see what results are coming in here we put unpacked and here we put creating a tuple this works with tuples with lists and others if I, for example, try to create a list creating the data here I can put data in tuple and here I can put data in list so here I do the same only that I replace it by a bracket there we are so I put data in tuple and below I can put something similar and notice that it works well it works and now i can put data in list and this Actually it also works because the unpacking can be given as much as for list as for tuple and also as for sets it doesn't allow me to unpack numbers that is a very interesting fact well here we have exactly this data already created and we have this precisely which is the unpacking they have just learned to unpack what good is this for us? It serves us a lot and we will see it more forward when we see for example functions since there are functions that, for example, return us tuples and if there are functions that return us tuples there are also functions that return us lists and if there are functions that return us lists and functions that return tuples we can just create information based to equate something to a function that is returned to us These data that we request now we will see Well, later I'll be calm but like that It is how they are unpacked, it is an interesting way to create variables just for that is unpacked a list a tuple are What packages right? data packets and what we do it is good we give a piece of data to each variable that way we unpack well now let's go to come back here and create a new file that it will be tuples.py and here we are going to create tuples we are going to put inside variables because It is seen that we left move there it is there a very interesting way to create tuples and is tuple tuple equals tuple is a function which allows us to create a tuple and here inside we simply put the data data1 data2 For example, if I now show the data print tuple but we have to pass it as a parameter a list that is there is only one parameter which is a list the list that is going to tuple me now I come and put print tuple update and it tells me dato1 dato2 I am going to put creating tuples here with tuple but there are also ways of create tuples of a rather particular shape we are going to put tuple we are going to redefine the tuple tuple equal data1 data2 so simple I created a tuple if I tell you show me this tuple we will discuss it for now I show it to myself the same because this is a way in which we can also create tuples without the parentheses if we only put the data separated by commas is automatically created the tuple this is here ok this is it same as this is exactly the same now the question is good but how do we create tuples with a single good data the form If we want to create a single piece of data, we put the data but at the end we put a comma because because if we put this without how this is a string an ordinary string with the comma is now a tuple let's verify it let's put let's create a tuple like this we are going to put this above we are going to uncomment it since what we do here is redefine it so this does not affect this at all creating a tuple without parentheses and here we go to put creating a tuple without parentheses of a single data of multiple data then here we have multiple data because here basically what we do is separate the data with comma and here the comma is not needed at the end the comma at the end is not necessary then we don't need to add it in fact if I here want to see the type tuple is there let's see if indeed is a tuple if it behaves like a tuple and if I will suddenly create the tuple only with a piece of information as we do as I told you before tuple equal data and we put a comma at the end So in this way we create a tuple with tuple in this way we create it without parentheses and in this way we create it with a single data ok with a single data we create it this way let's check to see if the tuple was created this is also created is a tuple effectively see it works as a tuple and it is not because of this because remember that here we can redefine it if now tuple is equal to this not to this but that to this in fact we are going to verify it if we take out the type it shows us the tuple come and now it is tuple data data comma and there we have the tuple created when we should create tuples well we can create the tuples when they are data, for example, read-only, that is, when we are only going to read data we create tuples lo What happens is that it manages memory better now that what the lists do to be able to be modifiable is they save two places in memory and one changes it and when one is modified modify the other then modify the tuple and then modify the other space in memory modify the tuple and then modify the other space in memory while the tuple saves only one place in memory then in this way the tuple is immutable because if you replace that data you run a risk that all the complete variability is erased so it is important that you understand that basically a different memory location is stored to a list then the list is stored a place where you can use process and so on while this is not then it is It is important that you understand that tuples for read fixed data and not to change They are much more optimal and it is what I recommend while the lists when we go to work with data that is going to be modified are the optimal is to say the lists for data more flexible Now we are going to create another one that will be set, sets or sets, sets.py like because we are seeing variables 2.0 this already we had seen it all but yet we are seeing how to create these things back we are seeing new things that's why it is precisely the most advanced version of variables is what you did not know of the variables and this is how it ends here all there are no other new things to learn because this is the last of the last so they just finished learning just the importance of each aspect well we can create the sets too with a set function as we already saw at the beginning creating a set with set and here it is easy we grab and put sets equal set and here we pass data notice that here it tells me what set needs as a parameter it is an iterable and we are going to see well that it is an iterable and other things we're about to get there here we give you a list ok a list that for example it can be data 1 and return data 2 here we are going to create the set if we give it We are going to go upstairs if we are together and we give print set indeed it is shown here set let's give it print set update and now data 1 and data 2 are displayed, this is spectacular we already have the set working now what happens when we want to put an element modifiable into other non-modifiable remember that the data the data for example of sets are not modifiable, that is, we cannot come here and say that set such is going to be the same to another data because it does not work how can we do to put data that yes can be changed into data that cannot be change if i now for example to set I would put another data suppose that I am here inside the list I put a list I put a list within another list this is possible let's see let's put a list that is data in list 1 comma data in list 2 I update This won't let me because it tells me that I'm passing a list and the list is a hashable which basically cannot be hashed inside of the set because that data cannot be modified and the list is mutable a list can mutate and here can only go data that is not mutate then we should use a tuple If now I replace this with a tuple come I update a tuple and if I run the program now it executes it for me because the tuples go inside other data so it wouldn't work with a dictionary either if I turn this into a dictionary What's up I'm going to bump this up a bit more if I turn this into a dictionary what happens is to say that it doesn't let me either and this is a list now i close it now yes, that is, it won't let me put dictionaries either because it says that the set cannot be found but how do I do if I want to put a set inside another good set we are going to try Let's see what happens if I take it out now we are going to put this we are going to get it out we are going to make this be the set this is a common set we are not going to come up here and put messing a set within another set a set we are going to create it in the normal way we create it well the set then I here if I wanted put a set inside from another set I put set 1 inside of set 2 this set will have data 1 and data 2 and you must create another set with set and data 3 for example this would not work this set can be inside another set nested sets can exist let's see it now i put you show me set 2 and indeed it throws me an error but I has an error for this I do not have an error for something else now we do update and there it won't let me put a set in it another set as I have to do if I wanted to put a set within another good set you have to use a function called frozen set What is a frozen set? Here we open parentheses We open as to create a list and here we do the same but inverted we close the list and we close and this also creates a set but creates an immutable set that can be frozen enough to be findable then Now if I update this and run the program I'm messing with what an asshole set 1 I update and if I run the program it will say that now I was able to put a set within another set and indeed this set behaves like a normal set it is literally a normal set here the same I had set a set, so in reality this line is never always running this is running but good if you want we can go back and verify that this is true just good I'm going to copy all this and I'm going to go back to everything so you can see I'm going to put set 1 for that I can run set 1 and there they see me Says you can't put a set inside well I'm going to delete this that is here now yes and I'm going to do this because as I say before It was set, that is, this was not running this was not running was I was running this so let's see explain it now see that it throws me an error yes I paste it this way and I put the frozen set I update and it no longer throws me an error then this is the way and the answer that comes to us to give frozen set that is to put a set inside another set since after this course is coming a course artificial intelligence does not hurt to work with set theories this is important since if we want to work with a set if we are working with sets we need understand the following in set theory we have on the one hand what has been a set and on the other hand what has been a subset which is like grabbing a pair of data from the other set and create a set aside, that is to say, if I, for example, have the set a that has the data that we are seeing and also I have the set b that has the data that we are seeing a is a subset of b because a we have only three pieces of information that are in the set b only that in b we have more sets then a is a subset of b because b has everything a and more is precisely is set theory a set that includes another and also has more data is a superset of another set, that is, we have two perspectives the first perspective Is that the is a subset of b then a is a subset yb is a set while we can have the other perspective that is to see ab as a superset of aya is a set is depends of the element that we take as reference is say if we say that b is a set a is a subset of by if we say that a is a set b is a superset of a this It is the theory that they have to understand because if we want to work fairly with the functions we have to see exactly this theory which is quite interesting so we are going to put it into practice and we are going to come here putting set theory let's go to create the set we are going to create again set 1 and set 2 set 1 goes to be equal to a set of numbers let's to put 1 3 1 3 5 and 7 numbers that are odd and set 2 we are going to put 1 3 1 3 and 7 more or less we are going to put these three numbers how do we verify if a set is a subset of another good we say result is equal to in result true or false is going to be stored because you are functions that we are going to use now return us true or false boolean values ​​say set 2 is a subset of set 1 this function This method returns that data, that is, set 2 is a subset is subset is subset means is a subset of set 1 let's see what he answers we are going to put 4553 03:20:47,55 0 --> 03:20:49,180 print result and we are going to execute this and it is going to tell us true because because is a subset because in set 1 we can find 1 3 and 7 but if we now change the numbers and say che a ver set 1 is a subset of 2 not because set 1 has more things then no, that is, everything that is in 1 is not in 2 but vice versa yes that is to say everything that is in 2 is in 1 then 2 is a subset of 1 we update returns true then Here we are going to verify if it is a subset another way to check if it is a subset or it is not using the lesser or equal here we put result is equal to set less than or equal to set 1 this works exactly the same that is to say this function and subset or this little sign is the same because what it verifies is that these numbers are greater than or equal to these It's simple, it's a way to verify it, ok let's verify it let's comment on this line let's see if it works for us it returns us true effectively because it is a form of verify I invert it again and put 1 and here I put 2 it works there we are it works and you tell me no because it is because of the quantity of data is not because of the amount of data because if I give you less here, for example 5 minus 10 for example if I just put minus 10 technically the sum of all of these is less is not for it is not for the sum I update the same it keeps giving me true so it has nothing to do with that the numbers I add up and nothing not at all is not that is a way to compare if it is a subset or not is a subset so these are two ways valid ways to check if it is a subset and then we have the The way to verify, let's copy and paste, if it is a superset, in this case it is superset And now we have to check it backwards, the sign is backwards Here we check if it is a super set, remember that this depends on the perspectives Note that it is the same, here simply we invest it If we take this one, the little head points to here If we take this one, the little head points to here So they have to check the prospects, don't forget about that The difference is that we don't use superset like this, but superset we use like this That is, if we want to verify that it is not a subset, we put it backwards To verify that it is a subset, it is say, to verify that it is exactly equal to this, is this the function And in this case, exactly the one that works is the sign backwards That is, here it has to be less than or equal to that, and here it has to be greater than I mean, the opposite If we update here and ask you to show the result, which will show us this, not all the others It's only going to show us, it always shows us the last one we put Here he is going to tell us that it is false, because together 2 is not a superset of set 1 Set 1 is a superset of set 2 So there it works, exactly what is here is literally the opposite to this that is here It is to verify the opposite, it is nonsense Superset equals this, it's an interesting way of looking at it Well, what if we want to check only if there is a number in common, we check it again this form Check if there are any numbers in common For that we use isDisjoint, same result set 2 isDisjoint set 1 So in this way we say, che, is there any common results? And here he is going to tell us false, why? It is not different, because as long as there is a result in common is already the same Here we are going to put 2, 4, 6, 8 Note that there is no element in common Now we execute it and it returns true, because They are different This will be true only when the sets that are being compared do not have any equal number If there is only one number, only one number that is the same, in this case it is 7 Currently it is going to give me false, because there is already a matching element When only one element matches, it already leaves to be equal That is, it is no longer completely different And this is no longer true So there we just made a comparison and we have just effectively seen if this works or it doesn't work So let's go to the dictionary section now, we also have a lot to learn ok, easy, let's come here and create new file, dictionaries.py and we are going to put it also inside variables 2.0 and move dictionaries, as you already know, can be created as a json in javascript or with the function dictate creating dictionaries with dict and here we put and put the same dictionary dictate the difference is that here what is going to ask is a set of key equal value, that is, the structure to create a dictionary that's how to put for example name the same lucas, comma, last name the same dalto in this way we create a dictionary and if we come here and we give print dictionary when this is executed it will throw us the dictionary here if you look we have name: lucas, last name: dalto because indeed it is as if we created variables in here well, that is the parameter that this receives function which effectively gives us the creating a dictionary is a different way to create a dictionary Instead of creating it that way, they remember that they we create like this name:lucas, instead of creating it this way last name: dalto I mean, we don't have to believe it like this form we can create it this way, you can choose the way you prefer don't forget that the way we create empty data is with this we cannot create empty dictionaries if we use the way to create it like this if we want to create empty dictionaries, the we can use with this formula we cannot create empty tuples unless let's use tuples, the function we cannot create empty lists unless let's use list It worked, but it's important to understand this in dict it works the same i.e. the tuples it can not be lists cannot be keys because they are fairly iterable Here we are going to see for example, the lists are not can be keys because they are mutable if I now here for example I create a dictionary same dictionary, here I try to create the dictionary with a list for example If I do it with a tuple, if you look at it, I I can do with a tuple for example, I don't know, dalto and stale, here I can put two points, haha I update, this shows it to me, the tuples can be keys we are literally putting a tuple like key but if I do it with lists, that is, I replace the parenthesis by the bracket that makes the ready Now I get an error because it is not hashable, what we saw before it doesn't work nor can it do it, nor can they be for example the sets If I want to put a set here, neither it leaves me because it is not hashable here I could put for example a frozen set If I put frozen set here, for example, here I put parentheses, here I was talking like a list here the same, ready, here it goes, yes I am i update it Now if you let me just put the set, frozen set do not forget that it is very important there it goes, there I put it, the lists cannot be keys if we use frozen set to put sets, not? there we have it, perfect then another way to create dictionaries is with from keys creating dictionaries with from keys This is a function that allows us to create a dictionary with all none values that is, without value, unassigned, how do we that? simple we put, dictionary will be equal to from keys but here what we do is create for example keys, I don't know, name if we now execute this, it will tell us that well it's wrong why does this have an error? ok, the mistake it is because this is a method of dictionaries so we have to put dict, which is the dictionary value, dict is a type of fact dict, period, from keys and here we create it, we update and run the program now look at who created us and the value is literally none, it is n, two last name period or last name colon why are you throwing my name? it's interesting this because it is making me that each value, notice that each letter, name each letter will be equal to the first one that i put here how do we avoid this? just why does this work? because this iterates the first element, it's a iterable so we have to put a list and now yes we close the list and when we run we created name, two dots none, last name, colon none and if we keep adding data, subscribers and else this basically creates all the data for us and all values ​​none Here, for example, we say show me a dictionary, name, it will show us none dictionary, surname, will show us none and so with any data that we ask for this is because it is a way to create dictionaries with all values ​​undefined It is interesting the technique that in which we can create a dictionary just just by passing a text string what we just show For example, here I pass a single chain of text that says abcde I touched this to take out, it doesn't go, there it goes I run this and now I create a dictionary with abcde all values ​​with none but abcde, no I know if you noticed even if I do as I did before and put another value such as value 2 what it does is equalize me abcde and always I set it equal to value 2 by default it comes like this, so if we we pass a second value what it does is always equal to this then the first data is an iterable, something that we can iterate and the second data is what we are going to equal from keys, it's interesting so in this case it will be for example equal to some fixed value with two parameters and then we can do the same here Here we can pass a list for example, we can put first and last name for example and here I'm going to put I don't know, I don't know and here below I simply give you the name and surname and the default values ​​will be none default value, none then we are going to change its place, changing the default value to I don't know Here we have a name, I don't know, last name, no HE and it works the same, this is how this one works section of dictionaries now, how can we just iterate a set for example? because yes, the lists, if you remember, the dictionaries we can call them like that we say for example name and call the value say for example tuple, one and it shows me the first data we say lists, one and he shows me the first fact but the sets, how can we see the value of a set? How can we, for example, call two? how do we call two? or how do we get it to show me the seven? only the seven for this we have to iterate it, because the sets are iterable but what is all this iterating? about what am i talking ok? We will see all this in the next section what is the section of loops so let's see what loops are ychain now we are going to see loops Now we are going to see loops OK, yes it is recording we can start now we are going to see loops can we start now we are going to see loops can we start now we are going to see loops Exactly, it is already an example of a loop. Well, already leaving the joda a little aside, That's actually a loop. Repeat the execution in a controlled way of a code. Well, for starters we need to understand what it is what comes being to iterate. Because loops are these statements that allow us to iterate an element. Can everything be iterated? Well, not. Not all elements can be iterated, but than only iterable elements. Now, what is an iterable element? Well, an iterable element is an element that comes, let's say, has an iterator that defines how to iterate. Not all elements are iterable. But basically an element can be iterable when you have something that defines how you are going to iterate. The first iteration is going to be from here to here. The second from here to here. The third from here to here. If you don't have anything tell me how you're going to iterate, that is, how are we going to repeat the code and in what way are we going to go through everything the element, because that is what iterating is, it is traversing an element, we traverse an element in bits. Those little bits and the way they go to skip those bits They are just defined by an iterator. So the question is what are the iterable elements? Well, by default, the lists, because they have various elements. In other words, basically, a way to iterate a list is first one item, then another, then other. The same in the tuples. Item 1, Item 2, Item 3, Item Four. They have elements to iterate over. That is, well, the entire tuple is data. And if the tuple has five elements, We do five iterations, one for each element. We can break the complete tuple into five parts and we're going to iterate and repeat code five times, one for each part of that code. Why? Because it's simple. The lists are already defined to be iterated that way. Strings can also be iterated over, We are going to see how, the dictionaries, the sets. So let's tear into this whole world and let's start. To begin we have just the first loop, the first type of loop which is FOR, which is the most famous of all loops, the FOR loop. And FOR is a loop that allows us to iterate, create an iteration. So let's start working with FOR. To start we will create a new folder what's it gonna be LOOPS and a new file to be called ITERATE-LISTS.PYTON And here we are going to iterate lists. But, let's see, before we start iterating lists and use the FOR loop, in fact, we can start right now. I want us to fully understand the concept of FOR. Rather, the operation of FOR. In Python, loops are FOR IN. In other languages ​​we have the FOR that has three conditions, right? That is, I equals 0, and as long as I is smaller that much, I more more, or I less less. That famous cool way of making loops. Python makes it completely simple. And Python uses FOR IN. What is it now that it is a FOR IN? The FOR IN is a loop that just what does is create a variable that on each turn is going to be equal to that bit of variable which we are equating Ok, let's think better of ourselves. Let's now see it in a voice-over. Ok, suppose we have a list animals which will be equal to dog, cat, parrot and crocodile. A list with four elements. Pretty simple so far. Now how do we iterate this list with FOR? Simple. First we say FOR animal in animales. We put the two dots and now we can execute the code. The question is, what is the animal going to be like? Easy. The first time the code is executed, animal will be equal to the first element, i.e. dog. In fact, if we use an animal print to show what the variable has animal inside, What is dog going to tell us? When he finishes going around the block, will check if there are more elements in this ready. If there are more elements, then it becomes to run. But now, animal is equal to the next element, I mean, cat. In other words, in this round he is going to show us cat. Finish executing, ask again if there are elements and there is the parrot. So, in the next turn, animal is same as parrot Again ends the execution and asks if there is another animal And yes, there is the crocodile. So run back and now animal It's the same as a crocodile. Now ask again and there is no more animals. Then the loop finishes executing. And now yes, we move on to the next instruction. So ultimately, The program would work as follows. We create the list then run the loop as many times as animals have, and when you have no more, the program continues with its natural flow. It's pretty easy, okay? Let's put it into practice now iterating a list. That's why we created that element to iterate ready. Let's iterate around a bit. We are going to iterate text strings, we are going to iterate dictionaries, Let's start by iterating lists. Everywhere, if you want to know what my temperamental, bodily state, forgiveness. I'm fine. I'm fine. Now I'm not setting myself on fire. That is, they can rest assured that, now there is no more 34 degrees. Let's see how much there is now. It's 32 degrees. Ah, on the other hand, we pass to finals. As I told them, they saw that I told them we were going to go to the finals. On December 8 I told them, we are going to win quarterfinals and we are going to win semis. And now the finals are coming. It's obvious to me, France is going to win. And there we will have the grand final between these two countries that they really deserve to reach the final. Which is Argentina and France. And the final winner now yes. That beautiful. It will be Argentina. Okay, enough of the chatter, enough of the bullshit. Let's start writing the code. To begin with it is simple. We are going to create a list called list animals, which was how we had it there. And we are going to create a cat, a dog, a parrot and a crocodile. Fine, easy. How do we go through this list? Well, we put a for animal in animals. Two dots and now we will see that if we put prints animal, when we run this code. Ah, I listed the same animals, what a salami. Sorry, animals, I wanted to put animals the same. Now yes, I don't know what I did. We run this code, cat, dog, parrot, alligator. Well, actually we can now say the variable animal is equal to two points. The variable, let's go, close and put the F forward. If we execute dice, now the animal variable is equal to cat Now the variable animal is equal to dog. Now the animal variable is equal to parrot. Now the variable animal is equal to crocodile. It's easy, because animal is going to run as many times as variable. You know, if we now add a new variable to it, for example, fish and execute, below fish is going to be added. Ok, and if we put it at the beginning, let's go to put it ahead of cat and we put a comma, there it is, it will be executed first fish. This is how Google For works, it's easy. Animal is a variable to be created only to be used inside here, that is, inside this block code, inside this block of code. That's why it's good, because in this way we can tour it. That is, if we, for example, want go do things like... I don't know, let's create another list that is numbers, is equal to... Let's create a list of numbers. 10, 62, 12, 70. And we want, for example, to show all the numbers and multiply those numbers by two, for example. Well, animal equal result for two. In this case we are going to change the arrangement that Lets put. What's more, we are going to do one thing, this is what we are going to leave it like that, just like it was. Ok, there it is, and we are going to put touring the animals list. And now we're going to come down here and put, for number, in numbers, two points, and here we say. Let's add these numbers that we had added before. Let's add any other number now. And here what I am going to do is going to be, result will be equal to number by 10, for example, we multiply it by 10 And now let's say, print result. So if we update this loop, we'll to give 520, 160, 140 and 720. What are these multiplied values? for ten. 52 by 10, 520, 16 by 10, 160, 14 for 10,140, ​​72 for 10,700. 4925 03:38:09,130 ​​--> 03:38:12,640 And in this way we can do many things, because suppose that I don't know, we have a list with items, or we don't have items with objects. We have an object and we have to show, che, Let's see, show me what are all the products that you have available. And I have available dad, I have available egg, then all available products add to a list And there we show them. We have potatoes, we have eggs. And so, it's easy, it's really interesting the way that we can work with elements like this. Later we will see many similar ways to work, but this is an interesting way to go ready. It's actually the way to loop through lists, not an interesting shape. I only have many deaths, they only have noticed. I mean, this is really very interesting, o It is very interesting that we learn this because it's a death of mine, but it is the way to do it, let's say. This we are going to add a comment that be, traversing the list of numbers and multiplying each value by 10. Let's see, each value multiplying it by 10. And there more or less we were left with this data that it's here. Ok, so far everything is fine. Now the question is, what would we do if we would like, let's say, iterate over two lists? How do we do two iterations at the same time? Well, the way is simple. If we want to iterate two lists, we can put a for inside another for, which are nested for, or two for together. But the way is using a particular function what is zip Let's do. If we wanted to iterate both lists together, How would we do? Well, first the lists have to have the same number of items. In this case, for example, we have fish, cat, dogs, parrots There are five elements. 4960 03:39:29,130 ​​--> 03:39:30,569 Let's go now to the fish element. Thus we are left with the same number of elements up and down. Here we put number, comma, animal, for example, in. Here we put zip. And here we list one and list two. In this case it would be animals and numbers. Here we put two points. And below, if you pay attention, we can put print traversing list one, two points. And here we add the animal. Here we put the F. And here we put number. And below we put animal and list two. If we execute this, here if you look at going through list one, two. Going through list one, going through list two. In this interesting way with the function zip, we can loop through two lists at the same time. weather. This is very interesting. I'm going to delete the above quickly. We update and if you notice, we just go to display this code. It's basically a loop in which we can access the return value of the first element in both cases. Then the second round will be the same to the second value in both cases. The third turn will be equal to the value. And this is really excellent. It's excellent. The truth is that it is widely used and I know I recommend using when you want to iterate two items from the same list. We can iterate two and three. Here also if they have another list, too with four elements can put some simplification from list three. And here put the complete list three. And it also works with more than two lists. This is interesting. Literating two lists of the same size at Same time. So we iterate two lists at the same time. This feature is interesting. The only thing is that this is iterated at the same time. That is to say, it is not first all one, then all other. It's one, another, one, another. List one, list two. List one, list two. That is, item one, list one, item one, list two. Item two, list one, item two, list two. Item three, list one, item three, list two. Item four, list one, item four, list two. And so. Well, then also what we can do to iterate is to iterate using the function rank. That is, if we do this for example and use the range function. Iterate number in... Here we can put anything, whatever we please. But the interesting thing is always to put names that match what we're doing. Iterate for num, we are going to put instead of number num in range. And here if I put from five to ten. This is basically going to run numbers from the five to ten So I put a colon here and say print num. What this is going to show me, basically, It is what we are going to see below all the others. It's five, six, seven, eight, nine. If I define two parameters for range, the first parameter is where it starts. And the second where it ends. Let me explain, here I put twenty. So I start in ten, finish in twenty. Come? Ten, eleven, nine, up to nineteen. Twenty never counts, it's the first one included and the last one not. Let's say twenty numbers. It's ten numbers, sorry. In other words, we go from ten to twenty. Twenty we don't count, ten yes. And if we don't put two parameters, only we put one It starts from zero to the number that we tell it. Come? Zero, one, two, three, nineteen. If we tell him that we want up to five, It goes from zero to five. If we do not pass any number forward and we only pass a number instead of two. The only parameter means from zero to the let us tell you Now you can say, ah, stop, to. In other words, if I suddenly want to go a list, I can also do this. I can say, for example, numbers and I will put lock it in len. So, if I have here the amount of numbers, what I can do here is say numbers num. So here he is going to tell me exactly what same, fifty-two, sixteen, fourteen, Seventy-two. We are traversing a list by index, why? Because the numbers show us the amount of elements that this has. It has four elements. Ok, so start from zero to four. On the first turn this is going to be zero and zero numbers equals this. Numbers one equals this. It is a way of traversing a list, but this shape is not optimal. Then we are going to put non-optimal form of traverse a list The correct way to do this is with the function enumerate. We are going to put the correct way to go through a list with its index. The correct form is for num in and here we put enumerate numbers. So if we come down here, now num will be equal to two variables. Num is equal to a tuple. If we tell it to show us type num, they go let's see what number Dude, now yes. They are going to see that num is equal to... Ah, I didn't show it, what a jerk. Print, now yes, we update. Tuples, are tuples. But what is he going to give us back? What tuple returns us? Well, let's see what tuple it returns. If we update, it will return us that the tuples are 0, 1, 0, 2. In other words, the first value that returns us is the index. The second is value. So if we want to access the index of the element, we just do this. Here we have the index. 0, 1, 2, 3. And if we want to access the value, we put the one. And if we want to access both, simply we say that index equals num 0 and equal value number 1. So now we can display on screen, index is a colon. And the value is, I copy and paste this variable and replace index by value. So I run it and it tells me, the index is 0 and the value is 52. The index is 1 and the value is 16. And this way is a correct way. Because if you do this, you're going to burst out laughing That is to say, outside of jodas they are going to recharge laughing. Let's leave that for other programming languages. that they do not have the possibility of having functions as enumerate. This is the correct way to loop through a list getting its index. Let me explain if you need to get the index of the list. Because sometimes they need to get it. It is very useful sometimes to get the index. Well this is the way. And finally we can also use the else in the for. That is, for else. Using the else. If at the end of a list, at the end of a for, at the end of a loop, sorry. We add the else to it, we are going to put it same. For numbers, or number, in numbers, two points. Print, running the last loop. Value, current colon, space, number. We put the F forward. And below we put the else. If we put the else here, it won't do anything. They have to live up to the for. That is, the for here below ends. So we put the else as if it were a if. Instead of an if, an else. Else, two points. And here we are going to execute print. The loop ended. So we run the code. And running the last loop. Current value, current value, current value. The loop ended. The else inside the for will be executed forever. In fact, without numbers even. Numbers is an empty list. When we execute it, even though there is no data. Notice that running the last loop no this. There is this here, which is from the loop previous, which is the one here. Not even. Because it's not running. Now the animal variable is equal to... These did not execute any of these loops. Because all these loops iterate through numbers. And if the number is zero, none of me he's going to walk it. This always runs the same. In case there are no elements to traverse. If this is not going to walk me, then what shows me the else. That is, the else is always displayed only once. Only once and it's at the end of the loop. It has ever been executed or not. It shows me the same. It's like something that will always show me the end the loop. In fact here in the else, if we try for example the value number. We come here and put number. Else is not going to show us anything. Literally number tells me that he is not there defined. Using the for else. There we are, now yes. This also works exactly the same with tuples. Just like we did this, we can do it too with the tuples. That is, any of these values ​​can be replace by a tuple. They are going to see. If I here for example, this that is here. I'm going to copy this. And this above too. I am going to copy this here. And I'm going to go back so that we have numbers up here. There it goes. And down here I'm going to paste this. There is. If we replaced this with a tuple. All loops would work exactly same. I close it there. I update and if they are fixed. The same. It works exactly the same. I mean, it works the same. So I'm going to replace him. Iterate lists. rename me Lists. Bar tuples. there we have Iterate lists and tuples dot py. This works. Here below everything I will put everything. The above works exactly the same for tuples. So there I am. And there I have everything as it is. It encompasses lists and tuples. Now we are going to create another file to iterate sets or sets. Iterate dot sets py. The same. If I come here I copy this. Let's copy all the code. Let's paste it here. Let's give control h to replace. Let's replace. List by set. I hit enter and there it was replaced. And I'm going to do it like this. Let's see if it gets replaced. That's it. Now yes. All lists have already been replaced by sets. Everything that says list has been replaced. Only now we are going to replace it. Let's put together. And we are going to verify that it actually works same. Let's see if it works the same. update. And now I get an error. Because in this case we cannot act by going through sets like this. Here if you look is not optimal. Let's save this way of doing it. Let's update it. And now it works. Do you see why it was not an optimal way to iterate loops? Even if we wanted to convert a list or a tuple in a set. We can't use that function. Instead, we can use the enumerate function. Although we say the way to call a data in a set be like this. So it's important to understand that the sets basically iterate the same. They just have some differences like the above that are important. We are here, for example, going through two sets. The same we traverse two sets. So tuples and lists. So that we also have the shape in which that we can walk it. That is, we are even going to delete this element. Easier. Let's delete this element. We are going to rename this element that is here. And we are going to put iterate elements. Because now that they know that everything is iterated same. What am I going to put it works exactly the same for tuples and sets. And up here we are going to put it does not work in sets. And now we are going to see how a dictionary. Because this yes already the dictionaries work different. Dictionaries have something quite particular. Let's add the same. Iterate dictionary.py. And to iterate a dictionary we do it the following way. First we create the dictionary. Dictionary equal name, colon fluca, surname, two points high. I sneezed like a beast. Let's put Dalto and Lucas. We are going to put subs of subscribers, two points, One million, one, two, three, one, two, three. And here we add the corresponding commas. Here we have the dictionary. If we show it on the screen it shows us the dictionary. Now how do we go through it? The same. For key in dictionary, colon, print key. Let's see what it shows me. It shows me key. Because the key is the key. When we put key in the dictionary what we is showing is only the key. How do we get it to show us the values? Or how do we get something? The same. We are going through the dictionary but no shows us the value. It only shows us the key. And here if we put value it will not change us nothing. The same. Because this doesn't change anything. It is exactly the same. We put value. And we update and it's the same. It shows us the same keys. Nothing changes. The way is using the point items. Do you remember that before we used the point items? And I told them that this was to iterate the element. It doesn't seem to work at all but allows us to iterate. Well, if we go to F5 now they will see that we are iterating the element and we access both. This returns us a tuple with a key-value pair. Exactly what I was saying before. For this they now understand that we are using items. If I, for example, now say key. In this case it would be data. Key will be equal to data. Zero. And value or value will be equal to data. One. So if we update there we have If we show them on the screen. Print. The key is colon space. Key. And the value is a colon space. Value. We update and run this. When I say we update it is because all my life I said update. But actually it is that we run the code. We run it with F5. We give it run run. I update it. We run the code and there we have this. The key is name and the value is Lucas. The key is lastname and the value is dalto. The key is subs and the value is one million. In this way we are traversing a dictionary. Then we put traversing dictionary with items. To get the key and value. And we're going to do exactly the same. But we are going to get the items from the one above. The key is key. And it's only going to be the same as here. There it goes. Traversing dictionary to get the keys. With this we get the keys and values. While only above we get the keys. That is, here we obtain only the keys. And here we get the keys and values. There we have two different ways of traversing a dictionary. Interesting, right? Let's see something next. If I iterate the element. I'm going to create a new file here. Which will be masiterations.py. And here we are going to do something interesting. We are going to create a list that will have for example names. Or fruits. A list of fruits that will be equal to. Banana, apple, plum, pear, orange, pomegranate. Not the ammo but the grenade fruit it is delicious And peach. Now if I do the same. For fruit in fruits. Two points and the same. Print fruit. I walk fruit. Okay. That's it. It runs through me and shows me all the fruits. But suppose that these are the fruits that I'm going to eat. So we grab and put. We put it in brackets. 5317 03:51:49,130 ​​--> 03:51:51,279 We put the brackets between braces. Here we put an F and here we put. I'm going to eat one. I'm going to eat a banana. I'm going to eat an apple. I'm going to eat a plum. All fruits are eaten. 5324 03:51:59,130 ​​--> 03:52:00,630 But suppose that suddenly I say. Che look but the truth that. And I don't like the grenade. And here what I have to do is say what Next. If, okay. If fruit equals pomegranate. We open condition. And here I will put continue. What does the continue do? The continue says good. The loop is going to end the loop and we are going to to jump. Everything he does. Because they saw that the loop goes around several times. Round 1, round 2, round 3. If it has 5 elements, it does 5 laps. Round 1, round 2, round 3. Suppose that in each turn there are 5 instructions. If statement 3 is continue. And continue runs. Everything else does not matter. Skips to the next lap. So I update. He tells me I'm going to eat all the fruits. But grenade disappeared. Because when fruit is worth pomegranate. we don't say I'm going to eat a grenade. We skipped it earlier. And now if you go to the next fruit that is. Peach. And it says like a peach. If we tell you here I really don't like apples. I do not like apples. We execute. And now it runs. And he eats everything except the apple. Okay. Because when the fruit is an apple. He doesn't eat it. Then we move on to the next round. Because the fruit is eaten here. But we don't want it to come here. But we want the loop to keep running. So we pass. Now suppose that here we are going to put. Preventing him from eating an apple. With the sentence continue. Now let's imagine that suddenly. We know that every time we eat. A pear. For example. Let's run the same code. There is. We know that every time we eat a pear. Every time our body receives a pear. His belly hurts and he can't continue. Prevent the loop from continuing to run. How do we say Well, look, that's it. You ate a pear. It's going to make your stomach sick. Do not eat more. Well we tell him look. Ifa fruit. Same pear. Two points. And instead of telling him to continue. We are going to tell him. Break. what break is it End the loop here. If you had to do seven laps. And you were on lap four. It doesn't matter. The other three. You don't give them. The loop ends here. And you can continue with what comes below. What comes here What is finished loop. Okay. So if we run this. Look at what you eat. Even a plum. What is the plum that is here. And then the pear. He doesn't eat it. Let's do it backwards. Let's make him eat the pear first. The pear is eaten. And then we execute. The conditional There it goes. The pear is eaten. And that's it. Term. Enough to eat. And now the loop ends. If I took the break. They will see what happens. Not. The lift. The lift continues to run. Let's get the full lift out. Without the break. It eats everything. Finish the pear. And then he eats a grenade. Leave a grenade. And a peach. Now with the break. He doesn't get to eat anything else. After the pear Because what the break does is end all the loops. Then we have an interesting form. What is integrating text strings. Okay. What are we going to put? We are going to remove this. We are going to integrate text strings. Oh. Another interesting thing. It is that here we put the else. Two points. When the loop breaks. This is interesting. For this you ask me. The difference between. Che. But if the else. It is the same as putting a print here. Then. So that I do it. With what happens. That with a break. When the loop ends in a break. It skips everything completely. The else does not execute it either. That is the difference. That when he finds a break. It doesn't run anything else. When you can't find it. If you keep running it. And when the loop ends. Run the else. That is the difference. Between using an else. After a for. And put the conditions alone. what happens It's that else. In case you find a break. It ends and doesn't run either. The else. It doesn't run either. This is important that we will expedite it. Well. And then we need to loop through a string. Let's loop through a string. Travel. A text string. When one speaks of touring. It is to iterate. When you go through something. You go through a list. You are iterating it. You walk a set. You are iterating it. Let's loop through a string of text. The text string for example. It will be. String is going to be equal to . Hello Dalto. How do we go about traversing a chain of text? Well. The text string. Some what they will understand. How we go through it We don't walk it. Word by word. We go through it. Character by character. For. Letter. Or character. Yes. Letter. In this case only text. If we are going to put lyrics. in. String. Two points. And here we say Print. Letter. And here it basically shows me. Hello dalto. Why? Because we are traversing a chain. In the second. Letter is worth O. In the third. Letter is worth L. And in the fourth. Letter is worth A. In the fifth Letter is worth an empty space. That's why he showed me. An empty space here. Because this also counts. And then we can also do. Booklets for. In a single line of code. That is to say. Suppose I have A list of numbers. Easier. Let's create the list of numbers above. Numbers. It will be equal to Two. I have the five. I have the eight. And I have ten. And basically. This is the amount of bitcoin I have. They are bitcoins. These are bitcoins. And suddenly. I want to duplicate it. The amount of bitcoins. As I do? Simple. For. In a single line of code. How do I do that? Simple. Create a list as follows. Numbers. Duplicates. Same. And I'm not going to create a list. That adds each value. Because the original form would be this. Would. For. No. Number. And numbers. And here we say Well look. Let's create a list back here. And we put Numbers. Duplicates. Same. List. And here we add it. Number. By two. Then. At the end of this list. When we show eg. Numbers. Duplicates. We show it with a print. We update. And he's going to tell us. Yes Yes. Before the numbers were Two. Five. Eight. And ten. And now there are four. Ten. Sixteen. And twenty. We literally doubled the numbers. But we can do this in one line of code. How do we make this easy? Simple. Well. What we do is. Erase everything. Okay. So this. X By two. And here we finish the forum. For. X in. Numbers. Here what we do is tell him that. X It will be divided by two. It will multiply by two. And the value that X will have. Now. It will be. This X But X multiplied by two. And now. Simply. We show. Let's say. Well look. Print. Numbers. Duplicates. Let's see what it tells me. And now he tells me The same. The same result. I've got hiccups. Forgiveness. How did we do this? Very simple. And went. A for. In a single line of code. Is the same. Here we can say For example. If we wanted to divide it by two. We divide it by two. Numbers divided by two. And divide by two. That is. The mathematical expression comes forward. And then comes everything else. This is for doing fairly simple things. Why. Let's say. With this we are defining the value of X. For example. If I said X Same. X For. Not. Is. We raise the X to. Cube. Then. All values ​​are cubed. You see? All cubed. And it's an interesting way to do it. In this case we are going to put Two. And we are doubling the numbers. And there we have. Literally. We double. The numbers. And we already have. Now yes. More or less everything that has been the functionality. These are the things we can do with a loop. These are things that are used a lot. And it's okay that they have this. Because they are interesting things. Relevant. And that they will serve you a lot. Now we are going to put Creating the lists. How beautiful, isn't it? How beautiful is this to program in Python. That beautiful. And more when they are subscribed to this channel. And they like it. And they comment on the video. And they tag me on an Instagram list saying. Che. I'm looking at your python course. The truth that is serving me again. It gives me an orgasm. Che. Then there is one more loop in Python. What is the loop while. That this loop already uses conditions for run. I mean. It's not like it loops through elements. But. It is executed whenever a condition is true. That is to say. It will always run. As long as the condition is in question. Be true. Let's see how While works. And we will use it a lot. Let's see the use of While. The while, like the for, is a loop, that is, it is a sentence that allows us run a code many times The difference is that the for loops through elements while the while will always be executed for a condition to be true So the while can be infinite, that is, for example, this code goes to execute while the number is smaller to 5 In the first round, number is equal to 1, in the second it is equal to 2, in the third is equal to 3 In the fourth it is equal to 4 and in the fifth it is equal to 5 So now, in the fifth, we are not going to run the code Let's continue with the following instructions, because the loop has already been executed long enough since the condition is not met So we're not going to keep running it This is easy, we are going to create just a loop that is loopwhile.py And we are going to do a test, we are going to put e.g. number equals 0 or counter There it goes, counter equals 0, there we are And now what we are going to do is while that the counter is less than 10, let's run this code So let's say print counter and this it will show us an infinite code Literally, this code is infinite, it is runs and runs and runs Let's stop the program, there it goes, we finished it to stop Why is this going to run infinitely? So what we can do here is add it Counter plus equals 1, as we did before In this way we are adding 1 to the counter So on the first turn, counter goes to be worth 0, but here it will be worth 1 So on the second round, counter goes worth 2 We add it, it will be worth 3 We add it, it will be worth 4 And every time I turn around, counter goes and adding When counter is 10, it will no longer be less than 10 It will be equal to 10, not less So this condition is no longer fulfilled. and the while finished executing So here we are going to put print, the while It ended We update, be careful when you use that infinite loop Because the whole computer can titate them Luckily my combo is a powerful combo It doesn't have to be that powerful, but just you have to hit the pause button And they solve it, because if they can't lock There it is, it runs 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Until the 9th and ended Here we tell you that until the accountant be equal to 16 This runs 16 times From 0 to 15, that is, 16 times When the counter is worth 16, he finally reached In fact down here we can say print accountant And now counter is worth 16 Why? Because I add it a lot of times And he did In fact we are going to do one thing First we are going to add the value and then let's show it There it is, first we add it and then we show it And now it's going to go from 0 to 15 to 1 to 16 This is how the while loop works This piece of code will be executed as long as this condition is met So we execute it, we ask it again Is it still fulfilled? yes then we turn it to execute Is it still fulfilled? No, not anymore we run it more And there the loop ends This is how the while loop works Now we are going to add the comment As long as the condition is met The loop is to be executed There I add a comment that is The condition is verified lap after lap For you to take into account Turn after turn the condition is verified And there the while loop works There we are, here we are creating a counter that is going to be added And there it works, there we have the program finalized This was the loops section It is something the truth that quite simple And if up to now they reached this point of the course I congratulate you, I congratulate you, but I recontra you, I congratulate Ok folks, now we're done with this. Let's go to the end of this section Before moving on to the practical exercises 2 And to the functions section That is, we have to see functions before to advance All we've been seeing now print is a function type is a function Zip, set and subset We were looking at a lot of features But how do we create our own functions? How do we make our own pieces of code can be reused? How do we make ourselves have our own functions? Well, that's what we're going to see now In functions section Well, now we come to a section that is of my favourites. We are talking about the functions section, which is really one of my favourites. More than anything because what we are going to be able to know how to do after this section is a craziness. I want to take a little break here to give them interesting news. And it is that if you go to Google now, enter to my Instagram profile, where it would actually be nice for us to grow up plus the number. Because come on, we're going to grow the community, let's make a much bigger community. If you are viewing this course and at any point It helped you, go follow me on Instagram. It doesn't cost you anything and it really is a excellent contribution. Also there I tell everything, when they give each other the artificial intelligence course will know first out there. When you stream to solve your Doubts they will know first there. Everything you do will be understood here. In fact I tell them and I keep them used everything and we can interact. And people know it, in fact it is not a joke, let's go to messages. Here you can see that all the time and everything the time we interact. It's real, you send me many messages because they know that I answer them. These are all the messages that you sent me they send And even if it doesn't seem like it, I take the time to read and respond to them. The issue is that sometimes I use a lot if I can't, but eventually I always see them and respond. Come all this a day ago, look ago one day, just one day ago. And that there are other requests that are the hidden requests. That in hidden requests, that's where most people arrive, in fact. So good nothing, the next time you send me a message, if you don't answer understand which is because of this In fact, if they pay attention and are detailed, they go Note that here it says dalto store coming soon. I just want to tell you that I didn't say anything, no I spoke nothing, I did not warn anywhere. I only put it on my profile exactly three days. Well, anyway, let's create a new folder which is going to call functions. There it is, we created it and well the same, we created a file. I don't know if you remember that when we started in Python, you saw that for this reason I was saying. You have to use the print function, which is for display them on the screen. Or for example the type function, which is for see what is the type of data, of the object that we are passing it Or the input function, for example to ask another user. Well, these are just functions. They are codes that are already created, that Python internal has. That is, let's say, they are codes like that already are written, functions already created by python. For us to reuse whenever we want. We use the len function, the range function, the enumerate function and many other functions which are already Python. And in fact we don't even need to understand what they have inside or how they work internally. Because we know what they do. This is because in Python there is a concept called abstraction. And basically it is that if we understand a function. That is, how to use a function and of what how it affects our program. We don't need to know how the fuck it is created. That is, let's go with other words. If we have a function called get numbers. And when we say numbers the same get numbers. And we pass it with mothers parameter. This creates a tuple with the numbers the mother who got We know what this function is for. And we also know what data you are asking for. Because we could easily pass as data sisters. And this would give us the number of the sisters. So we know that getting numbers is a function to get the numbers a group of people. And the parameter asks us for an argument that tell us the numbers of who we want get. I mean, who are these people? Now, do we know how it works? Not. Why? Because in this case it is not necessary nor does it affect the operation of our program. What matters is that you know how to use it in its entirety. That's abstraction in Python. Hide all the complexity it has. But at the same time it is easy to use the function. And it can be used to interact with the program without knowing its inner workings. Well, this is it. It is simple. It is exactly the concept. But basically now we are going to explain what are the functions. Because now we saw the subject of abstraction. And the issue of why we don't understand how that works. And that's exactly why. But when we create our own functions. Yes it is necessary to understand them. But hey, to explain what a function is now. A function is a piece of code. That we can use at any other time. No need to write the code and again. That is, we do not need to do a copy-paste. In other words, copy and paste. To use the same code. We simply refer to that name. Which contains all the code. This allows us many things. For example. First, avoid repeating code many times. 5904 04:06:59,130 ​​--> 04:07:00,350 Second, modularity. That is, it allows us to separate the program into smaller, more manageable parts. And then even be able to try them separately. And that this does not affect the program. We cannot test and modify them separately. And then integrate them back into the program. I mean, it's like basically making the program may be separated into parts. That later we can modify a lot easier. Then make the code more maintainable. It can be easier to debug. Because every change we want to make. We just have to go to that function specific. We make the change. And it will already be in all the calls of the function. Reflected that change. Furthermore, this is also a consequence of the previous point. And the same goes for the fourth point. Which is that it makes the code more readable. By having everything well separated. Whichever is easier to debug the code and else. It is as a consequence of these three. Which makes the code more readable. And if a code is readable. Good for us. Because even if you don't believe it. 90% of the time we spend reading code. The rest we write. But 90% of the time we read code. In other words, the most important thing is to write it well. Because most of the time we read it. So if we spend most of the time reading a code Why are we going to misspell it? The time that we are writing it. It's very important. While we too can create our own own code. That is, we can, instead of going around creating a code. And repeat it a thousand times. We can create a piece of code. And then execute it with a single line of code. Because that's what functions are used for. But we also have the functions that are Created by Python. As we already saw. Not that we create them. In other words, they are functions. And they are created by Python. Not by us. Those are called build-in functions. They just come built by Python. That's why they have that name. Build-in. The build-in functions. They are precisely functions integrated by Python. Let's get a new file. Let it be build-in.py. There is. And now we are going to see some examples of the build-in functions. In addition to all the ones we have already seen. Let's see some new ones. To review a bit. We have max and min. For example. Let's put a comment. What is finding the greatest number of a ready. For example. This applies to any iterable. Not? I for example. I come up here. And I put list numbers. Same. And I create a list with a couple of numbers. 4, 7, 1 and 42. and 15. There is. We have a list with these numbers that are here. If I now put for example. Highest number. Same. Max. Numbers. There is. When I run this. If they notice He's going to give me back. Well. Nothing. Because they don't use print. Let's go print. Print. Highest number. There is. I run it and it returns 42. Why? Because it says. Look. What is the greatest number of all these? And the 42. This if it were a tuple. It would also work. So don't worry. If it were a tuple. If it were a set. Come? It works the same. Because what it does is determine. The highest number in an iterable. They have to be numbers yes or yes. Or it doesn't work. They have to be yes or yes numbers. We can do the same. But with the smaller number. Finding the number. Lets put. Minor. From a list. And here we put Lower number. And if we run this. Above returns us 42. And below returns the 42. Because we run Max. Instead of Max. Let's see if they guess. If it's not Max. If Max is the highest. Which is the smallest? Main. Exact. Fine. If they hadn't guessed. I would have been quite worried. Really. There is. We update. And it tells us 42. and 1. Because the smallest number. It is the 1. If we remove the 1. You should tell us the 4. Let's see if it works. It tells us that it is 4. If we remove the 4. You should tell us it's 7. Good. It tells us that it is 7. This is how it works. The minimum is 1. In this case. And the maximum is 42. Perfect. After. Let's use another function. What is round That although we already explained it. Now we can do one more thing with Round. Rounding to 6 decimal places. If they noticed. Before with the Round function. We used a calculation. To solve problems. In the practical exercises section. Which was using a mathematical formula. To make a number roundable. With 3 more numbers. Or 2 more numbers. To later run the comma. This is what we did in the first exercise practical. But. Today we can do it differently. Because we are going to learn a new tool. The promise is not about being. Always the ones that give the best solutions. But it's about learning. Of that. Go creating better solutions. So the key to grab a number have a comma And run the comma. No need to go around multiplying it by 100. rounding it off And then dividing it by 100. Is the next. Because before what we did was this. Before we did an equal number. We had eg. This number. And what we did was We multiplied it by 100. Suppose we wanted to do 1, 2, 3, 4, 5. We were doing? We said well look. We round this number. We give you this number. Suppose we had this number. This floating number. When we used the round. This number rounded us to 12. So if I show a print. Let's stop showing these numbers here. These print here. We update it. And I put print number. There it goes. This shows me a 12. Why? Because it's rounding me down. If I wanted to show the number before. What was he doing? And first what he did was. This number. I enclosed it in quotation marks. And multiply it by 100. Round number times 100. So in this way. If they notice He didn't give us 12. He gave us 12. 35. So what was he doing here? It was divided by 100. And this way. It had two decimal places. This was how we did it. in practical exercises. I challenge you. Back to doing those practical exercises. Now using the round function. Thus. In the round function. What we have. It's a posibility. And it is to say. How many decimal places we want to leave. Default. This is zero. But if we give you two. And now we show Number. Let's see what leaves us. Two decimal places. And we have the same. Just adding a comma. And the number of decimal places. We want it to have three decimal places. We add three. And there it will have three decimal places. This is the correct way to do it. The same. But cheaper. Do as we were doing before. It wasn't entirely accurate. What interests me. It is that you do things. Good. For that reason. I am explaining them to you only now. Because I'm not interested. That you guys copy all the code. That I do. And write it down. I'm not interested. Because that's such a common mistake. That what it does is that many workers. Grab copy code from the internet. And use it without even understanding it. And see and understand its functionality. And how can it be optimized? This is a very common mistake. And you shouldn't. A... Let's say something so simple. Like this. Misuse it. Because they became bad practice. By having a non-optimal code. When it was just doing this. What interests me. It is for you to develop your logic. Your creativity. It's not copy, copy, copy. OK that's fine. You can copy. Because even I do. I copy code. But the important thing is to understand it. analyze it correctly. Investigate the features you are using. To see what problem it can bring us in the future. And optimize it. So now I give you that first task of programming. What is a task that in a job quietly could be given Even for your own projects. And it is to optimize the practical exercise one. With this function round. Making us not have to do so much calculation mathematical. To be able to round Instead we use the round function. with the second parameter. What is the parameter of decimals. And I'm not going to do that. I leave that to you. For them to do it alone. And they can get the same result. So that's the first challenge that I will leave it to you as homework. If they can do it. What is the most common? Because it's nothing so complicated if they arrived at this point in the course. I congratulate you. Because they just did their first optimization of code. They used a tool. May I never explain to them. How to use in such a specific context like that. To solve a problem that they had to is. We need to optimize the code. And they just did their first optimization of code. Without my help. So congratulations. Then we have the function ball. Which basically returns us. false. In case we pass you a zero. We pass you an empty number. Or an empty data. Let's pass it false. Or none. In other words, nothing happens to him. If we do not pass anything. We give it a zero. We give him a void. Or a fake. This is going to bring us back. false. And it is precisely the function ball. Bull. It's not really ball. It's bull. Oh well. It doesn't matter. If I, for example, pass zero. Here we are going to put Result. Same. Here we will show the result. Result. Boolean. It doesn't say it's fake. Because we pass zero. If we do not pass anything. It also returns false. If we pass him one. Empty list. It returns false. If we pass it an empty tuple. It returns false. If we pass it a none. It returns false. Do not forget that none It would come out as what is none. Not. So let's put none. The fake. Of that if we also pass it false. It returns false. Or true. In case we pass him. A number. Non-zero. True. Or one. Text string. Any string. If we pass it, for example, an array. With I don't know Two elements. It returns true. Okay. Or non-empty data. There we add. A list for example. It returns true. Or that has data. We put a nine. has true. In fact if we pass a minus one. What is he going to give us back? And if we pass minus one. It will return true. Because all non-zero numbers. They return true. A text string. We are going to pass you this data for example. It returns true. And any data. Let it be true. It will return true. Then we have another function. Which is also very cool. what is there This function that is all. Returns true. If all values ​​are true. I mean. We are talking. That the same thing that bul does. That is, if what we pass as a parameter. It is true or not. He does it there. This function that is here. Result. there. The function is all. But. Instead of checking. A single element. Check what is inside an iterable. I mean. We pass it an iterable. And it doesn't check the iterable as such. Check for example. The element this The element this Another list that we pass for example inside of the list. Do you understand? This is the data it checks. And in fact if we now tell you the result. there. there. It is not said or al. Niall. It's like there. The mixture between the and the o. It returns true. Why? Because all these data are true. Now if I were to pass a 0 here. Now it returns false. Because 0 is false. Do not forget. Up here 0 is false. If I pass it a none. None. It's false. I pass you an empty list. For example. An empty list. It also returns false. Because it is one of the data that returns us false. So this is how it all works. Yes or if all these have to be true. Then we have for example sum. Adds all the values ​​of an iterable. If I, for example, give this. Total amount. This is going to be equal to. sum. Numbers. If I tell you here total sum. When I update it will say 69. Oh what a beautiful number. Why? Because 69 is the sum of all these numbers. If I happen here for example. 30. It should return me 99. Because 69 plus 30 is that. Then. It is the sum of all the numbers. I, for example, take him out. All these numbers. It returns the sum of. 4 plus 7 plus 1. Well update. 12. 4 plus 7 is 13. Plus 1. Forgiveness. 4 plus 7 is 11. Plus 1 is 12. sum adds all the values ​​that a iterable. It is important that they are numbers. Because if they are not numbers. If I here for example add a. A text string. It would start returning exceptions. I'm going to comment on all this so you can see. Which is what throws me exceptions. 6390 04:17:15,94 9 --> 04:17:17,300 This returns me an exception. The one below returns me an exception. I keep updating. Y. sum throws me an exception. These three who face adding numbers. sum, Max and Min. They return exceptions. So it's also important that you understand yes or yes They have to be numbers. Because if they don't return exceptions. Now if we are. Good. Well these are some examples of functions integrated. Okay. Build-in functions. But the question is dalto. How do I create my own functions? Because everything is very nice with this. But I want to create my own. I want to have my functions. Being able to create them. Being able to use them. Being able to create my own code to use. How do we do that? Well. We are now going to see how to create our first functions. Well, let's start creating a function, let's create our own functions Because all good with the functions that already are ready, they are already integrated python But we have our own For that, create a file called CreateFunctions.py And we are going to start, I am going to put def That as before we put, for example, while to start a loop Or if for a conditional or for for a for loop We use, in this case, def To tell the program that we are going to create our own function And here follows the name of the function, for example, say hello The parentheses are important because here there is a parameter Now we are going to see what a parameter is I am going to comment on it from now on so that we already make it clear Creating a simple function, this is a function simple We put the colon and here the whole fragment of code we wrote in this block It will be part of the function, me for example I'm going to do a print Let him say, hello Lucas, my teacher, how you walk? So, for example, I want to execute this function As I do? Well, just as we executed type, just as we executed len Just as we executed any function, is the name of the function that is greeting And the two parentheses and the function is executed And here he tells me, hello Lucas, my teacher, how you walk? Yo estoy muy bien flaco, gracias por el saludo Y ahora en vez de andar poniendo este código, si se fijan, si yo pusiera este código Es un código gordo, es feo No digo que los gordos sean feos, por favor, no descontextualicen porque no soy gordofóbico Ahí está, tenemos un código que es gordo y es feo y realmente no nos sirve, no nos interesa So how do we make the code be cuter? I am not saying that fat is not beautiful, I am saying that in this case it is not aesthetic nor is it practical well, it's understood So, simply what we do is give say hello, say hello And this will execute the same code many times And if you look, it's the same but it's skinnier, then it looks cuter Same thing, the code, it's flying code But nothing, anyway, I hope you understand because this is the function of the code This happens when we have something small But if we had, normally what we do in a function is to create many lines of code If not, we don't make one function, we create many lines of code So, in that case, the amount of code which translates is bestial You will see it when you work with functions more advanced We are going to see it now in fact Making a simple function, simple function and here we give you executing the simple function Why are we going to comment everything? We are going to discuss everything because now we are going to create a function with parameters Let's put into function What is the problem with this? And, easy, that if I, for example, wanted say Hello Lucas, my teacher, but suddenly my name is Dalto What happens? And, what I have to do is use a parameter So let's create a function that has parameters What is a parameter? is a variable, a parameter is a variable Only that it exists inside a function, outside does not exist Los parámetros son variables que se crean para ser usados dentro de la función Y después ya no usarse más Entonces ponemos def saludar y acá le pasamos un parámetro que es nombre Ponemos dos puntos y acá decimos print Hola, acá usamos un f string porque vamos a decir nombre, mi maestro, ¿cómo andas? Entonces de esta forma, si yo ejecuto esto, ahora pongo saludar y me dice Hola Lucas, mi maestro, ¿cómo andas? Pero también me puede decir Hola Dalto, mi maestro, ¿cómo andas? And you can also tell me, hello Camila, my teacher, how are you? Greetings to Camila, teacher Ah, but Camila is not a teacher, she is a woman, she is mine So what's up? And we have to see if it's a man or a woman, well Ah, but how do we verify it? Well, we add another parameter, the sex Man or woman So we put if sex is equal to female Let's put, first and foremost, sex point There it goes, this is a method that they do not forget what it does is convert all of us to lowercase So here we simply put woman So if we put woman with a capital letter, with lower case, it will identify it So if it's a woman, two points Let's say that instead of teacher, let's to say teacher here we put So here we put adjective The adjective can be any adjective, we can say that for example If the sex is female, adjective is equal to me queen for example If it is a man, the if sex is the same as a man The comparison is always in lowercase Si es hombre, el adjetivo va a ser titán Y si no es ninguno de los dos Es porque eventualmente no se identifica ni con hombre, ni con mujer Entonces podemos decir adjetivo igual No lo sabemos la verdad, no lo sabemos No, pero no vamos a poner eso, vamos a poner crack Vamos a ponerle crack para que sea, viste, pasa que es muy por ahí Ellos dirían que es paki decirles así Entonces por ahí podemos poner mi amor, seguramente mi amor les guste Ahí va Entonces Camila, ya que le paso, mujer Esto básicamente me respondería Que hice mal acá Ah, puse esto, me quedé con ya Ells dos puntos, se me falla una forma Hola Camila mi reina, como andas? Dice que es mujer con mayúscula, a ver que nos devuelve Lo que pasa es que acá sexo punto lower No estamos convirtiendo sexo en lower Tenemos que decir sexo igual sexo punto lower Ahora actualizamos y ahora si dice Hola Camila mi reina, como estas? Si le ponemos mujer así todo mal escrito Hola Camila mi reina, como andas? Si después de Camila llega dalto Vamos a decirle saludar a dalto Hombre, y que hombre? Y nos dice hola dalto, mi titán, como andas? Y si no nos identifica, saludar Que yo puedo poner fran y el fran no binario Por ejemplo vamos a decir hola fran mi amor, como andas? Ya está, espectacular, un ejercicio que además es inclusivo Pero que más podemos pedir en este canal, espectacular No se me ofende nadie, estamos todos felices Yo también estoy feliz porque no me funan por algo innecesario Y damos un buen mensaje a las generaciones de hoy en día Ah no, pero está acopado, si no te sentís ni hombre ni mujer está bien Que hayan empresas que digan si no te sentís ni esto ni esto Te damos otra opción para que te sientas dentro, está bueno Y acá fíjense que no usé la E, no necesité decir amore o titane o reine Yo creo que también ser inclusivo es saber hablar bien But instead of saying students maybe we can say people who study And it's not person or person, it's person, person who studies So there we are including everyone world Because all people, no matter how we identify ourselves, we are people I understand that it is to simplify the language That's why I'm being inclusive when I use love So it's a point of view And in this way, if you notice, there it goes We're running this code, all this code that is here We're running it like three times And in other situations we should have done this, look We should have done 1, 2 and 3 All this code we just simplified with these lines of code which is fantastic now But now the question is, how do we do if we would like to use this phrase Because we don't always have to go around giving back things to the user I mean, literally what we do sometimes is, we are returning things to the user But if we wanted to do things that the user they can't be... I mean, like not... Let's see, I'm going to show you an example We are going to create a function that returns us values What is the use of returning values? because it's simple Yo por ejemplo creo una función que me devuelve un número Ese número tengo que poder hacer cosas con ese número No siempre se lo quiero mostrar al usuario Si yo por ejemplo extraigo un número de una base de datos que es privado Y le hago cálculos No quiero mostrarlo en consola, ¿por qué haría eso? Lo quiero para uso propio Vamos a ver Si yo creo una función que sea def calculo Le pasamos un num de número Y venimos acá y el código va a ser número por 2 Primero lo multiplicamos por 2 Después lo que hacemos es, agarramos una lista por ejemplo Y lo que hacemos de la lista es, agarrar y decir por ejemplo A, B, C, D, E, F, G, H, I, J, 9 caracteres 9, J, ahí está Vamos a crear un hash Create password, random This creates a random password So we're going to come here and we're going to do let this be equal to List of characters will be equal to this Then we are going to grab num and we are going to convert it to integer We are going to give str and here we are going to say num The number that is passed to us is converted to an integer. And then what we are going to do we are going to say that Value or integer is equal to this And then we say back that num is going to be equal to int An integer that gets the first value of num So in this way what we are doing is Here we give you a number We can spend 10, 20, 30, 40, 50, 60, 70, 32, 45 He will keep the first number that we passed If we pass 25 to him, he keeps the 2 We pass him 47, he keeps the 4 Always with the first number We pass him 1 he keeps 1 We pass him 3, he keeps 3 If we pass a number with more than two digits everything ignores me It only remains me, it leaves me only with the first digit What are we going to do next? Character 1 will be equal to integer num minus 2 Character 2 is going to be equal to num integer And character 3 is going to be equal to num integer minus 5 For example, here we are So in this way what I do is say Password is equal to list of characters That we are going to put the other name Chars Chars means char, char is character chars is like some characters Here we put chars c1 Let's put it as a string F, chars c1 chars c2 chars c3 And we are going to tell you the integer that we gave back For 2 There it goes, in parentheses obviously So if we now pass the password We are going to put this on top of everything And we pass print The password for example If I now say create random password And I give him, for example, a 98 integer number here actually goes 0 Because what we want to stay is the first character And the first character of a string is 0. So there we update, now yes And it gives us this that we are actually turning whole So now it is no longer integer, it is num And in all it will be equal to num Then we add the number Integer num no longer exists, now it is num integer num was a temporary variable we created At first num was equal to the value that we passed After is equal to integer There it goes We updated and it was overwritten, that's it Here instead of passing a list We are going to pass a string Why is a string traversed letter by letter? So there it is This is like tweaking the code to go solving These little mistakes we have This created us this random password Created us H, J, E, 18 Easy I put here for example I pass the 4 And it gives me another password I pass the 7 And it gives me another password I pass the 1 And it gives me another password It keeps giving me different passwords According to the number that passes Yes ok, this is a gimmicky function but it is an example you can create any If they want to do a test with you if they understood this and they can create it Create it for practice great If not, don't worry They can create any function that have numbers or phrases Or something The conclusion I want to use this For an inner working Suppose this is in the backend And it is very complex It is a complex algorithm What creates a random number that this is not random This will always be the same Always If we pass 1 It will return the same to us It's not random But suppose we pass it a number Which actually returns a random number we want to do something with it And what we want to do We don't want the user to see it Because here you will always see it on the console All the password is seeing it in console I think it's close to me How do I make it intimate with me? Simple Instead of giving it print Password What I am going to do is return Password I'm going to return it What is return? return i.e. that suddenly This function It will become a value That we can assign it to a variable Or other things For example You saw that we used the round function good round If we pass 12.5 returns 12 But we put result Same round 12.5 And result is worth 12 Why do I round 12.5 to 12? returns 12 Because what returns us round it's 12 So in this case Returns the password If I execute this like this no more That's it It doesn't show it anymore in console What it shows is the above But this was not showing it anymore in console The password does not show it But how can we get it? Simple What we say Password or password It will be equal to this And if I want I can show it Now if I want I can show it Password For my operation I can show it That's it But now I can work with the password I can say for example Phrase is equal to Your new password is a colon Here I make an f of fstream I say skinny Your new password is password And now what I show is the phrase So now I can operate Your new password is jvg12 If I here, for example, would pass the 3 Your new password is vdi6 That's it We are working the return values What allows us is the data to be able to save it Because if we don't return values And we give it a print We can't do anything with the data That's it Once the function has been executed It was done We did not do anything Your new password is none Why? because it's already so it was shown He showed us the password But we couldn't do this out here We would have to do it in here So the way to use data from the functions outside of functions is by returning values In fact, we usually create functions because they return something to us we make a process To get a value And that value is the one we use in type For example we pass him a number And it returns us what type of data it is That is the value that returns us Max The max and min function We return a value And it returns the maximum number or the number minimum But it does all an internal calculation And it tells us that the greatest number is this That is the value that returns us If we give maximum number Here we can see it number equals this This returns a value That's why we can save it here This This And that They return values ​​that we are saving If they didn't use return This runs and that's it It was done But it was never saved For it to be saved Or to be able to save it We have to return a value And with that once you are returning a value This automatically becomes that return value So we can equate it to a function They are already living it with practice This is a function that was perhaps too far-fetched For example I was maybe a little wrong I was wrong I admit it Perhaps it was not the best function to explain Because they got more dizzy with the function than with the concepts In fact this is only such a simple thing Compared to what we will see in the future That they cannot consider the complex And if they consider it complex it is normal because it is basic So don't feel bad I just want to get into it a little in more advanced territory And this is a good example But basically we are going to review general Here what we do is create random characters A, B, C, D What we do with integer is convert to string the first number Why? Because if we convert to string When we loop through a string The first value of the string is this the first letter So if a 7 happens to us Is now it's not 7 Is now 7 when we tell him Pass me the first data that is in the 0 That is, the index 0 of the string 7 will happen to me If time happened to me this This is only going to happen to me So that's the number we need So we convert it to number Whole, sorry Because as a number we cannot get the value 0 I just want to get the first number what happened to me That's why I use this function Because with this what I do is get only the first number If I pass 527 I get 5 The 5 of the 500 the 5 That with this that is here We did it integer and we get the first Easy If the number was 425 has three characters 4, 2, 5 With 0 I access 4 and always first We have the RUN function if you want What does it say here? C is equal to num minus 2 That is If for example the number is now worth 7 C1 is worth 5 C2 character 2 equals num So it's worth 7 And num and character 3 is num minus 5 That is, if it is worth 7 It's 7 minus 5 So this character is worth 5 That is if the number is 7 This is worth 5 This is worth 7 and this is worth 2 This is more or less how we play if the number were 10 This is worth 8 Because 10 minus 2 is 8 This is worth 10 and this is worth 5 Because 10 minus 5 is 5 What use are these values? they serve us Because I here for example If C1 is worth 5 5 is 1, 2, 3, 4, 5 The e Then he shows me the E Let's check it out I give it a 5 here This returns me the E Well not here because I'm using a print Let's give it a RETURN To be able to use it RETURN the E not gives us the D There it goes Because it is we give it a 5 All right If we give it a 5 0, 1, 2, 3, 4, 5 The first character has 5 minus 2 or is it minus 1 minus 2 is the D All right So it's 3 0, 1, 2, 3 The D Fine If we give it a 5 character 2 it's 5 or is it 0, 1, 2, 3, 4, 5 The F And here is the F Fine Let's see where the A comes from C3 is num minus 5 or is it and 0 is here The A Perfect And then the last thing he does is to numbers multiply it by 2 So if number is 5 This goes to 10 Perfect Let's try it with another number Let's see if we get with a 3 Ok let's go with 3 3 update 3 minus 2 is 1 0, 1 The B It's okay 3 is the D So what does the D show us? It's okay And then 3 minus 5 is minus 2 But remember the occasion on the list When we give negative numbers This is minus 2 So that's why we see it there And then 3 times 2 is 6 Here we show C1 Here we show what chars has In 1 What's this Here we show what chars has In 3 What's this and here we show what chars has in C3 What's this and here we show the for 2 It is easy In case they did not understand that's the explanation But nothing Don't look for it so much The important thing is that they understand That we have to return parameters if i did all this These concepts They are very good And let's learn to exercise to move a little The code and to manage us Because when we do real programming This is so It's the truth we do these things they all look weird we move this way What if We use it and it applies Then It is not bad that they begin to see real examples I do not accept comments from oh dalto I found it for you you rummage If there is something unnecessary Not it is not unnecessary Okay maybe to explain it Yes But when you have to take it to the practice They will have to do things a thousand times more complex than you are Not Not They will have to do the same So it's good that from now on they learn to do things like that And more if they sound exercises And if they turn out well If not learn it the same Until they get out Eventually If they want to be programmers and be good This they will have to understand So it's good that from now on they go all right And if you understood it the first time you are an excellent person You are very big It is normal that it costs you if it costs them don't get frustrated In fact If you didn't get this part Nothing happens Let's continue with the following Total This is not an exclusive requirement The only thing they have to understand Is that we have to return values That is important Why do we have to return multiple values? I mean Not only do we need to return A value Here we can return for example a tuple Give us back the password and num Why? Because if I, for example, happen to him 398 number He's going to give me back 3 So I want to keep that 3 I dont think is bad I want to keep that 3 For some reason we don't know I want to keep that 3 That returns us multiple let's put it here That returns multiple values If I want it to return 3 for example As I do? And good Password is a tuple I am returning a tuple Well let's show us The new password is This eat 3 This is a tuple So we should say Password password is equal to This Zero Because the first value is the password And there we have the new password And if we want to access the second value Let's put it Result 1 It is this And result 2 It is this So if we show here Result 1 But what is here is not optimal not optimal How can we do that? And remember what I taught you unpacking instead of doing this we go back There it goes We put the comma and now we put Number or the first number first number And now we just unpacked it And in fact here we do not need to add it this Because a tuple can be returned like this No need to add parentheses we update And now we have two values Password and first number And here we do not put 0 we take it out we update And now if I should throw a thing There it goes your password is Password Easier two different prints Your new password is Password And below we will say the number used to create the force Two points first number and there we have Your new password is Is and the number used To create the was 3 And that we are happening to this we can pass 981 And he's going to tell us your password is Is and the number used For here it was 9 Because even though the full number was this Only the first digit works Then That's what we're doing So this is a good example here we are saying unpacking The function Showing The results Earned and the data used For get It There we are Now if we already have all of 10 We already have everything discussed and all optimal Now the question is What if for example We want to make an indefinite sum Of numbers I am giving another example Completely different another very different Let's create a new function What's it gonna be Parameter args py point Suppose I have here A function that is Addition A function adds with a and b Ready I execute it here I put return A plus B I say good Result Same Addition I want to add the 5 and the 3 This is going to give me 8 And now I show it on the screen prints Result Until everything is fine Ready That's it 8 But if I want to add more numbers For example I'm giving it a 9 I give it a 9 And I don't add it throws me an exception How can I do this well there is a function Well the normal way is pass a list Say this like it's a list Inside execute a loop I mean inside the function We run a loop We go through it by adding the values optimally Of sum values For example Let's stop running it There is A non-optimal way to add values It is to create this function that is here And say for example Ready And here what we do is say added numbers same 0 And down here say And down here say For number in Ready Two points And here for example we say added numbers more number More Forgiveness Same added numbers More numbers So then what we do is finish the for I put a list and shows us 17 If I happened here for example a 10 and a 20 he keeps adding it to me returns 47 And if I also pass a add me another 3 give me back 50 sorry it's wrong Because this is not the way to do it We should be able to make the number of arguments be undefined Don't pass him a list This is disgusting So I'm going to comment because it's not very good So I comment I comment and I will comment everything I comment out all lines of code Well all this was for before I commented there We are going to show the optimal form now of do it Using the args parameter If we use the parameter args Let's copy the same code And now we have to use Okay Let's use for example Numbers Here what you have to do after putting numbers I put Forgiveness the asterisk Okay This little sign that is here How good, at least in Argentina we say asterisk Ok let's process it first What we do here is tell Che look This is going to be a list Okay And it is a parameter that basically We can do this Can We can pass for example Result Same Addition and we can tell you 4 5 Okay This is going to turn All parameters as if they were one I explain It will be that all the parameters that we pass him be only one I come here and tell you Zoom Do you remember that Zoom grabbed the iterables and added it If I have a list with 5 numbers I add it But if I pass Here 5 numbers There is 5 numbers And it becomes a list Actually in an iterable Zoom should add it to me So we put numbers And if I show them and I return them I return this value Let's see what happens update the same numbers Do you remember that this gave me 50 Let's see how much this gives me update give me 50 works exactly Same as function above And that using the parameter args This is good In fact we can do one thing We can say For example ask for the name An important thing of this parameter It is that we have to use it In the end if we use it Then we can't add more parameters is the only parameter what can we use And if we want to add more parameters For example Che look I want you to add a name And also after give me The next What's it gonna be F-string And we are going to return Name your numbers the sum of your numbers is 2 points And there we show it if we update and we pass Luke this tells me Luke the sum of your numbers it's 50 because the first value It's the name all those who come after They are going to make a list what will be called numbers and numbers they are here Then, later We add all the values Of the list And they tell me The sum of all your numbers The operator args The operator as argument Here we use args And we can also use it to break down I mean We can use same function as before That we are going to copy and paste it But We can use it in another way I mean If we can pass you the list But instead of running All this I'm going to leave it as it is I'm going to put numbers Also to this function And here we can tell you return to us The sum Asterisk Numbers And this also works the same Total amount Let's put another name so that not Here we put sum so that the function Don't tell us it already exists I now say what result 2 Is equal to Total amount one And I'll give you the list up here one Let's pass this on one We did the same thing up here. one Here we will see if it works one And in fact one let's get to this one We will not show this result one There it goes one we are not going to show it one Let's show the second one let's show one prints one Result 2 one we update one what happens here one Is that we have to create the list one we put a list one There we close the list one we update one And now if we run the program again one it works for us too one because we are telling one Che one And we will show exactly one The inside one but without the list one In fact one if i grabbed this one and show it one would show me one This one only that one It would not be a list one here for example one I tell him one prints one Numbers one This is going to show me here one if they notice one 5 one 3 one 9 one 10 one twenty one 3 one I say show me the type one Let's see what type of data it is one gonna show me one Why don't you let me one It tells me that there are many arguments one That's the interesting thing about this function one He is quite a special operator one and it's very good one I use it a lot one And can be used as a parameter one Or here we use it as a parameter one to pass him one The amount of data we want one If not one we can use it one to do the same one The other way one Only this is more tedious one Why here we have to use one a list here one And also pass him one A list one Thus one That's where we can go one the amount we want one Only this way one We limit ourselves to that one always has to be one The last parameter we added one Because if it is not the last parameter one Then, later one we can't add more one instead here one If this were the last parameter one then we can continue one adding parameters one because if we add one One more parameter one This parameter one does not run one because this is infinite one So everything that we happen here one When you know the program one What is this parameter one Never one because always everything one He's going to get in here one well, finally one and here we put one optimal shape one to add values one Or let's put it up one Because this goes with the code above one Optimal way to add values one and here we say one same as above one But using the operator one args one as argument one As a parameter, sorry one Yes actually one we could have done the same one We could have created this list one For example one we could have done the same one We could have created this list separately one and have put one list, point, number one if it was the same one Well, here we saw the parameter one arcs one What if it is seen in a file one set aside for this one Why is it important that one That we give you priority one not its importance one Well then it's interesting one let them know that one I mean one The order in a common function one For example one Let's go create functions one Let's create another file one Functions, extra data one .py one Since we are going to put one Let's create a common function one For example one def, phrase one He will ask us for the name one He will ask us for the last name one And he is going to ask us one Let's go here and tell him one return one hello name one and last name one you are very adjective one So now we tell you one For example one Phrase equals phrase one Phrase equals phrase one best resulting phrase one Resulting phrase is equal to phrase one Lucas Dalto is a boss one that was true one is a kingpin one I mean one but did this one And it doesn't show me anything one so i will say one prints one resulting phrase one And now yes one Hello Lucas Dalto one you are very boss one Easy one Now one Might one Let's check it out one update one Hello Dalto Lucas one No, it doesn't change one the order is important one Now one If I put here for example one Adjective one Same one Hood one Eat one This is forcing an argument one And we can do it at any time one Because adjective is equal to capo one So we update one Well one This is precisely one because if we pass this one We have to pass him all the others one So I can for example one now say a name one Same one Luke one And surname the same date one And now it's complete one The second one value 2 one I put it in the third one And the last value I put in the first one nothing to see one but i update one And he told me one Hello Lucas Dalto one you are very boss one and it works the same one nothing changed one And changed the parameters of the place one Why? one Because these are the parameters one We can say that they are the parameters one of keywords one The keyword parameters one while the others one are the required parameters one I mean one The parameters that are one positional one That is to say one These parameters one What are they one positional one of position one Parameter 1 one Parameter 2 one and parameters one of keywords one Then one The order does not affect one The same as one We can also define it one straight up here one That is to say one if i for example one This leaves it as it was before one And here I tell you one adjective equal fool one I here one This one I can change it one explain this one you are very stupid one I run this code one So let's do one thing one Let's run the same one But one Lets put one adjective equal boss one Let's put it at the beginning one We are going to leave this as it was before one Same name Lucas one Same last name Dalto one Lets put one creating a function one of three parameters one and now we say one Using keyword arguments one They're like one just arguments one keyword one and down one In fact one We are going to discuss this one Too one because i want to create one other function one to do something similar one I want the function one The second one that I am going to create one The adjective has it defined one like fool one So here it is not necessary one that we pass him nothing one me here for example one I tell you this one I will copy and paste one down too one here it is not necessary one what happens adjective one I can pass one Lucas Dalto one when i update this one he's going to tell me one Hello Lucas Dalto one you are very stupid one but here one This will always be one Silly one The variable one I am defining it up here one But if I come now one And I put adjective one Same one Intelligent one i was so smart one that I managed to change it one These are parameters one that they are already forced one come defined one Default in function one But we do want one we can change them one That is to say one Why does this exist? one Because it's the same there one what to come here one do this and say one This Dalto and you are changing it one Not one You know why? one because it is very stupid one But if you define it one Thus one Okay one you are defining it one you can change it one In fact one If I make him smart one default only one is also changed one Because it is a third parameter one What is optional one If we want to add one we add it one But one equals dumb one creating the same one The same one Function one with one parameter one Optional one and a value one Default one The optional parameter one Is this one The default value one It is foolish one Because we can give it to you one As optional parameter one Plus one We are defining a value one So it's both one It is an optional parameter one and a default value one This is how you do this one Well and now yes one a beautiful part one is coming now one What is lambda functions? one so let's see one This last section one of functions one What is lambda functions? one let's see this At that moment, Zell felt the true terror. Oh the shell of your gun, always something wrong He pays me hundreds, thousands of dollars on my card and my production and the whore that I gave you, I take everything to hell. Shell of your weapon. Now simple, let's get a new file, which is going to be Lambda functions, who know Python or who were intermittent a little bit, that they got in and did the function part and want to know what Lambda is, they can put him to listen or they said ah, it's like the function on arrows in Javascript. Yeah, it's like literally an arrow function in javascript. How do we create a Lambda function? Simple, is the name of the function equal Lambda, parameter, colon and the expression, for example, by two. We don't understand anything, but basically we go to explain what this is. Here we are going to put it, multiply by two. Lambda, is a way to create a function anonymous. Why is it anonymous? Because it has no name. It is as if I said, for example, a String, a String, this has no name. It is an anonymous data, it is an anonymous String. If I create a list, this for example is a list is an anonymous list because it is a list, but it is not associated Nothing, it's anonymous. So this is the same, when we created a function we put def, name, function, parameters, colon and it is no longer anonymous because we are going to store it here. The difference is that Lambda creates functions anonymous that we can later store, for example, in variables. If now, for example, I say print, multiply for two, five. What is this going to double me? Ten. What does this function do? Simple Lambda is a keyword. So far it's like I said def, multiply by two and X The difference is that here I am inside saying return, X times two. The same to save us all this code, to save us from opening a block of code, because remember that every time we open a block of code, that is, an instruction, a while, an if, a for, a function, we are opening blocks of code because We are leaving a space this space because we opened a block. To avoid doing all this, we created these functions. What are the benefits of creating just Lambda functions? Let's comment on it. Creating a Lambda function to multiply by two. First, the first benefit is that we can use when we want to do something simple and Quick. And then they return automatically. We don't have to go around making returns, returning the function. Furthermore, it is important to prove that they are not suitable when we have to do more than one instruction. When we have to give more than one expression, it is not suitable There is a function that for example is filter, with a common function. Filter is a common function. It is just a build-in function, because It is built into Python. And it is used to use a function that returns us true or false. And we create a list for all values where the function was true. For example, I'm going to create a list, number one, two, three, four, five, six, seven, eight nine. Easier. Here I am going to create a function, creating function common to say if it is even or not. What I do? Simple, def is even, so I put the number here, two points. And here I say if num the rest of this divided two is equal to zero. So this is even. Why? Because any number that we divide by two and the remainder being one is without pair. One point five is c. If the remainder is zero it is because it is a number pair. Anything with a remainder of zero is a number. pair. We put a colon and say return true. And with this we are already. We have just created a function that returns pair numbers. What Filter does is say even numbers. It will be equal to filter. Here what we do is tell him look. Use the function espar and pass it the parameters numbers. Now numbers is a list. We are passing the ready function to it. What this is going to do is pass that function to it. And what is this going to do? Well, if I run this, if you notice me going to return ten. Of course I have returned this because we are running the other function. It is even numbers. We have to ask him about the variable numbers peers. Let's create an exact filter object. Because the filter object returns us all this values. We execute this function and the parameter is each of these list values. It's like we're going for a loop. It's like an artificial loop. Which is not a loop but is artificial. Why? Because he says look. Do you see this function that is here? Yes, good. Now in the first turn number is going to be equal to one. In the second to two. In the other three. And so with each value of the array. If the array has ten elements it will do ten times. And in each one it will pass a different value of the element. Those that return true will be added to a list that it will then return. Those that return false do not add them. So if we now give you even numbers and we do this list. We come here and put We turn it into a list. We give list even numbers. We update. And now it returns a list of numbers peers. If here, for example, I add eleven, thirteen, fourteen, fifteen and twenty. Which ones are you going to give me back? Well, he's going to give me back the fourteen and twenty. Which were the only pairs I added. And if now I want the numbers by example. They are not even but they are odd. With this I have the odd numbers. How can we execute this function by example? Not with a lambda function. Well it's easy. Instead of doing all this we are going to say creating same as before but with lambda. Let's discuss this, this, this and this. And all we have to say is here. I uncomment this. And here instead of doing all this simply I put. Lambda, number, colon, number, remainder. Two equal zero. If the remainder of two is equal to zero. It will return us true. Something cool is going to return to us. Or be this. If not, nothing will be returned to us. So I run this. And it will return exactly the same. This is what lambda is for. To simplify all this code that was here. We simplify it with lambda. It's simple, this is the functionality. So we say look. Creating the same as before but with lambda. Too easy. How does this work? We say look. Let's make an anonymous function. It has a number parameter. Okay? Number we are going to divide by two. And if this is equal to zero we return it. Otherwise we are going to return something that is false. What the filter function does is Executes each of the values ​​of an iterable. each of the values. He is running them here. If we pass a text to it, it executes the text. Each value that we pass to it will be executed here. So for it to create a function from scratch. We run this. So in the first round. It will be worth one. Number will be worth one. One divided two. Give rest one. Then it will be worth false. It will not be added to the list. In the second round it will be worth two. So you know when we do the same. Here is zero. Then the number is returned. And if the number is returned the list is added. That's how it works. Too easy. If it returns true. Or something that gives us true. We added it to the list. If he doesn't return us. we take it out It is very cup of this function. We will use it much later. So it's good that we do a first look. From the filter function. with lambda. So good. We have just finished the functions section. It's starting to get pretty complex The issue. I told him that this was not such a calm course. If it is a calm course. But it has its advanced things. Because if we can't say it's a course complete. And different. And that is what I want to get to with this course. Well. I think we can move on to the next one. The next part of this course. Which is practical exercises two. Now if exercises are coming. More complicated than the previous ones. version two. And I think now is a good time. To go changing shirts. We can go and climb the level. Because once we move on. We are escalating the level. So over there. We could change camisulis. To do these practical exercises. Because when we dominate them. We are climbing. So I would say that. It is time to change it. It seems to them? Let's level up. Let's go with practical exercises two. Go. These are already advanced. They are already advanced intermediates for the course. We can say yes. This is already intermediate. For the course is advanced. But overall. It is an intermediate level. So let's go. Well, the truth is that it did not complicate it so much for me, okay? I did not complicate it so much and I wrote down the exercises on a cell phone Why? Because I said, look what we're going to be doing voice over Do you know why it takes so long? does it take so long in taking the courses? Because I do voice-overs, I do animations, I edit a lot Instead of taking a week as they take all creators I take 4, 5, 6 months Why? And why did I take the time to to come... This is not my house, this is a studio I specially hired this to record So, I have to travel 40 minutes that I want to record a video A video, this that records 40 minutes That's why I record everything at once Then I have to put together the scenes I have to go around doing the subject and one giving it to me Preparing classes in advance I edit everything a lot, it takes me a long time to edit Every half hour of fragment that I edit, in average It usually takes me more than a day, more than a day And I'm not farting all day So it takes time And also, the voice-overs that I do That's not those half-hour videos, no include voice-overs In other words, the voice-overs, a voice-over They are the ones that are animations, graphics and others Without my face, when a screen appears Let's see an example of what a voice is in off A voice-over is when, obviously, not... Ok, yes, yes, that's a voiceover itself That takes a long time to do So I said ok easier I have the agenda here, practical exercises 2 Here it is Let's go with the first exercise Today the class teacher was absent And the boys organized to put together the his own One of the students is going to be the teacher And another will be his assistant A. Ask for the name and age of the companions who came to class today And order the data from largest to smallest. B. The oldest in the class is the teacher And the minor is the assistant The question is, who is the assistant and who is the teacher? Well, here is the folder, so Exercises-2 And in a file I call exercises-2.py Well, the first thing we have to do is write down the data Always write down the data Come on, then, the teacher was missing And the kids are going to put together the class Well, first we are going to ask for the name and the age Of the classmates who came to class today let's start with that We are going to leave this behind colleagues, same A list There it goes then we will say Let's say For i in range And here we are going to pretend that they came 7 companions there it is, 7 From 2 points, that is, we are going to execute this loop 7 times let's start And it will run 7 times A loop that will ask the user the name, the same Input enter sorry, the name of the partner And age will be equal to The same Input enter Age of the partner But remember that this returns string As much as the guy enters a number It will return a string So we have to put In Input So that the answer you give us automatically become an integer No problem Partner is now going to be equal to a tuple with name and age And we're going to add to this list This fellow companions.append Partner There we are Well, here we basically have the data of the companions But since we want to order it randomly What are we going to do? Let's put this Number of companions And what we are going to do here is This put it inside a function so let's say Dev get companions What exactly is he going to ask of us? The number of colleagues 2 points And we run all this code We are all going to advance it What is necessary so that you can be well identified And don't throw us mistakes And there we have the code This is a function It works? Now, once we're out of the for What we have to do is order this Because that's it, we have everything But we can't do this with max and with min Let's just have the information I mean, yes we can Making a loop that runs concurrently At the same time That is, we create two separate lists And we are executing them simultaneously But that's a long way We can do it with a function that we have already viewed so let's say classmates.sort And here we say that the key is equal to Lambda x2 : x1 Because we know that the age is the second parameter And the second here we put it as 1 So this is basically what it's going to do is Sort us mate by key What is the key? Well, the second value of the tuple It is easy Here I explain them Basically this creates a kind of iterable or list We can say it, tuple, whatever they want in which it says che look Ok let's sort it out Remember that sort is a function that orders Well the question is we are going to order it But how are we going to order it? Well I want you to order it for the second parameter The second parameter is age So let's sort them by age. from smallest to largest That is, this says che mira we have two data That is, we can order the set But how do we command you? That is, what is the parameter that you think that we take into account To order it? Because it can be by name in alphabetical order Why do you want to order it? And I want to order it by the largest number I want the orders of the number is of greater number Well, give me a numerical data here is your age So, this list with tuples order it back to me with the tuple Whose second value be the least and the tuples Where the second value is the smallest they pass forward And those with the highest values go to the end that's what we do here We are ordering companions For this Over time the more they begin to use lambda functions More will realize what this is But it's pretty simple KEY is precisely a parameter that we are forcing It is an optional parameter We are telling you that we want you to order By the second parameter of each What this function does is return us this Now, how do we know which one is the partner? Simple The partner is We have the wizard on one side that it will be equal to companions Let's access the value of the tuple Let's access the list first Okay The list The zero element of the list will be the one that first is sorted And then the zero list element has two elements Well, let's access element zero And then This is because it is from minor to major So the assistant is the minor How do we access the minor? Simple if we have a list Ok, a list with lists we have this One two One two One two This is what we have So we are saying Look, I accessed the list Ok, we're in here What item on the list? The zero ok here it is We're here we are in this element Now This element in turn has two elements Which one do we select? The one or the two? The zero, that is, the first this one here Why? because this would be the name Remember that we put the name first and then I gave him Or is this the name? Well, then you're going to show me the name Of the first element of all that appears What is the first? The younger Why do we order it from largest to smallest? So the wizard is equal to this And the teacher is the last last on the list But how do we know which one is the last one? Because there may be millions of students Well, do you remember how to access the last element of a list? It is simple Companions minus one In this way we access the last element zero is first The least one is we start again And then the zero element Because we want to access the last element to the name So what we are going to do now is return We're We created a function that did this for us So now if you want we can discuss it well But let's verify that functions Let's say get companions And I want to pretend that there are 5 classmates Not? 5 companions This is going to give me something back Well, I'm going to say that I'm going to ask him assistant, teacher equal to this Because we are unpacking the value Here could be any name They don't have to be the same Remember that these only exist inside of the function Outside they don't exist And now we are simply going to bring print The assistant is Two points And now here I add the assistant But here we have to put an F in front Well if you don't tell us And we copy, we paste And we put the teacher What's more, we can even put it all together We can do this Delete the line above And put the teacher is such and his assistant is And there we add it There is Now yes We run and verify that it works Number of companions is not defined Perfect Because it is a number of companions There it goes Now yes we run back We run and enter the name of the partner Well, here we have to leave two points Space Because if we are not going to stay stuck I'm going to put the age of the partner partner's name is Luke The partner's age is Thirty partner's name is Fran The partner's age is twenty five Enter partner's name I'm going to put Camila The partner's age is Twenty seven partner's name Robert The partner's age Twenty nine Enter partner's name Peter The partner's age Forty two The teacher is Peter and his assistant is Robert Perfect Because Peter is 42 He is bigger 19 is the youngest. This works and is running from 10. And here we have a function explaining the last concepts that we were learning. We apply loops, we apply the sun function, string methods and so on, we apply functions, we apply unpacking, all this in just one simple exercise that summarizes several items that we were learning. We are going to comment a little on the code and I'm going to show how it is. Done, here we have it. Function to obtain the assistant and the teacher according to age. So we create the function. creating the list with the partners, we create it by executing a for to request information from each partner, this is the for. Inside the for we add the information to the list, we add it. After We order the numbers from least to greatest according to age, we do it here. after companions x, that is, this that is here, returns a tuple with name and age. And then we access Name, or this is here. name is first value, this is here. To define wizard Y Professor, what do we do? we define assistant and then we define teacher, accessing peer values. After we return a tuple that after we unpack to finally show the result. That was a beautiful resolution of this exercise in Python. Now yes, come on with the next. Ok, the second exercise don't give it to me complicate so much. I said, che, let's create a function that when we pass a number, it generates numbers for us cousins ​​up to that number. For example, if we pass the number 15 to it, it would pass us the 1, 3, 7, 11 and 13. Why? Why They are the prime numbers from 0 to 15. Is say, we create a function that returns us a prime number from 0 to the number that we passed him Let's do a pretty function basic that later I am going to allow you that optimize it. Let's create a new file which will be called exercises2.2.py. Well, now We are going to comment the function ourselves, creating a function that returns the numbers cousins between 0 and the number we passed. Perfect. Well, def, numbers, primes, num, colon and here We start creating the function. if a number is divisible by another, the remainder is 0. Then we would have to divide the number They go through all the numbers. In other words, a loop nested. Well first let's create a function that checks whether it is a prime number or not. Ok let's go to put is cousin. Why? because as we have than using a loop inside another loop, it goes to be better than instead of putting two loops, let's create one function that first defines if that number punctually is primo and then another function that executes a loop that will call that function that at the same time calls another loop. So it's a way to make nested loops without the need for make loops nested, because we actually call a function. It is not a nested loop as such. Yes at the level of execution, but not out there at the code level, in terms of readability. So let's go do it. For i in range num. Let's run a loop the same number of times as the number that let's pass it on So how do we check what is cousin? Simple. What we do is, that number let's divide it by i, which is an incrementer which is going to increase. So let's put East for, that we are going to read the two dots and we go lets start. If i, the remainder of dividing the number for i, there it goes, is equal to zero, that is, if we divide the number, suppose this is worth 10, right? in the first lap this will be 1, in the second it will be 2, in the 3rd it will be 3. So we will go verifying in all turns that the number is not can divide. In case the rest is zero, it's because yes it could be divided by a number. Whether could divide by a number. So let's go to start from 2 to no. We start from 2 because if it can be divided by 1, it will tell me that It can, and all numbers can be divided by

  1. By 1 and by the same number. Then should we say let this eat this. Why? and has to subtract 1 because if it is divided by itself also going to give remainder 0. Then it has to be from of 2 and this number minus 1. I repeat, because Yes you can divide by itself, this will give us back 0 and it is going to become true and we don't need to be that. So here we put two points and here we put false. In case it can be divided for some number greater than 2 and less than itself, is cousin. So we're going to return false. More easy come on to use what we learned and we are going to give it a break. And there the loop ended. If this finds That you can split, ended the loop. That's it the loop ended and it does end. In case of than the loop finished, let's do the following. Two points. Let's execute more than one expression like this that this let's leave it like that. let's put it down because we are going to use more than one expression. first we go to say that we return false. Why? And easy because yes, sorry, it's not false false. if it comes to meet at some point, this is because it's false. That's it, there's no need to turn around, It is not false. Because if it can be divided by a number, that's it. And if this returns false, the loop terminate, stop running. because if we returns false, when a function returns something, in this case it is as if we used a break because ended there. Already function when executed the return, it stops running. everything that comes after of the return, it is not executed anymore. and if this ends to be executed without returning false, it is because no number was prime. So we are going to return, let's check if this works. Result is equal to is prime and we are going to pass it the 7. And here we are going to say print result. We execute and it tells us true, it is prime. All right, come on to pass him the 9. It's cousin 9, false. Good for what? Because 7 is prime. 13 is a number cousin, true. So, wait, this is a function that we know that it returns prime number. Very simple, very easy and very fast. Now we have to do another function in which we call this function. So that we are going to create them. Let's create another function let it be def primes up. here we put another num. So here what we do is the same. For e in range 2 num num. So, for e in range num. And here inside the loop we are going to verify that each of these numbers is prime. Then we put is cousin and we are going to give it results. And indeed, if result is true, if result equals true, then we are going to create a list that is prime same list. Here we are going to say cousins ​​point append and we are going to give append and at the end of the for We are going to return cousins. So, from this shape, yes now we execute primes up to 13, when we execute this we are going to see that it says 0, 1, 2, 3, 5, 7, eleven. Because we are running the prime numbers from 0 to 11. We should prevent it from coming out 0, but it does not matter. Let's hit it in range. It itself, we boot from 2. Because we can say that 1 is a prime number, but let's start from 2. We start from 2 because 1 is not a number cousin. And there it throws us the data. 2, 3, 5, 7, 11. In fact, here we could start From 1, not since 2. Because he is taking us into account 2 as a prime number. and here is less one. So, there we run. Here we are going to add a 1. We updated and now it returned me 2, 3, 5, 11 and 13. Here, so that this does not work, we are going to remove the 2 and put 3. It is a change what are we going to do so that simply the 2 does not take. And there I would be counting all the numbers 13 to the 13th. The only problem is that here the 13th he is not taking it from us. That is, if you notice the 13th we did not taking. And 13 is a prime number. And that says up to 13. So, for that I have to give it plus 1. Updated and 13 is already included. So, now he is throwing me all the numbers cousins from 0 to the number that we pass to it. In fact, if we pass here, for example, 98, update and we have all the prime numbers from from 0 to 98. And the amount of of prime numbers that are in it. It is fascinating. This function is a valid and excellent function, I would say. There is another way mathematically to do so by multiplying by 0.5 and the rest. But we are not going to do it now because it could make you very dizzy. keep this one form, with this solution you are correct. Then, Now we are going to comment each part of the code to explain how we did it. ok here we go to create a function that checks if a number is cousin. Here we already created it. Perfect. we verify that the passed number cannot be divided by no number between 2 and that same number minus
  2. If it is divisible by any, we return false and ends loop. If the loop ends, it means that was not divisible, so it is prime. we return true. This function is already commented out. We are going to comment below. creating a function which returns a list with all the cousins We create the list. we verify if the value is prime. In case it is, we add it to the list. We return the list. There is. We create the result by calling to function and we show it. There we have executed the Python exercise 2. Fascinating. Yes, biumberella I am a fan. now basically we have to do the same as this in the exercise 3, but with a difference. Exercise 3 tells us asked to write a program that calculates the series of fibonacci up to a specified number of terms. This means, instead of showing all the cousins there is, from 2 to the number that most we call, we have to show the same, but in fibonacci. Instead of prime numbers, the series fibonacci between a given range. That is to say, between 0 and the number that we pass to it. What is the fibonacci series for people who don't do you know her? Imagine that we grab the 1. 1 more 1, 2. 2 plus 1, 3. 3 plus 2, 5. 5 plus 3, 8. 8 plus 5, 13. 13 plus 8, 21. 21 plus 13, 34. And so on. Is a series of consecutive numbers in which we grab a number and add it by the previous one. Us gives a third result. that third result we add it to the previous one and gives us another result. that result we add to the previous one and it gives us... that's it. It's basically that. Look for a sequence of fibonacci. Here it is. This is the succession of fibonacci. Is an infinite sequence of natural numbers. Now, fibonacci is the classical sequence. from 1 forward. But we can do it any way form. We can start from 9 if you want. Can boot from 40. We can boot from
  3. From the number you want. 57 more 57, 114. 114 plus 57. And they can do it from there. Only that the original is from the 1. That's why We are going to start calculating the Fibonacci series from 0 to the number that we pass to it. So which we are going to create a newfile. Exercises 2.3.py. Creating a function that returns the series fibonacci between 0 and the given number. Good. Let's create it. def fibonacci num. The fibonacci a number. Going to be equal to 2 points. And now we are going to begin to create the function. This one is quite simple. First we are going to create a tuple. And then We're going to unpack it. Easy. value to yb is equal to 0 and 1. Easy. Let's create a for dei in range num. A for that is executed from 0 up the number that we pass. So, let's go to do the following. If a plus b is greater what number return num else. Two points. Here comes the magic. What we were saying now is that a is equal to b and b is the same aa plus b. Let's unpack it. A and b. A equals ab and b equals a plus b. I eat we do this? Easy. Here we are unpacking. A is equals ab and b equals a plus b. Here it is the key of fibonacci. Put it in a loop. The only what we have to do next is at the end of the for we return num. That's it. Here we have the fibonacci series. Now this is here not doing nothing. So what we have to do the else is to throw it down and save these data. Say the list fibonacci list equal since we create the list And here in else simply let's add fibonacci list point append b. and now we return instead of fibonacci num list. So, let's go a correct that this works. same result fibonacci from 0 to 20. Print result. We update, let's check. This here is unnecessary because at some point this function is forgiveness it will be executed. So we just have what to say fibonacci list. We update and now it should work. 1, 1 plus 0, 1. In fact we start from 0. We can make the first value is 0. There it is. And we start. 0 and
  4. 0 plus 1, 1. 1 plus 1, 2. 1 plus 2, 3. 2 plus 3, 5. 3 plus 5, 8. If we had passed it, here what was missing was joining us one last time plus the value. Because a plus b says that it is greater than num. If this is greater than this, it will return us the ready. When 8 plus 5 equals 13, simply it was not executed. That is, it was not added. Of done, if we had passed it for example the next one, which is 21, this gave me 13. And if we had past the next one, which is 34, I would have past the 21st. But if he had thrown it away on 33, which is a number less, no. Here we are telling you if a plus b is number. What we have to do is tell who only wants to check that b is greater to the number. So we update and now works. If we pass the 34, it includes it within from this list. We have a function that returns Fibonacci. Here we are going to solve the exercises. And they are not mathematical exercises. because they could see it as mathematics. Mathematics is the logic. It is a very easy tool. Is a number that we take the previous one and add it to it. Already We took that result from the previous one and we add it. And we hold onto that result. It is easy. It's not that it's math. It's just programming. Because what is here, I don't see the mathematics. I simply see a more here, a greater than and not I see more math. I understand that all this it is mathematical logic. But let's see, there is no a lot more science. It's just logical. Okay, that we can apply using elements of programming. What are assigning values ​​to variables, loops, an orange function, create our function itself, pass parameters. It is simply carry out and put into practice all that we have been learning Which is fantastic. So we can say that we already realized Fibonacci. Spectacular. In fact, there is one more way simple to do it. And easier. Because I challenge you to these exercises that are here. Let's see, this does it do the job? Yes. Is there a better form to do it? Yes. That's why I challenge you to find it. What I really want is that you grab this and improve it. Because that's the goal. In fact, if they are content creators or they cheer up to make a video creating content, I challenge you to make a video. They make a video making every part. A video solving practical exercises. One, in the best possible way. one, exercises practical. Two, in the best possible way. And another, practical exercises. Three, of the better way possible. The three practical exercises, one that is still missing that I did not do it, I challenge you. So cheer up Do it. In fact, if you You are a spectator and you want to see if other people it They did, you have to search on Google. solving exercises from Dalto's Python course. use the hashtag Dalto solved exercises. hashtag Dalto solved exercises. so if i want find them, I can see it. And if all the people who is watching this video wants to see you to you solving the exercises in the best way possible, it can also find you. So that all we make that hashtag. Hashtag that one, ok? Well, I took the time in my house to put together a code pretty quickly and this is what came out. I was able to achieve it in a single line of code. Lets see if you get it, take your time, pause the video and try to understand what is He passed. The I challenge you to find out what the function is that I used here, such as All. investigate well what does this code do and how manage to do it only on a single line. This is for that you can try the same in the other exercises to reduce it as much as possible they can. Not always reducing the code is best. Is say, sometimes longer code is better but more readable and not a simplified code in a single line that nothing is understood. But it is not more to know optimize correctly. So I challenge you to see what they can do. This is the shape to reduce as much as possible the exercise of the prime numbers. Now yes people, come on with the next section which is a spectacular section because it is what we need to get into a semi advanced section. I leave you I don't want to say many more words. I leave of this section and now we do go once per all with a beautiful section that is the modules. Go. We are in one of the final stretches of the course, We are in a moment in which I know you are already committed to the cause, the cause of learn python, of course, after thinking about it but digging into it enough I realized that in I don't really care that much, because if you went able to understand all the things we saw so far, or at least 93%, that is, If you stayed with 3 or 4 little things, it doesn't matter, It's perfect, that doesn't count, but everything does the rest you understood well, we are talking of variables, of functions, of methods of strings, list methods, loops, unpacking, the practical exercises, if you got to this point is because at least you saw the above. That's why I'm not worried, and that's why after to reconsider it I said, yes, this person is capable of achieving it, this person is capable to finish this Python course, because the more people starting a course does not finish it, and that it has come this far means something that is very positive, and that is that obviously you want, obviously you want to achieve it, so it's up to you achieve the goal, but you are doing excellently all right if it's about reaching the destination. So again we start with this section very important of the course, let's go like this now same to go with the modules, I have piola, It was frashero, it was very epic, yes? Thanks. Ok, concentrate on this part because it is very important, for starters, what is a module? Well, pay attention, a module is any .py file, yes, that is, what we are seeing on screen is a module, exercises 2.3.py, if this is a module, why is it a module? Because it has the .py extension, I know what it is difficult, I know it is difficult, but be careful, this elif.py is a module, let me think about it, Let's see elif.py, it has el.py if it is a module, ok ready it's a module, I know it's complicated, I know, but please stay tuned, come on once again, inputs, this here, they have 4 lines of code and half are full comments, is this a module? Yes, oh how complicated, by God, how complicated I don't know whether to continue, well not really This part is complicated, it's quite simple, all files ending in extension .py are modules, we are going to close all of them, to the shit that there were enough, why what do we call modules? And basically we call it modules because from one module we can call another, from one module we can create another, we can change the routes, we can access, we can form packages, if I for example create a module with many functions, suppose I have to calculate the fibonacci function that we did in the previous exercise, now I You already believe it, I don't want to go around creating that function all the time, easy, I create a module with the fibonacci function and all other functions that I need, then from a module new I call that previous module, and now just by calling it I can use all the functions and all the code I made in the another module, it's great, it's like the way to break the program into parts and use it and handle it however we want, basically we have three types of modules, this is very simple, we have first and foremost the modules python, the python modules, which are the modules which are created by python, which are already coming built into python, these modules after are written in C, that is, C is a language programming, which is lower level than python, they are written in C that's why they call python modules, they are not common modules but which are modules created by python itself but in C, but they are still modules, then we have the third party modules either third-party modules, which is like per example, I now create my own module, with specific functions that you They serve you, I upload it to the internet and you do they want they can download and use it, well that would be a third party module, because I believe it, I uploaded it to the internet and you they downloaded it, it is not a module that you create, it is a module of someone else, companies that create their own codes, let's say libraries, all those things are third party modules, you can download and use it without problem, and then we have the own modules, they are the own modules, our own modules, the them modules too, which are like the modules created by us, ok, those three module types, which are native python which are written in C, the modules third parties that are modules created by someone more or another company or another person who does not it's us, and then our own that we create to facilitate the life or for something, but they are ours, it fits clarify that the last two modules are it same, that is, a dear party module is the same than an own module, that is, third-party modules are the same as our modules, why what? And because if I worked at Facebook, a module own would be a module created by Facebook, but if I work at Amazon and use a module of Facebook, it is not its own module, it is a third-party module, that is, in terms of file already meaning is the same, but only it depends, if they are not mine I tell you from third parties, if they are mine I say mine, the ones that are different are those that are from python, those that are native because they are written in C, not are any .py files, but are written in another language, are like more internal from python, well let's make a new folder which is going to be modules, and inside we are going to create a file that will be modules.py, this function modules.py will call another function, ok, we are going to create another file that it will be, in here too, module saludar.py, here we are going to create the typical function of greet that we had already created before, easy, def greet name, colon, print f, hello name, I hope you had a wonderful day, if we now for example to this function we print or we greet Just say hello Lucas, when we show the greeting Let's see what it tells us, update He tells us no, because we don't return it sorry we are going to give it a return, we return it and we return this, let's see if we update and hello Lucas I hope have a wonderful day here we have the greeting, now if we wanted to use is function but from another module i.e. I want to use from this module to say hello Lucas and say hello too, how can we do that, well for that we have to import the module, we basically have to access to that module from another file, for that we just use import and here we put the file name, function is import module, in fact here they state that visual studio code throws us the modules that are found in the same folder, we throw the folder in the one we are in, which is the current file even also and greet module, in this case we is saying that we can put this and not is the module hello dot py, so don't know puts, only the name of the file is put, not the extension, remember that a file consists of two parts, name point extension, in fact it is only one, only that when a point is found some programs lo identify and interpret it differently, in this python case only asks you for the name, not the extension, because we already know what it is point pi, then we give it hello module, what does this just visual studio code, that is, well, look, I'm going to read all of them the files let them be dot py and I'll show you the name, So you import them like that, and that's how we end to import the function, if I now for example I have the possibility to call it, this we go to be accessed as if it were a method, ok, it Do you remember the methods that we mentioned above? example, list point append we add an element, something point something was a method, a method is a function applied to an object, this behaves like an object, the file, the separate module behaves like an object, which has its own functions, so if we want to access the method it would be the function is now no longer a function, greet went from being a function to here inside be a method, so if I now for example I put module say hello point say hello, I can come here, this in fact I'm going to delete, because this is already unnecessary, let's see, I can come here and say hello lucas, and this I'm going to match something, I'm going to say hello equal to this, and here I am going to put print Greetings and if I update, if they look, tell me hi lucas i hope you had a wonderful day, I just accessed a function that is in another module from this file, that is the magic of the modules, they are going to use them to everything, because most of the things they do in python, most will not create them you, most of the things you do have to use not one, but several modules, and that is the reality, as well as now I don't know imagine creating a program without functions or loops, they won't go away tomorrow either to imagine creating programs without other modules or libraries or packages or whatever, because is the key to everything, is to understand that others they create code that we can use, which companies create their own libraries or sets of codes, packages and so on, so that we let's make much more optimal codes, even python already comes with its own codes, which is not they are all imported because it would be a program unnecessarily heavy, each module we can import it and use it to our liking, but this is an interesting way to import a module and we have many more, but it has its limitations, because I, for example, here I will always have a greet module and I will to have to use the method, that is, I can't directly access the function, notice in which here I put say hello name and that's it, I have to put module dot say hello and then as a method to greet, because good, because This right here is a namespace object, I actually want you to watch this, I I give module type hello and I update it, they go Let's see what this is, I'm going to give it a print, now if i update, and this returns me a module, a class module, because the object is an object module, and this is called namespace, when we import a module and in this case we need to reference the function, as a method in this case, we are working in this case with namespace, in fact the name says it, namespace, namespace, is such as the name of the module, the way in which that we are going to refer to everything that is within this module is through this namespace, is the set of all methods, all functions, everything defined within of that module, in fact if we look for a second over here, let's see that this creates something called pycache, this what it does, ignore it, is a folder that what it does is create itself only so that the execution process is more fast, so ignore it, I hit delete, I execute it, it is created again, they will see, there it was created again, it creates it automatically Python for their internal things that they do make this faster, then we have an operator that is called like this, which is to assign, as well as for example we say variable equal value, that's how it works in reverse, it's like if we said value as variable, it's something similar, but it works in modules, instead of putting variable equals such, this is backwards, value as variable, not even close to the same, but is a way of referring to the same thing otherwise, in this case we can do it here use to e.g. call the module another way, here we can say import module saludar as msaludar, and here we no longer have make more reference to module greet, We are going to put msaludar and if we execute, here runs and works again, why it is this? and because this what allows us is to be able to assign them names that we know they will not interfere with what we we create, because I create a module greet and here I create a variable called module greet the same hello, if I give you print here and update, this will show me hello, but If I didn't have it this way, this is already going for me to launch full errors, let's put the name complete, hello module, update, now yes and it will throw me errors, why? why we just worked with this, so module say hello, here is what is allowing us is the as operator, assign it the name you let's feel like it, so as not to worry of, to see if there is no need, there we can use it like this, but if the module is a long module and it's tedious and it's gigantic, What's up? we can name it as a module small and that's it, it's a very cool function and allows us to give it the name that is given to us This namespace wins, and let's leave it So, we update and there it continues to work No problem, there we have it, well, actually if we only want to import the function, because for example we are not interested in this, we have a fat function but we want the function run apart, why? and because sometimes this is so, we have a great code, beautiful, but we don't want the code to have a gigantic function that is going to do something that it is unnecessary for it to be there, we want that there is a main code, for example, we have a super big program, so in the first part of the code we do this, in another we do this, and in another we do this, are three big processes, each process It has one, it has several functions running, if each function were such a corn, it would be a terrible problem walking around looking at code by code and a huge spaghetti, then sometimes we say, look, the truth I want separate and make this function in a module aside, because it is so long that I want it to have a specific module so that any error that has anything can solve it here, no problem, it's more readable, it's more fast, it's more manageable, and when I call to that module, I want to import only the function, no to the module, it sucks, I just want import the function, how do I do? easy, we use, we delete this, and we use the from, ok, from, greet module, that is, from this file, from module hello, I want to import only the function, which is to greet, of done, the same, here we do not throw it away, we write oh, it throws us what we want to import, it can be a property, it can be a method, a class, an object, everything we have defined in the module, we will be able to import it, So now, if I take this out of it, it works, and there we have the greet function, not necessarily as a method, but now yes, we can say that it is a function that runs from 10, without the need to go around calling or doing reference to any namespace, if we want add more functions, because we have for example, hello function, and hello function weird, queondaluquitas, I hope you're nashé, anashéli, anashéli, condaluca, I hope that be nashé, anashéli, anashéli, this It's a strange greeting, it's a strange greeting, but young people use it a lot, I have two greetings, wave and wave weird, I want to import the two, and how do I import both, one comma, say hello, comma, say hello weird, and now I can greet Lucas, I greet Lucas well, and to Fran, weird greeting, it's the same as saying hello rare, fran, then I show the greeting, and below I show the rare greeting, I execute it tells me, that Hello Lucas, I hope you had a wonderful day, and fran tells him, tell fran, I hope that you are nashé, anashéli, anashéi, strange, but hey we did it this is a good one handy for working with modules, in fact We are going to comment on everything we are doing, let's say that importing a module and naming it msaludar, then I put import module greet as msgreet, then this We leave it as a comment if you want to use it this form, and here we are going to put from that module we import two functions, there we are, we create the variables with the results, we show the results, here we put, good time with greetings, and here we have discussed the first modules exercise, fascinating indeed this is cool, but we can even rename functions, if I wanted them for example, greet weird had another name, I can put, greet rare as greet as coscu, for example, then here instead of saying hello weird I can say hello like coscu, so there I tell him to say hello like coscu, fran, wave fran, i hope this is nasha, nashalia, nashayyyy, He greets me like a coscu, the same as the coscu if he is Seeing this, I don't think so, but well if it is Seeing this, they love you, they know that they love you love, I love you very much, don't be offended, is clearly an example and a joke, as I'm going to insult you after leaving me present youtuber of the year at the coscu army award, which is your most important event, of done if you are watching this video coscu, you are a great influencer, share it pa, like this more people learn by the sea, you see? hug, give him coscu, do not do the dobolu, you will a do a favor to many people, if you shared This is going to help a lot of people even find some reason why to continue living, to learn to program pa, well anyway, that way we can rename variables, ok, in fact here we can put greet, we can also change the greet, greet as greet normal, then here in instead of saying hello we say hello normal, We import two functions and we change the name, say hello normal, say hello weird, then there we simply have a change made, and there say hello and everything works excellent, later if you want we could also import todo, ok, from module hello import todo, we import everything, in this way we can import everything and there we do not need to do anything, we say hello, say hello weird and that's it, What's up, Lucas, I hope it went well. and it works too, no problem, it works, the topic is that this is a bad practice, because causes the program to become overloaded, very heavy and if the module is quite large, it does that a program is unnecessary, that is, unnecessarily heavy, in itself a bad practice, indeed pep8, which is exactly where we have to go to consult all our doubts, that later that at that end of the course I am going to talk to you of that so that they continue learning, pep8 recommends against doing this, and has all the sense of the world, do not do this is achieved a bad practice, in fact it is one of the worst bad practice so don't do it i know it's a straw to be specific with what to wear and what to do, but do it, believe me it will be a relief for the result then regarding the optimality of the code, ok, now what happens if we import a variable and a function with the same name, because Here, for example, I can say hello and say hello weird, and if now I for example have a name called greet the same hahahaha you you morphed it, what's going on, what's going to matter to me, this or this, because if you look before I put greeting and here when I told him that I care import, say hello, I care to say hello or greeting, I can care about both, but if I suddenly I say I care to say hello, I say to say hello is a variable and not a function, when I care, who is going to show me, well we update, ah it tells me that it is a string, but stop, and if I put it before it will not happen nothing, it will not be executed, it is an error, there I put it before, we executed and now it is executed, but functions are always defined first, that is, whenever we define a function we define it first, then we should put here, and if we put it here and keep it, when we call it from here effectively what is happening, and what happens is that this error does not matter to me, it's fine It's a bad joke, I already tried, as you He said, I don't care about this, no I don't care this, but you are not importing the function, because you are importing the variable, so It is important that we know how to separate the variables of the functions, so when we work with modules, let's separate the functions very well of variables, there are in fact many methods, many bookstores that allow us to work with this, but we are not going to work with libraries, but in this case typically they have to know that there are methodologies, such as For example, we create functions with a capital S, so never like this we are going to confuse, and here we can work them for example with capital S, and there if I care about them well, there it continues to work, run, no problem, there are many methodologies that allow us to differentiate when is a function and when it is a module, a for example is this, which is to use the first capital letter for functions and for variables start with lowercase, well there it is, anyway, it was just an example, let's get this out, leave everything as it was, there it is, perfect, well, anyway, there we are, an interesting thing is what happens if we enter this and give it dir namespace, in this case it is a healthy module, here we should give it, get this out, in fact we're going to comment on it for now, and the one above we are going to uncomment it, and we are going to put msaludar, to see what it is what throws us here, if I do print dir msgreet, when i update this code, show me this, what is this, well remember that dir throws me all the properties and methods that he has, and here he just tells me, che look, you have a function called greet, and a function that calls me say hello weird, If I put a variable here, for example, Greetings the same, haha, when I update this, I update and it tells me you have to say hello, say hello weird and now you have greeting, greeting is a variable, say hello weird is a function, and say hello is a function, throws us all the things that we define, right here, everything that is here is part of the object, everything that is here It is what we create, that is, everything interesting that it is also good that they know, in fact here I am going to add, to see the properties and methods of the namespace, and I comment on this obviously, and I comment on all the bad things, strong it was, and I am commenting on this, it was very strong, we updated and everything is as before, an interesting question is, what if we are going to import it back, import module say hello as msgreet, let's go to import it back down here, we import it twice, say hello, but what if I for example I show msaludar.name, what works for me to show here is the greet module, which is this is the module we are importing, that is, what this shows me is exactly the module we import, this is the name, if we want to access the name of the module, here we import, we use this, from done if I, for example, come here and put name change, when I update, here I am says it's false, why, why can't we equal it, if I give it a single equal, neither let me change, it's not a property to be I can change, but nothing, it's good that know that you can show us this, in fact if we go here and show print name, we update, is going to show us main, why, why says that this is the main module, and if we came here and we show name, here too it will tell us main, because main refers to because the main module, that is, the module that is running is this, it's good, It's interesting to see what's up with this, we agree to the name of this module, and here we put, we access the name of the called module, it is well this, because once we rename, once we rename the file, the same we can access the name, it's good this, we can have it as a variable, now Let's see the routing section, for that all good with this, but now we have to see the routing, that is, how can we from one file call another well, like we can move between folders, as we can add it to a path with all the files, How can we see where all the modules are? that already exist from python, and see the tidbits more, it is important because we are going to use them quite a lot, in fact thanks to that we are going to be able to use all the modules, so let's go with that. Ok, now on to the performance issue. modules, it's basically the same, but it's about how to move, right?, at the time to call modules, why? What if I, for example, instead of have this folder, right?, modules, and the file module greet, the same folder, I had another folder that already... Good features, there it is, better features good, and we put it in there, what happens now?, what do I call it? And if I now run the same program as Before, I get an error because I can't find it, well this is easy, the way to call it is, remember that the name is going to throw me here of what you find, So there we put, good functions, period, greet module, and in this way we have just walk through, ok, we update, and it's functional, Why? Because what we did was access to this folder, and within this folder, he searched as if he were right there, and found this file, so It matters, that's the way we should access, if we were to access a module inside a folder. Ok, now we are going to delete this, and we are going to create a new file, in fact, module say hello, we are going to leave it, and here in functions good, the module that is in here say hello, we are going to pass it on to modules, we move, there it goes, we delete this folder, and there we have the greet module. We copy the greet module, paste it here inside, only now we are going to rename it and we are going to say hello, just say hello, so we can differentiate the greet module, to greet, are both modules, only one does not have the module ahead, so we can separate it and do something apart, where, and in another file which is, modules 2.0, or 2.0.py, here it goes, So here we are going to do the same, from, or easier, import, modules, rather, good functions, point, module greet, or in this case say hello, because it is no longer called more module say hello, the file is called to greet, Well, now we come here and we put print, for to show it to us directly, say hello to Lucas, let's see what this throws at us, now see what's up with this, we enter greet.py, is not working, why it's not working, and why it is, we were using it as a namespace, like so what would it be to say hello. say hello, now yes, we update, ah, it doesn't work, why doesn't it work, and why now it's good shows.say hello, Now it runs correctly, see, exactly, this is how correct, and why does it return us this name, and returns that name, because here we are telling you that it shows us the name, it's great is showing us the name of this file main, modules 2.0.py, and shows us the name of the namespace is spectacular, because We are not here, if I execute this here, shows me main, but if I run it here, it shows me this, and what is running is this, is what same, just run different contexts, in this context it returns us that, It's an interesting thing to keep in mind. so let's name it, let's put this, like, no, we're not even going to do it, Let's leave it like this so that it is understood, no, let's do it right, as saluting, m, say hello, the same, m say hello, now we put m, underscore, say hello, and now if we have the same thing, and it works out of 10, now, What happens if, for example, instead of being inside a folder, this folder would be for example outside, yes, we move it, and now the function is here, good functions, what happened, well, let's go to try to access, functions good, period say hello, oops, can't find the module, oops, What do I do now, it's a folder behind, Well, what we have to do now is, import sys, ok, actually we're going to do one thing, let's comment, if the module were in a folder in the same path, it is imported like this, ok, it is imported like this, but as it is back, in a function outside, what we have what to do is do this, import sys, sys is a python module, So now, I'm going to delete this, and What happens if I, for example, now give it, print sys, update, let's see what it throws at us, It tells me sys, it is a build in module, which means this, which is a module built in python, which is what I was telling you, a module build in, build is build, build is built, I think that once before I said build, build is build, and build in is integrated, like that has already been integrated, in fact there is a property, remember that we access the functions So, and the properties like this, then we put point, build in, module names, here we pull the property, and this we are going to see that It is what throws us, this what returns us It is precisely a tuple, with all the values of the properties, and they remember that before he gave us something back seemed to say, well now what brings us back are all the names of all the modules, which are in sys, we have the nt module, we have the sys module, we have the module time, we have the zlib module, we have the audio module, come if I go upstairs and Now I throw this up, we got a lot of modules, which are all these that are here, functools for example, which is widely used, operator which is widely used, winreg to access to windows logs, array which is for work with arrays, later we will see the official intelligence course, we are going to use this that is here this module, here we have the modules, the classic modules from python, in fact they are created in C, interesting that data, this is good because you can create modules that do not match these that are here, because if you create a module, and the module that you believe already exists and is here inside, for example your module is time.py, which you here time matters, this will not import your file, it will import the native python module, the built-in module, so it is important that they know that python gives priority first to modules that they are native. Now how do we know where they are staying the modules? Well, here we say sys.path, path has exactly the route, so here What we are seeing is a list with the module path, the first route that returns us is the route current, we are here, if you look we are on drive C, users, rainbow 6 that is the name of a game I created this with Username, desktop which is the desktop, and on the desktop we have a folder called python course high, it is like that, indeed this one is here, and another folder called modules, that's right, this one here, and right there we were hosted and calling the program from now on, It's true, that's how it works, exactly, it's the route current, in this one here are the modules installed python, ok, easy, and if not we want to add it here, that is, if we want to be able to import it, and our route is not there current, we have to add it here, and if not, we can add it in another way, suppose we have the module here, not? remember that we have good functions, well how do we add it? simple, in this case we have the route, the route is this, well, we have a route back, well, I'm going to copy up here, and I'm going to come here and put a point, in this case I'm going to take it out, I'm actually going to come over here and put sys.path.append, and here I am going to put the route that I copied, only which is now no longer in modules, are good functions, and here I am basically accessing the this folder, and now yes, that's it, that's what yourself, remember that we are here, on the road current, and good functions, this that is here is the route where hosts the greet.py file, so now If I update this, they will see what it shows me, ok, the code, there I am updating, They will see that it is showing me the code, at the end is the path where we added the last module installed, i.e. first path, our route, all other paths are installed modules, I just installed this module, which is going to be valid only for this session, if we want a permanent module, we install it in another way, with python.path, that's why it's something else, so now if we want import the previous path, we simply say say hello, So if I, even if I don't throw them away, and I Say it's a bug, it's not a bug, yeah I now for example I put print greet.greet, I say say hello to Dalto, tell me the code, hello Dalto, I hope have a wonderful day, actually here I can put the greeting module, and here I put the same, greeting module, it's ready and it works for me, it works the same than any other module, what is the key? this, is, che, look, the truth that It's not in my path, I can't access that one route, Then what do I do? and I add that route here, and once i added it, now i can importing the module, normally, is good let them play, believe their things, if you got to this point, believe your stuff, create your modules, try a little, don't continue the course, if not, you will do it on your own, okay? on your own, create a couple of modules, create for example some module that has some calculator, and a module that is for functions math, another module that is to say hello, and another module that is for something else, and unify it all in a program that can allow you make calculations, that can allow you to say hello, and various other things, to practice, let's say, to move and handle logic, so that when we have to do real practices, that at the end of the course we are going to do it, understand how to do it, because if not, they will not understand the subject of priorities, what if they matter things with the same name, what are the degrees of the hierarchy, that they will realize also trying it, because that's why I explain them to you, but They're going to forget unless they try it, okay? everything we do, I already told you, take it In practice, all this has to lead to practice, and this is basically the very quick vision of what they have been the modules, because we did not do exercises with modules, yes we will do them later, but This is to give you an idea of ​​how import them, right? how to call them, how to use the AS operator, how to add, say, other modules that they are not on our same route, and so on. Now we go with another important section, which is the packets, ok? We have to see what the packages are, we have need to understand what modules are and what are packages, because a module is just one Python file, one package is many files python, so let's see how this topic is the packages, let's start, and now yes, Come on, let's not waste time, let's start with packages. Okay, now let's suppose that I, in here of modules, I'm going to create another folder that it's going to be a package And package will also have the greet module I'm going to copy and inside the package I'm going to put the greet function And I'm going to put another function that says hello copy But greeting is going to have a function, I'm going to make them different modules Greeting is going to have this function that is here, the common And the other one is going to say hello weird, there goes And I'm going to change the name to be say hello weird There I have two different modules in one same folder I'm going to put this folder in here, there It's done, I put it inside I got all this right, let's create a new file called package.py Suppose now suddenly I want import a package What is a package? A package is a folder with many python files Simple, many modules, one folder with several modules What is the difference? It is not the same matter a single module that is a file Than import many modules together, because sometimes we don't have one, we have many modules what to care Because modules don't have to do much things, okay? A module sometimes has to fulfill a function specific That's why it's a module, it's a part of the program that performs a specific action When we have a well-done program, we have many modules So if we want to import all those modules together and not go around doing it one by one We import the package that matters to all of us the modules They can be 10, 20, 30 and we do it in one single line of code How do we import it? Ok first the key to differentiate a Python package It understands that it is a package if this has a file named init.py Why did we create this file? Does not have to have nothing, that's it, we close it It's a file that Python says, let's see, is it a package or a module? Ok if it's a folder and you have file then it's a package If we come here to package.py and we import package If now we come here and give print type package To see what type of data it is, it tells us that is a module But despite being a module, this is the same it's a package Because a package is still a module, is considered a module But theoretically it is a package If I for example the function, sorry, the init file dot py will delete it I update this and it works and it tells us that it's still a module What is the difference? It's a routing issue. fairly Here the problem is that Python to search this between, let's say To find the files and subdirectory if we put here for example Point path, we use this property and give it there, we are going to see that it does not allow me to access to attribute Now if I return the py attribute, there it is, and i run this program Now you give it back to me, why give it back to me? Because now it has this attribute, now the Python understands that it is a package So I update and now notice that I returns the path of the package He treats me as a package, I repeat, I delete this, I update and throw an exception I put it back, this is with control z, with control z I undo the last change So I come back here, update and shoot to the list with just the package This is the same, it has to do with a theme that you can help me look for it within the file as such So if I now even wanted to access to a module, I can just come and say point say hello And here I say, for example, show me the package point say hello And here I say dalto, so this that I show, function and is working Only now we are doing it to through a package We access the package and from the package we access to function This is almost like accessing a file inside from a folder Only now we are telling you that we are not accessing the file We are accessing the package in its entirety Since the package was just added to the path where we can find all the rest files Well, anyway, there we have it, there we were seeing the differences Then we have the sub packages, which are as packets within packets, it is not so complicated When we import a package and it is inside from another package, it is considered a subpackage What if we call a file that has the same name as a package? That is, if for example I have the folder package and I have another file called package Who will you give priority to? And to the folder always gives priority to the folder If we want to import a subpackage, it is same, we do exactly the same For example, we take a package and create another folder in here And here we simply put package.subfolder And subfolder would have to have the init.py So if we put subfolder, now we would be importing the package subfolder Which in turn is a sub package of package It would be a subpackage only if it is a package That is, if package were a folder, that is, if I didn't have the init.py We are simply accessing the folder package to package subfolder But there would not be a sub package, that is, a subpackage is a package inside another package Not a package inside a folder To be considered a package, it must have the init.py So if there is a folder that has the init.py inside another folder that also has the init.py There we have a sub package and a package So nothing, they are conceptual issues, so there we have the idea as such They already have the idea and the notion, which is the important thing And they already know how to create packages, create sub packages, access the different packages, create modules, access modules and everything you need So now we are ready to move on to a section of this same section What is to access the files Because now that we know how to access the packets, access modules and so on There are some modules that allow us to work with files So what if I invite you to we access a module that allows us to open files? Or rather, will we have to access modules to open files? Well, let's see how to read a simple file TXT, let's go with TXT files to see how we can manipulate a bit with Python What is one of the most common things? I love this part. Come on! Well, now we are with a section that is important, since we are going to understand well how the issue of reading files works, the topic of writing files and how be able to manipulate them with Python. Yeah, that is, we're going to use whatever we come learning to learn something new and give it a utility so that when more in the future we have to implement them in some projects we can do it. Because it is the most common thing there is, reading files, writing on them and knowing how to manipulate them is one of the most important things in any programming language. Since files are normally created, they are read and are manipulated in any program that would normally we believe that it has an intermediate functionality advanced. So now we go with the basics to understand first what is a file, how to create them and how to manipulate them with Python. Ok, well, for starters, a file is what that we all know and it is simply a information container. Because many may have the idea of ​​what which is a file, but they do not know well well what is a file. And it is that, it is an information container. They also have a format. The format is like in a programming language a data type, just as we have strings, ints, arrays and so on. Right in the archives they have their own data type, if eg.png is a image format, if .wav is a format audio. If it is let's say mp4 is an audio format and video. So the files have to understand which are composed as to the name of two parts, name and format. If for example we have an Excel file, we have a file containing spreadsheets, we have just one file that can contain video, image and everything we were seeing. So in this case we are going to learn how to manipulate two types of files. The first is.txt and the second is.csv..txt it is a plain text file, very simple. Well, to speed up here I have created one folder called files and a file called.read.txt.py. Ok, so now let's start writing k code First we are going to go to the blog of notes, the famous blog notes, and we're going to write two lines. The first line is, if it's working for you the material activates the bell, what a bell Don't treat yourself teacher, don't ask. And in the second line of code we are going to Put a lawyer, what a lawyer, don't ask, don't donate, again. And we are going to save this in the same path, in the same folder files, dalto.txt text. And in this way we are saving it and here It can appear to us on the route. What we have to do to start is give to the open function, not literally give it to the function open, but let's say write it. And here we are going to put the name of the file, in this case it is text from dalto.txt. But if I run this and we update, yes look, in my case it will throw me an error and this has to do with a topic of routes, routing. What you have to do is give it the name of the folder, in this case the container folder files, then I give you files. We put two bars, how do you do the two bars? Don't ask me, I copy and paste. It's the backslash, there are characters for put it the same if they have a common keyboard, because then to have an advanced cross of Python will minimally set the bar reversed. Here we have this, if we run now, if we fix does not throw us any exception. Now, this file we have toNow, we have to equalize to something, because if it's already there we open it, but what are we going to do with the file, skinny? We have to do something once we open it. What do we do? We give you file, the same and what we just wrote In this way we are making the whole file already equal to this variable, so Now we are going to display it on the screen. File, we update and well, here it shows us all some weird code, that's because we had open the file. But we didn't read it, in order to work with the file and the material inside we have to read it. How do we read it? With the read function, we put point, read and here what we do is update and one says if you are serving the material activate the bell. I repeat, do not ask and then one says lawyer, what lawyer? Don't ask. So there it is and we have the file and we are reading it, now if you look at us throw this out here. Why does he throw us this strange A that is here? Ok, for a coding issue. We have to set the UTF-8 encoding, which is a universal encoding that reads all characters. So if they are on another operating system or using another type of encoding can don't get the error. But if you miss the way to fix it It is here we add the encoding, the same there it pulls us, mind you. UTF-8, so we already updated. Now yes, notice that we have no problem. Why? because we have the coding It's beautiful, which in HTML reminds you if they saw the little course, what if they didn't see it they are going to see it, they are going to put posi and they will see it. What we were seeing is that when we had a mistake sometimes, that they threw us, they didn't They didn't take the commas or the accents either, I don't really feel the accents, the accents I didn't take them. So what were we doing? We used the label metachase UTF-8 and with that we made everything be converted to that encoding that was, Let's say universal. So good, now that we have this well no problem, we are opening this file with UTF-8 encoding and we are Reading. Now, this we can equate a variable, that is, I can say file without reading, is this, and below I can say same file unread file dot read. Now if the file is unread point read is file we are doing the right thing because we are saying the unread file now we are reading it. So now we have to put a file, not an unread file. Now we print, file and we're done showing just this, the same code than before. Ok, it's the same but cheaper. Another thing is that if you press alt more shift, ok, there you see I change the language enter, are changing keyboard language. So now, for example, I come here and I do some little things, ok, like they stop work or don't work, that's because of the language of the keyboard. Ok, I remember what happened to me at the beginning that I showed them that we had other characters of those that are not the keyboard, at least from here in Latin America, that's because the language changes and when change the language change the characters So, for example, I press the key the keys, throw this at me, the common keys. But if I press alt and shift, ok, when now I press the same sign, it no longer appears and something else than nothing appears to me, which is like a kind of apostrophe. So it's important that if that happens to them, alt plus shift and there you have them back keys working correctly so as not to have than to go around doing the embola. And now, for example, the accent works fine for me. Then I made them do two lines of code here, if you pay attention, of code, two lines actually of text, due to the fact that I am interested in working with individual lines. How do we go about reading a specific line? Well, here we can say for example, file, or rather, line1 is equal to file.readlines and this is what is going to return to me, if you pay attention let's use it on unread file, file without reading. Readlines what will return me is an array with all lines Let's show you what line1 says, from fact is lines, not line1. Line1 would be if we put readline here, ok, If I put here, for example, readline and I say show me line1, if i update this it shows me what is wrong with me showing is the first line that in this case has nothing. If I now, for example, tell him to show me readlines, what will show me in line1 is an empty array. Why is this? Ah, it's not because line1 has nothing, it is because once the file read can no longer be read. Why? Why don't we close it? When a file is read, if we want to return to read it we have to close it, if not already the process we are using it for was used. So once you read it, you can't go back. to read, for file security reasons. So what we should do is directly, in this case put this line, we are going to comment, read complete file and we are going to comment the line and down let's say read line by line, and in this case we read line by line with this that is here, which is lines equal to files and read readlines. If you look now I put lines and when run the program, lines, lines, and when the program runs if you notice this returns me a list, a list with this and that. What is this here? this bar N, backslash N, is the form we have to interpret a space in a plain text online. If I add these to any plain text characters, which is the backslash and the No, We are telling you that we are going to leave a space online. In fact when we have to write about a file will see that this is the way in which we can leave a space online. We can write a lot but the space online is only left with this character. In fact if we want to read a single line we can do it as follows. Read a single line, ok, here we are going to put it, We are going to comment on this, and here we are going to say line equal files and read point read line, no lines, line. And now we are going to show it, print line line, It is true that we are in a course in Spanish. And here I only read the first one, if this is following the material activates the bell. If I put two here, he says yes, yes I I tell him to show me one he is showing me the. Let's see if they can guess what is wrong with me showing, if I put ten on it, it will show me many more letters Why? Because what we do with read line is if it doesn't read the whole line, it reads the number of characters we told you. If I put a hundred here, this reads me the amount character limit and I have a hundred to spare. One hundred characters that are reading me in read line. What I recommend is if you want to read the first letter, done, great. If you want to read the first letter or the first letters and so on, gem. If not, use the complete read line and that's it, there we have. This read lines thing is interesting, why? what is interesting? Because before what we did was to use this, which is to use for. And what we did with the for was read this of several turns in the loop. We used the rstrip function and with that, with that function what we did was put this in a for loop and with the rstrip function we could read line by line. Now we can do it directly with read lines. The only problem with read lines is which for large files can be consumed all the memory of our computer and you can run out of RAM, basically out of memory. So it is important that we know how to use it with conscience and for now we are going to stay with this solution. As we understand that they are not very large files of text, we can use it, but when they are very large files we have to work with other processes. But it is important that they know what they are doing. You always have to think carefully about what is what we want to do and when we understand it, if we already have it raised, find a best way in code to get it done. It is easy. Once we open the file and that already we finished using it, we have to close it with close. Close the file and here what we do is say for example unread file dot close. I wouldn't say unread file, but in this case now we are going to file. There it is, easier. And now it's unread file, close and we use it. We update it and sorry unread file no, file. We update and now yes, we run the program and he tells us that now, well, he doesn't tell us anything, but this closed correctly. In fact, now we could read it again and we give it a print file dot read and this read us the code again? No, because once we close it, file it closes and if we want to read it we have than to use the open function again. This is interesting, but we can store the information we already had and use it as we want. In this case, we use this read function a single line and we already have here the first line of the file, read without problem. It is important to close it, otherwise the program You may lose data by closing unexpectedly. Many files just don't store the information until the program did not close. Also, it's important to close it because sometimes the operating system limits, the file itself limits the number of times it can be open the same file. That is, for example, I want to open a file and sometimes I can open that file with a program but not with others. In other words, it limits the number of times a file can be opened by the same programs. It doesn't happen to them that sometimes they have a program or some video or something open and it tells them... First close the program with which you are using because if not, it can't be opened. That is because it is opening and working with the file. Once the file is closed, there already can be read back. If we don't close it, we can't open it from other places. Even some files can only be opened by one program at a time. Besides that, finally, when we close the file, we release the resources that our computer you are using to process this file. How do we solve this problem? What solution does Python bring us to avoid close the file every so often, lose all this? Well, the solution that Python brings us is an interesting solution that is... With Open. Now let's see, this we are going to leave it like this and we are going to open another file new. A new file that will be LerTXTOptimamente.py. And I say optimally because WITHOpen is the solution and how to read now that we are using when we do it natively without libraries, which is WIthOpen. Now we are going to see why. That is, for, for example, CSV it is good to use libraries like pandas, but for TXT is not necessary. I can do it natively like this and it's very nice. So the form is, instead of WithOpen, we give it WIthOpen and here we put the name from the file. For example, LerTXT.py, which is the name of the original file. And we are going to put the two backslashes, file, backslashes, LerTXT. So there we give it two points and we go to see what happens here. Let's put print, hello and the hello leaves to execute only if the file is achieved open correctly. Sorry, it's not LerTXT.py, it's not this. Dalto punto text, if I close this, Chivos, bar bar. Let's see what's up. There it is, it's working. Now yes, say hello. Perfect. There he returned hello to me. This means that the file was opened, executed the code in this block and exited. The file has already been opened and closed once the instructions have finished. This is the optimal way to open a file. If not, we don't have to go around forgetting to close it and else. Remember that every time we open a file, this opens with read mode. That is, read. The read comes by default because what we are doing is reading it. We are reading the file, so we are not writing. To use it we have to use the ace, not the ass. But the word as to refer that we are going to change the name. In this case we are going to say as, file, for example. So in this way, because before they told me che d'alto, you had a file before. How do I assign the same variable? The same. We give you ace, file. There is. So if we now say print, file and we update and run the program, it throws us this. Do you remember what we had to do? We give it read. So now yes, if it is serving you the material, activate the bell. Lawyer to which lawyer? We use the same here. We give it encoding, utf8. There is. We update and we have the same as before, But better. Now we can say back that it's the same, but cheaper. The same, but cheaper. The same is literally cheaper because it consumes fewer resources, it is faster, it is more optimal. So out of 10. And it is also faster. In other words, in code it is less. notice. We can do everything we did here, in here. In addition, this will open brings much less exception errors. Open throws us more errors and this one is less. In other words, better in every way. In this case we are going to comment this code, this that we lack We are going to tell you, assigning the file that we open with a universal coding. Or easier, using open to open a file. File with a universal encoding. Here we say, we read the complete file, read single line, read line by line and else. In fact here we could do this. We can equate this to this here. Luckily we changed it because if we don't it would look bad to uncomment it. There is. And here we can say, for the line to read, when i update i got an exception. Because file is not the same as file closed. This in this case I will comment. There is. And I'm going to leave the file here. So we have the example. And now we are going to try to do the same as this in the previous So let's do it optimally. Here we say, opening the file with with open. Here we say, we read the file, content same file.read. And here we say, we show the file, print contents. And we put it down here, it is not necessary to close it when using with open. And there we have exactly the same as before. Only that we have a more optimal code. Now we are going to create another file that will be writetxt.py. Let's write them. Instead of going around now reading them, let's open them with other types of permissions. Let's open them with a write permission to be able to write on it. Well, for starters let's say, let's open the with open. With open. And we're going to open the same file. We are going to use the two slashes in files. Files, slash, slash. Let's use single quotes, files, text from dalto.txt. The universal encoding, utf8 encoding. Here we are going to say ace, file, colon. But here we have to add an extra value. What is write. In this case we will put it before. And now the coding. Why? Because the second parameter write. In this case it is being referred to that we will have a write permission. Let's write to the file. And now we can write. If, for example, I write file.write and I put hahahaha the recontra teclie. We update. And it seems that he did nothing. But if we get to open the text file. Pretty strange that noise. Yes Yes. My file explorer closed, people. Well, don't do this. Lie, everything is more than good. Joined the explorer? No no no. Now we open the file and see what it says hahaha teclie recounts it. But what we have just done here is rewrite the file. The theme of this, as I told you, is that this what he does is write to us. And overwrite the file. It does not save the information because it does not read it. He does nothing but write it. And in this case if we already have a file. We have just overwritten it. And we basically shit. So on the one hand we have write. And on the other hand we have write lines. Let's see what this function is for. In this case, if I am going to comment on it. I'm going to put overwriting the file. So that's how I'm going to comment. So we more or less know that we are overwriting. And here if we put write. In this case file. Point file write lines. And here I am going to write something. For example, hello teacher, how are you? Let's see what happens. Here, for example, I am going to press enter. It seems that nothing happened. But if we go to the file and it says hello teacher how are you. What happened here? It is that if I put a comma here and write another stuff. Like mercy. Why did I put this word? I don't know, but it was very unlikely that he would put it on. So I just put it out of context. I update the program, I run it. And it throws me an error. Because it says that only one argument is requested. And there are two left. Why? Because what we are asked for here is an iterable. Here, for example, I give you a list. And here I put the word mercy. when i update. Now if you just did something. We come back here and he says hello teacher how you walk Mercy. What does this do? What this does is it writes lines. We can pass him. It's like the reverse process to read lines. Do you remember read lines? Who reads the lines. This is like the reverse process. Instead of asking for them. And that returns a list with all the lines. This is what it does. He asks us for a list with all the lines. What happened before is what happened to us. If they agree on this type of files. Easier. Specifically here. Let's uncomment this. And ask him to pass us the lines. In this case. If we run this He returns us if they remember. The lines. Okay. All lines. But let's leave a space below. We update. And now we're going to run it again. The one here And we had this here. For the online space. So if I am here. I paste it here. In this case we are going to paste. Here this. And run the program. Now he just wrote me the same thing. I'm actually going to delete this. I will update this. And if they notice Now it's updated. And he left me the space online. It is literally the reverse process of Readlines. Because instead of repeating Ask it to return a list with lines. We are passing you the list with the lines. And we leave the online space with a bar no. Backslash No. What is the universal way to leave spaces? online. In the emails. Wherever you can imagine It's interesting. Because in this way we can write several lines. Now. What happens if I use twice. For example the function Write. Or the Write Lines function. They both write. They always overwrite. If something exists, it overwrites it. And if you don't believe it. What happens if I use it twice? Let's try. If I use it twice. I'm going to put another text here. To differentiate it. update. And let's see what happens. Obviously it works. But what happens is that he writes to us both. Now it does not overwrite. Because Write Lines. What it does is kind of builds up. If we put this Then we put this It's like we do something similar to this. In fact. I'm going to show you. Which is like we did this. We update. And I don't change anything. Because it's the same. If we put this Only that. Let's add it. And we can use it. For example. In a loop. In a for. If we want to add information. In a for. We can add information. And use this. It's like the reverse way. That the functions restrict. And I commented to them. Well. Something like that. So in this way. We can add lines. For example. Here I will comment. I'm going to leave a space. And comment. Adding two lines. With Write Lines. And I'm going to put it down here. Adding. Two other lines. In fact it is important. At the end of each The result. And let it be line by line. So here we put Hello teacher, how are you? Mercy. I dont know. Why I say that. Neither do I. So here we put As if it were a conversation dialogue. And there it is. We run the program. And when we go to the result. We have. Hello teacher, how are you? Mercy. I don't know why I said that. Neither do I. Here we are going to change it. And put. I don't know why you said that. We run back. And we already have the dialog created. 100% from Python. Okay. If they have a keyboard with numpad. What they can do. It is to press 92. And it jumps out. And they have to push. The CTRL SHIFT. OR. and C5. And then release CTRL SHIFT. OR. And they keep the 5C tight. Forgiveness. 5C. And there the inverted key will jump. If they don't do like me. They copy and paste it. And ready. And so it is more or less. how we write We read and so on. And we work with files. In fact. It is so simple that if we want. We can give it in append even. If I now for example. Add. Txt.pa. And we are going to do the same. Let's come here and copy. What he says to write. We copy it. Let's delete it. It seems that nothing happened. But when I come back What it did was give it an append. Because the append. It does the same as the write. Only that the write. What it does is overwrite everything all the time. While the append. Every time we run it. A. Two. Three. I ran it three times. Now I have three times the same code. Because what append does is add. Here for example. I'm going to delete it so that we don't have this one foulness. But every time we use append. What it does is literally add us. In fact what can we do here. It's me write write several times. For example. And now I write something else. I put the one forward. I give it F5. And when I come here What it does is. Write one first. And then the other. We can actually come over here and use a loop. For example. For. And in range 5. For example. And here to say File dot write. Line. We are going to use F. Here added. Let's give it I plus one. And now when we run this. It was done. Ran. And here he tells me. Line one added. Line three added. Line five added. And there he throws the whole can at me. To give the bar N at the end. Bar No. So you can leave a space online. So I am going to. Delete all these lines that I add. Neither do I. Haha. I'm going to leave this here. And this I run back. And now if you look. Line one added. Line two added. Line three added. So more or less we can work. Adding the file. Using a loop. To add. several lines. In fact. Here we are going to use He wrote. Before the for loop. File dot write. To simply add An online space. Before it starts. This is for what. Let's have the program. And there it worked for us. And it started from here. There it goes. Perfect. Adding. Lines. And even if they want to. I challenge you. To use for. 9777 06:14:29,130 ​​--> 06:14:30,130 In a single line of code with this. This can be. Use. With a single line of code. So. I challenge you. Let's see if they dare to simplify it. Okay. Which is quite simple. So. 9787 06:14:39,130 ​​--> 06:14:40,130 I leave them. Now that we more or less know. How to read a TXT. How to read it optimally. And how to write. And add more information. That is to say. On writing it and working with it. Let's see now. As is the subject of writing. Work and so on. With files. Go. Let's see now. Ok, now we are going to work with a CSV file, which the name literally means, Let's say comma separated values, ok? So let's get to work directly creating a new file to be called Ler.csv.py This is something unusual, I have the notifications deactivated, but for some reason I ran out to make a notification Which group? From our family group Beautiful, my aunt, let's put the airplane mode, so nobody fucks us It's what you have to do when are viewing this course, add the mode plane, okay? And they start to see the course because the cell phone is the biggest source of distractions I am very sure that throughout all this course, some notification sounded or with something they got distracted and that's where they diverted their attention Now they grab it on the cell phone, put the airplane mode, they suspend it, they leave it there without problem and they give And if you're watching this cell phone course, something is wrong here, it seems to me that something is not it's working because who sees a course cell phone programming But hey, it doesn't matter, everyone does what What do you want with your life? So good, let's create this file and now we are going to start working To begin with, if we want to read a file CSV, in this case we are going to create a file CSV any The first column will be name, the second last name, the elderly So, here in the first one we are going to put, let's put a comma the same Let's put Lucas, Dalto, let's put 99, well I am 99 years old And below we are going to put Roberto, Insane, 42 Here we are going to remove the commas to make it numeric type, there goes, 42, comma and space online And finally here we are going to put Camila, Daltyx or Dalto And another space that will be the age, that will to be 24 We update and here we have a CSV file, let's save it as data.csv We close the file and we already have a code CSV, something you can easily interpret excel or whatever If here we give data.csv, here we give colon, print data read successfully We run this and welcome we throw the exception, we have to do what we did before What is to use files two bars, ok, we use files two bars, we run And now that we are running it tells me data read correctly But indeed this read the data correctly for me, ok let's check it out If I now say print, here we are going to assign it a value, as file and here I give it file.read When this is running we read this which is here, but we are going to import CSV, the CSV module And now with this import we are going to be able to read without any problem Here we do not use read, we use CSV.reader, now it does change the matter And here we put the file, we run this and when we run it, now, another mosquito In the fourth scholarship a mosquito appears in this Course, don't tell me Look what they brought me, not how we are doing to advertise this brand and less when it comes off Well, anyway, let's throw a little bit, I you saved Sai, thank you very much, it throws like this not? If you hold it tight I found out it goes better wow amazing In my cuatronia of assholes Then I take us home, but kind of calm Did you see that at least the mosquitoes don't either But I am sure and I am calm that was that off oh well that's too much My dear friend Sai came to keep me company and he came to give me a little hand to suffer with me the heat He said, well, how are you going to suffer? for the Python Boy course and accompanies you to suffer too Well, here what we have is a CVRader object, with this we can do many things With the standard CSV library we can work with CSV in different ways Because we have something like DataFrames, which are not DataFrames as such But you can manipulate them to do things If I here, for example, do this and say Reader, same, file, easier, CSV point Reader, archive And now I have this here, I could show it As we have seen before, PrintRader We show it and we get the same thing as before, the object Since I loop through it and it is an iterable, then we can walk it For, we put Row in Reader So this is what we are going to go through, let's say, are rows by rows Row is a row, so we can traverse it the rows Colon, PrintRow and if right now we traverse shows us this as rows And now he is returning lists to us with the rows If you look, name, last name, age, LucasDalto99 This final extra space that he leaves us is like a fourth value Why do we have this fourth value? And that fourth value is an extra value because in data, if you pay attention, we leave you the comma So we should take the comma out of it, update it And now when we run the code in read CSV, here it is Now he interprets this to us correctly, because in a CSV is separated by commas and by space online So it's, value, comma, value, comma, value, online space Value, comma, value, comma, value, space in line and so they separate The former are technically interpreted like the names So, for example, when we take them to a Excel This interprets it as if they were the names of the columns They saw that above they put the name of the column Well, and the rest are the data from the columns This is what we really have in one eye calculation, for example So this is how we are reading it all right And here we have three data The name, which in this case is Lucas, Roberto and Camilla The last name, which here is Dalto, Demential and Dalto And then the ages, which are 99, 42 and 24 So now with this information we can work because we are reading the file But my recommendation is that when we work professionally with Python and with files I do not recommend reading that with this bookstore Rather, I recommend reading it with another who knows calls pandas That first we are going to do the process of this same code and read it with Pandas And then I will explain the differences But professionally when we work in analysis of data That in fact for that we usually want to read CSVs In data analysis where we aim on our learning path What is artificial intelligence, analysis of data and others We are going to work with data analysis and with this So it's important to keep in mind what are we going to learn Pandas It is a very important python library that allows us to do this but better And it is more professional, it has many functionalities and fewer limitations than CSV So we go, we create a file that is Read CSV with pandas.py And now we do something that's pretty crazy What if we suddenly want to import Pandas? I give it import pandas as pd The acronym of Pandas with which you usually work is ps When you want to call the bookstore panda They have to assign it as pd Because it is something universal that we all put on it PS to identify her So now we just imported it But if I update the code and run it It tells me that there is no module called panda So let's start installing it First we are going to come here to cmd Ok, from Windows, type cmd Right click to run as administrator OK yes And there it develops, I'm going to close it The first thing we have to do is install To see if you have one installed you can put pip And if it doesn't jump they can put py pip If it doesn't jump they can put py-m pip So I can effectively see that I have installed pip Because if I didn't have pip installed I wouldn't throw this, so I have it installed Well if you are on Mac or Linux It is important that you understand that you can find the official documentation on the page If you have already reached this point in the Python course It is very easy and you will know how find her They google how to install pip and how install pandas And they will be able to do it I am going to show you the process in Windows And you can do the equivalent on Linux and on Mac If they have Ubuntu it's the same they will be able to do it too You will see that several sources jump here You can go official if you want. What is pip documentation That if they translate it into Spanish, it works for them to explain how to download it They have, they say, if your environment doesn't have installed pip There are two mechanisms to install pip Directly supported by maintainers pip Headpip.py which is the common one Here we have in Linux, in Mac OS or in Windows So they tell Windows now, they tell it the Windows Well, let's go to Windows Because how do we translate it into Spanish? Windows is Windows Here it tells me how to get this It says here that Python comes with this module That you can install pip in the python environment So what we do is copy this into the CMD We give CTRL V And there pip is automatically installed That's it, it's installed, we already have pip Once we already have pip installed, let's to verify it To verify it then it is simple Py yom m pip And there he already throws all the data of what Can be done It's simple, when you have pip installed We can proceed to install pandas This is the same, it's Py yom m pip install pandas they press ENTER And there it will install pandas, it will start to run And here it tells me that it was already installed without problem Let's check if it is installed Here it continues to install, it continues to install Let's wait for it to finish installing And I'm not going to use the famous me I don't install it because I already have it I install it with you because I don't I don't care about anything I come all or nothing You know, from the beginning of the course I said there he settled We close, we run this and we will see if it works Ok, the program is running, it works Let's check it out Print type p.d. Done, class module It is a module, it is a module that effectively works Why did we do all this, dalto? Why did you make me so rude? Well, now I'm going to explain Relax me because I'll slap you, do you understand? To begin with, to read a file we use the read function So here we are going to say the same file read In this case it is pd.read Here we have all the functions, you see? read.csv And here we put the name of the file In this case we use data.csv And don't forget that we use the file too So we're going to throw an exception Let's put files The bar, bar We update and there it is working We have already read the file Now we just show it print file We run and it shows us the information of csv Here we could work with chapiter notebook What is a way of working intelligently? official And more optimal data analysis I would say I suddenly put control shift p here And I put chapter notebook What is like a chapiter notebook Here I could come here and copy this, come? I copy it, copy it here and paste it If this that is here I run it Allow access And we give install You have to install chapter We can install it from anywhere But here it is installed automatically What I am going to have here is An optimal way to work with science of data And when we really work with science of data This is what we have to use and it is chapiter It's kind of working with an environment of different development And we use it a lot in data science, very much I'm not going to get too involved with this I'm not going to go deep either But they have to know that it is a good way to work In fact here if you look It tells me that the execution took 0.3 seconds And here it gives me the data In fact, if I get the print here And I only give you a file i run this And he throws me, he already throws it at me in format it throws me a format The first data is a self incrementing that does not depend on us It auto increments by more than we don't let's tell him and the rest of the data is First name, last name, age It automatically gives it its own format It is very important that when we work more forward With data analysis Know well how to handle jupitas In fact here I can continue creating columns Here I have more code Here for example I have a code I can change it, I can modify it I can drag it, I can change In other words, there are many things that can be done with this In fact, here I can see how long it takes For example, in importing pandas And on reading a file And then I can see how long it takes for example in read me the file So, now we are going to execute one by one One, three, ran on 0.1 This ran on 0.2 And now to show it I only know that it took 0.1 Now we are not going to give much ball to this Let's go, in the artificial intelligence course Or data analysis yes we will see But now let's close it And let's focus on this It is important that they understand That working with Jupyter is very important Jupyter Notebook is widely used like i told you so let's use it try to get familiar But for now we are going to use this In order not to turn around I don't want them to keep changing contexts Every time And that they have to constantly adapt What is there to do in technology? Actually in the world of technology you have to do like this But we're on a course Let's go calmer Well, here what I did was comment it Ok, what were we doing? I added two other data So that we can have more information about the to work And I would like us to see Some other extra things To begin with, we should redefine this And instead of putting a file We should put DF Why? because this actually It is not the file as such But it is the DataFrame The DataFrame, as I already mentioned Or I don't remember if I told you But hey, I'm going to repeat them again They are let's say data structures two-dimensional Similar to a spreadsheet We can, let's say, work and treat it the same Like it's a spreadsheet not exactly the same But conceptually for us to understand So by not behaving like a file It has its own way of accessing The values ​​that they will have are always two Rows columns In fact, if I tell you for example show me this Well, for starters it's the same It will show me the same information I'm going to ask you to show me for example now column name Let's see what it shows me when I update Well this way he gets me All data in column name In fact, I'm going to comment on it too Getting the data from column name Here I will put a name name is the same And here I get the data All right Now, what if I for example I would like to load the headers In a different way Instead of loading them by first name, last name and else I want to load them in another way what we do is When calling the file We assign the value Names, ok, the same And here we give you a list with For example, instead of being Name, surname and age we can tell you We can translate it into English Name, last name and age There it goes So if I update this and I show it print def What it is showing me is Well, here he is telling me that There is an error in name Because it is no longer called by name Now it's called name There it goes, we update is using us First name, last name and age Let's say Like the first rows And now Name, surname and age are part Ok, what they weren't a part of before Before, if they see each other Let's go up He showed us zero Lucas Now he shows us that Lucas Now it shows us that Lucas is the Now it shows us that Lucas is the first Why? Why did you add this to us? as if it was the header like the columns What make up the names of the columns Like what make up the column names This, the first row in this case Make reference to just the name we can do that with what is here But I'm going to delete it Just for your reference just so you know And if they want to do it they can do it In fact, let's Later When we plant some quick exercises To do with TXT and CSB Let's all do in CSB Actually in TXT only one What are you planning to do first? But we are going to solve it We are just starting to work there. Deeper, right? But let them know that it can be used Now we have to learn a new concept Called Slicing And although I could have explained it before I preferred to explain it now Because well, before I didn't want to put so much Although I already put everything in and only left myself That's because we wouldn't have seen it Slicing Until now The Slice Annotation Or Slicing in this case It's kind of a technique that Python has that allows us to do certain things When we work with some elements In the case of arrays It allows us to identify The beginning and the end In the way in which we are going to access the items For example Yes I have A list We are not going to create a list here. equal list or a chain a plain string String Same 1, 2, 3, 4, 5, 6, 7, 8, 9 from 1 to 9 There is 1, 2, 3 And let's say from 0 to 9 There it goes So if we call it by index More or less we have this Remember that if I for example I want to access some string value We are going to Do not comment on this anymore I put string 0 This would show me technically i hung with it There it goes If we show the code here it will tell us 0 Why? Why string 0 is equal to 0 String 1 It is equal to the second element 0, 1 So you have to return 1 Let's see if it returns 1 returns 1 All right We already know this We already saw it up to here We understand and it's very simple But What happens if I want, for example, to access From value 2 Up to value 4? Normally we would use it using methods specific And else Well there is a technique called Slicing what exactly is Using the two points It allows us to identify what will be the beginning And what will be the end If we leave it default This that is here we are going to run Everything That is to say We are calling all It's like just We will not specify anything Come? It's like it shows me the whole string Because we don't specify anything Now This side comes where it begins And on this side where it ends If we don't specify Start at the first element In the first element of the form to traverse it And ends in the final position That is, it starts in position 0 And ends in the final position That is, the minus 1 But if I here for example tell him to go from boot until 3 this is going to show me 0, 1, 2 Why? Why did it start here? and it ended here If I tell you for example until the 7th Started at 0 And it ended in 7 The 7 is not included Okay? If here, for example, I put 2 what are you doing here It's showing me From character 2 Up to character 6 And this is how slicing works Okay? start position if included end position not included That is to say If I wanted to have the position here 9 Not position 9 included But it's included there Because we are including the 9 When we refer to the 10 So say this It's exactly the same as saying this Okay? The same And also the same as saying this It just doesn't work Because if we want to access specific values We can do it Definitely Why am I explaining this to you now? Because the next thing we are going to use Handle this concept of slicing Okay? Since we are working with the library panda They have to know that one of the functions more common is the slicing and it is very common Now that we have seen the slicing Okay? We can just ignore it Pretend that you already understand If you want, go and add them If you want to keep it But if not, they will already be quite clear Now this since we learned it Let's see it later In some seconds In fact, a few minutes But now we are going to continue with the following which is how we can do If for example I want to order the data Suppose I have different ages, right? If I, for example, show what we had before The data frame What we have is 5 data with different ages If I wanted to order this the age from smallest to largest As I do? Here we order the data frame by age What we have to do for that is simply say That the data frame, ok, point sort values Okay And here we can use the by parameter I mean, why are we going to order it But in this case we are not going to give the by Because we are not going to put it as a parameter optional But as the main parameter and we are going to give We want to sort it by the age column So in this case let's give it age Because we are not ordering it by age but by age we update And well, it doesn't show me anything But if I suddenly now come and show the print defends What do you think you will have done? Will this have changed? Or just created an anonymous value? Well let's see it Didn't change it? Created an anonymous value So let's say sorted def In this case, sorted data frame So now we're going to display the sorted we update And now if you look Before there was age 97 first now is last Why? because now he ordered it In fact, if you look, they're messed up. indices 1, 0, 2, 3 this is messed up Why? Because the orderly now is this Even if we want to sort it in descending order We can use the second parameter Now let's say it Sorting it descending We paste the same code But we add the second value that now the second value It will be equal to ascending same false Because this second parameter By default it is configured So that in an ascending way Ordered, that is, from smallest to largest Even alphanumeric From A to Z But if we give it false It's reverse That is, it does not start from the smallest to the largest But it starts from the greater to the lesser And as for the numbers Won't start from A to Z But from Z to A And if we now show exactly the same we update And the sorted data frame Now it's sorted backwards the 97 above 24, which is the smallest age Bottom Here we are going to put it in order Descending order Ascending order So the information doesn't change Very good Here we have so far what we have been seeing we get the file we knew how to read it We got the data from the column name We sort them by age Then we sort them in descending order. even if we wanted Now, how could we do to concatenate them? Suppose I have two data frames We are going to read exactly the same One two And I give him df2 Let's read the same file But we are going to concatenate them How do we concatenate it? Well we use the concat function Here we come here and say Concatenating the two data frames Ok, here what we have to do to concatenate them That is, for example df concatenated Is equal to Remember that pd refers to This pandas module, ok? And here we put concat point What is a pd method and we say First date frame the original And then comma data frame 2 Here I put two lists, sorry just a list To put, that is The parameter that asks us is a list A list with all the ones we want to concatenate In this case we concatenate these two We run and there it more or less throws us The concatenated Come? And they concatenate us I mean, now it's just A data frame with all these files With all this data actually Then we have the head and tail function which just allows us First see the headers rows from top to bottom and then tail Which allows us to see the last rows from the bottom up If I say for example Accessing the first row with head I can say df or easier First row is equal to df.head First row I run to see What is it showing me? And he's going to show me Gonna show me all why head It asks us for a parameter that we pass him something If I here, for example, I pass 1 What is going to show me here It's row 1 Ok, what is this here? if i pass 0 It will only show me the header what is this here returns it to me in another way that has the columns Name, surname and age has no rows So it does not say that it is still a data frame But it's an empty data frame because it only has names of the columns Or the header but no information about it If we want to access the first row We give him in head 1 And there it shows us the first row We want to give it in head 2 And it shows us the first two rows not the second the first two rows And so we can display top rows for bottom So the first row We access with head And in fact here we are going to change it and we are going to put Accessing the first three rows with head And below we are going to put Accessing the last three rows with tail and let's try it In this case front rows And down here we are going to put last rows Same Df.tail And here we are going to give it a 3 same thing, a 3 And here we are going to tell you Show me the last rows Let's see what it shows us Shows us the last three rows from bottom to top Remember that here we have the complete list with all the names this one here And the last three are Machine, Nicolas and Camila Well If we come down from everything I show us that Machine, Nicolas and Camila The 4, the 3 and the 2 What are rows 5, 4, 3 then with head We access the rows from top to bottom and with tail We access the rows from the bottom up Then if we mean Hey, the truth is I have files that are passing me Okay? I have files that pass me And I want to do different calculations Depending on the number of rows And the number of columns that pass me I want to know how many columns and how many rows there Because depending on this amount I'm going to do one thing or another For example If there are three columns I make three columns If there are ten columns I show ten columns That way I can create for example If I mix it with web pages I want to create an element Which depends on the number of columns you have I believe the number of elements Or the number of rows Or whatever Well, how do we access the columns and the rows? Easy Accessing the number of rows and columns shaped shape is a property That is, it is an attribute It's like a variable of the object For that we simply say that Total rows and columns Is equal to df.shape If we now show here Total rows and columns This what will return us is five and three The first thing that returns us is the amount of rows And the second thing is the number of columns y is a tuple A tuple with two values It's very simple So if I want to get the tuples I just say total rows Is equal to df.shape total rows equals Total rows and columns Zero And if I want to access the total columns Is equal to Total rows and columns One And now I can access the values Or I can do what we were learning To unpack it and just say total rows Eat total columns same df.shape And that way we unpack So if we now show total rows It will show me the rows what are five And if I display the total columns I can access the columns that are Three Very good, so far we come from ten Then we have more complex functions That these are already more for the analysis of data As for example describes That allows us to obtain statistical numbers For example Getting Data Statistics From the data frame If I now, for example, give him df.info Same df.describe If I now show myself the information Let's see what throws us df.info Let's see what he throws at us Here we basically have the amount of of rows we have the average We have the standard division we have the minimum we have the quartiles and we have the maximum So these are statistical information That in the analysis of data they serve us And we'll see what they are When we just do a course of this Do not hurry because this is already more mathematical And when we see it with artificial intelligence It will close them much more But for now relax us But nothing, if it helps to obtain this information we can get it here Okay Why did I tell you that we were going to have just What to learn slicing? Well, about the slicing we are going to work now Because we are going to work with two methods very interesting they are lock and lock Lets put Accessing a specific element From the data frame with lock If I now, for example, tell him specific item Lock It is equal to data frame point lock It's not a method, it's another property actually So, the first thing it asks us is the index In this case it is the way in which we are going to call up the ranks The rows, if you remember Come, the rows have names The way we refer to the rows is with numbers with an index One two three four You are automatically assigned In this case we refer to the rows by index If I say for example I am going to access the element that is in the row Two Not at zero, not at one Two And I want to access the age I'm going to put age So here it will throw me the data of the element specific if i put Item specific lock Here it returns me twenty-four And if we go to the data It's true These are the columns of the names we ignore it This is row zero This is row one This is row two This is the name This is the last name this is the age So we are specifically accessing to this item So we access with lock Now we are going to access with iloc With iloc we access only by indices In fact, the i in front is from index If we count as if it were an index This would be zero, one, two To access the age values We have to access by the value two So we say two, two And in this way we access the same value Accessing the age of row two Now we are going to say exactly the same Now we do it with iloc there we have the same Now, if for example I want to select all rows in a column How can I do? Well I'm going to say for example Accessing all rows in a column In this case I want columns only show me one But rows I want to show me several So I'm going to say all or last names I'm going to put iloc iloc lastname will be equal to df.lock Two points Because remember that this asks us for positions Here the position that we are going to pass is X is going to access everything And it will access only the first element what are surnames It's first name, last name zero is name One is last names So here we are saying Access me to all the elements With the slicing we ask you to access me all And with one we say now access me only to the surnames So now I show this Sorry, this is with iloc we update And now it shows me You are accessing all the last names Come? DALTO DEMENTIAL, DALTO SUSTAIN GALACTIC There he accessed all the surnames In this case we will say We are going to invert them because we are using first place and then iloc So we are in order So in this way we can access just to all data in a row And the same with the columns. If we want to access for example Accessing row 3 with loc Is the same we put row 3 same df.lock And this we simply say row 3 What is in the 2 It's 0, 1, 2 3 is 2 Eat Two points I want you to return all the data of row 2 I now show row 3 When I run it it shows me row 3 All data the name is camilla the last name is dalto gives you 24 and that's it And if I want to access it with iloc what to do Let's see if they get an idea Exactly, in this case it works the same Why does it work the same? Because in this case the row As we call it by index And the row in this case works by indexes it will work too They will see that I am going to overwrite it update and it works too It's exactly the same In the same way no problem doing it In the same way And here I can use a condition For example I want to access rows Let's see Where the age is greater at 30 then i will say accessing rows Older than 30 then i will say Che look Greater than 30 is equal to df.log The same The rows What do we select? Something Let's put a comma And what do we select here? Everything then columns all rows Well let's go now with the rows The rows will be only the df Age one Let's access the column one Age one and we will only say one while this one Be older than 30 one Thus one if we update one Here we have to say that it is one Greater than 30 one we update one And it will give us back one Only rows greater than 30 one Come one 97 one 42 one 39 one And now I tell him one Return only the ones that are one under 30 one they are going to give me back one Those who are minor one So this way one we do things one Why? one Because the first piece of information that you ask us for one It's the rows one And the second the columns one Columns we ask all one rows one Only one Those who are older than 30 one Ok now that we have seen one More or less how to manipulate one and work with files one Let's consider one a couple of exercises one Okay one Before proceeding with the following one Let's say one Che look one Suppose we are one building an app one and we need to work one with txt one And with CSV one What are the problems one What can they tell us? one This is not a practical exercise one don't confuse it one It is not a practical exercise one but it is something similar one because we are going to raise one Problems one But many more problems one but that are resolved one Too much faster one shorter problems one So let's go fast one With the section of one solving problems one in which we are going to solve one Some TXT and CSV issues one so quick one Go well let's create to start a folder to wrap these files solving problems to avoid problems we are going to put the script low I'm going to drag her out because not the I want inside files but I want it just outside solving problems or more easy there I renamed files problems resolved well now let's create a new file that goes to be problems.txt.py well the problem that exists is the following is something very fast We have two lists with name and surname, that is, a has a first name another has a last name we have to to write the data in a text file optimal with a good easy for we are going to put two lists one with first names another with last names well let's go to create them names equal to putting lucas matías Camila Pedro and Roberto Roberto cannot be missing and surnames dalto sing camila also dalto Peter rubetix and roberto tarado and now simply let's show them record this information in a txt optimally well we do this with a for as we already said we are going to create the text in In this case we are going to give it with open the text created will be names and surnames.txt and we are going to just write it down and first let's say before we are going to assign a value in this case going to be file arch file.write lines and we are going to write the data are colons and now we are going to write the data we are going to use the slash n no need this is a line like this what are we going to leave it like this not if we have to use the bar n the data is bar n since we use a for but in In this case we are going to do it optimally Do they remember what we have to do is tell them Look, let's see, let's do a for in one single line arch.write lines f name two points since we use the name in this case it will be ny We are going to put the bar down and we are going to put last name two points we open and we are going to put ay lo same we are going to put after slash ny dashes To leave a space like downwards what will it be worth ny what's going to worth to good basically let's go to say that for n,a ok these two variables are going to be equal to the values ​​of zip first and last names ok in the return of the loop in this case it is in for in and there it is technically if we execute this let's see what happens we run as python file also something happened good we'll see we entered the file no file was created obviously so something went wrong a no I know created here name is surname.txt was created It looks beautiful on the outside, we access it and here we are says the data son first name colon lucas last name colon d'alto name matías last name without name Camila surname d'alto here we have an error and it is that this doesn't leave an inline space afterwards so we have to leave space online too there it goes well we run it back and now Yeah we should have the file ok there it is in fact, we are going to leave two spaces for the first one in line we run back and it's here is our file created with the data the data is first name lucas last name d'alto first name matías last name without name camila last name d'alto Y else how does this work easy this is as if we throw down here ok I'll put them so for na in zip first names last names colon and here let's say the same ok the same the same the same here this We paste it here just as they are seeing works exactly the same only that to do single line for instead of do it like this we have to say che mira no going to have the two points this will be before ok and let's go to put it inside an array and in this way it What we do is create an array with the value in each turn of the loop ok it's as if here basically we were performing this action in fact I'm going to delete this in fact if I take them to take out this for you to take into account this that It is important if they take it out in they take it out of here and me I update when I want to run the code this tells me that it does not work because programs not create no array and do not create anything associated nothing is important that they understand that the form to run it on a single line is within a nothing we are putting inside a list so we could do it that way so it's important to keep it and inside but it is is the form of simplify it instead of putting this inside of the for is basically a form like I said of simplify it we had already seen it the same should be just a good review now what already we solved this problem of tequiste let's go to solve ok let's put it here inside come on to make the copy path and we are going to put it here everything used the double bar so there It's in In this case, the route that interests me is this that it is almost that we put the double bar and ready files problems solved let's see if I create it and inside I'm going to delete it delete delete it I run and there it is, I believe it in here but it tells me the data is two points because I do not know that moment I put this as a tuple so I'm going to change I don't know at what moment it became me a tuple I update and if I open the file now everything is fine perfect we are already the same but inside so we don't get lost and now let's go to create another file that will be problems csv.py not problem problems cause let's pretend small problems but quick to solve it First is to change the data type of a column suppose I suddenly have this doesn't matter pandas as pd we are going to create the data frame data frame the same as pd.read.csv and here we open it the file csv is the same as we have here in files We are going to copy and paste it here we are going to close the tequist and close this thing about pandas and we only have all those open files let's paste this and put the name of the file that in this case is data.csv to see that everything is ok we give printf and see what it throws us ok well it throws us the data well the slogan in this case is change the data type of a column change the data type a column well let's do very fast and very simple of f in this case we go to say for example the age column is going to be same a let's change the value this has a value We are going to change them, it will be equal to df age also but we are going to use the as type str to convert it into a string we are going to verify it if I for example now I say print df age let's go Let's see what it shows us, it tells me 97 42 24 27 39 if I here give 0 to element 0 we go Let's see what it gives us back 97 but let's see what type of data this is we are going to put type to close it in type a see what we returns and this tells us it's a string ok if I didn't put this here it would be equal to numpy int is say is a numpy integer but they can stay with what is some kind of number ok then of this way we convert to string convert to string the data of a column and of this form convert all the data and here we say show display the data type of the first element of the age column is exactly that later we can replace values ​​if I for example want replace the value or say for example that df names or name would be pardon name point replace replace where it says dalto replace it by teacher and if I don't show it print df Name Let's see what shows us updated in In this case we are going to replace the last name sorry surname not the name but the last name that tells me dalto dalto dalto why is this because we a last attribute was missing which is in place in this case it is true ok for us to finish to close the in general and there notice that he replaces me dalto by teacher whenever high appears it replaces me by teacher come here dalto appeared now Master appears I am going to replace the dalto data by teacher showing last name column in this case we are going to uncomment it even why It is not necessary and we are going to discuss this because if it is necessary since we are not interested more show it now we have another problem the data the data suddenly they have rows with columns that would be missing as for example this one has the 39 which is missing and another comma has two data that they are missing and one that is left over is more let's go to leave it like this I'm going to delete this too well how do we remove these rows with data that is missing easy we say def same def drop na point and here we are eliminating what which has been the ok rows with missing data Yeah before this I show print def I act and then show it back print def well now when update look at what is showing me here I'm missing two pieces of information, Stange Nan tells me nan and He directly deletes them that tells me not skinny The fifth is already here, I won't show it to you because you I deleted deleted so we just said eliminating the repeated rows suppose that now we duplicate a row we have this row exactly repeated repeats as well as the come repeats itself as we do one thing right before is that I wanted to tell you that if you wanted remove columns with missing data what they should do is tell it axis 1 and there I know would remove the columns because the parameter 0 are the rows 1 are the columns by flaw and so if we want the columns we eliminate it like this but it's weird to remove columns only because data is missing but well it doesn't matter let them know that they can do it then to delete the repeated rows in this case delete here the ones with the rows with missing data I I confused missing ones above we eliminated the rows with missing data and now we remove the rows repeated let def is going to be equal to def point drop duplicates and now we delete the rows repeated so now we are equalizing the data frame to the new data frame with the rows duplicates removed if i don't show it print def let's see that on the one hand no has neither on the one hand the rows with missing data nor does it have the repeated rows that was repeated that they were a galactic machine he eliminated well here basically if they occur account what we did was create a program that makes us a lot of things that replace us values age by strings instead of integers that they replace the data frame with the last name where I know find high and make us a teacher that we delete the rows with missing data and that we remove the repeated rows we now have a clean data frame we have another problem we want cause the old file to be saved because we don't know how to write data in csv yet well let's create a new one by creating with the data frame clean result in this case is the data clean frame def point to csv let's convert the data frame in a csv file and we put the name in this case we are going to pass this value and we're going to tell you data and a clean bass So we have data that is clean we update I just created the clean data file we enter and there we actually have the program with the data frame that we have created we have the the same as here but now we have it clean let's say even if you wanted to call him you could call it and operate with it back this section basically create it very quickly so that we can solve some problems or that can arise as for example that we have to change the type of data from an entire column or that we have to replace all a value or that we have what to remove the rows with missing data or the rows repeated problems can arise and from this way like that we are solving them this is basically It's not that much of a problem but how do you I said before and I challenged them, I told them to see, you do it ok but do it optimally well here there is another exercise similar to the previous one in which basically do what I told you that I know how to write a lot lines optimally the difference that here we do it with two lists together but goes runs and goes out of 10 now we are going to raise other problems we are going to raise graphic problems ok here it we are going to change we are going to give him rename instead once solved we are going to put simple ok problems Y Here we are going to change the resolved one if you ask them We are also going to solve problems problems and here the same problems because i did this i did it because now i would like us to solve problems graphics like this What I'm going to do now is create another folder more than that will cause files problems graphics and in this folder we will create the files of what we are going to have now because now we are going to bring graphic problems that is to say let's pose various problems and solve them but at level graphic i.e. work no more with console but with graphic things if we go to use the console to solve the problems but nothing I want you to see a little of what we can offer some python graphics libraries so let's learn as we go let's solve these problems Well, the first thing we are going to do is create a file that will be linechart.py Because we are obviously going to work with a line graph Let's pose a problem We understand that farting is an indicator stomach problems So basically I create a detector of farts and every time i fart, this is recorded So after a while, ok I have a CSV file with two columns The first column is the dates and the other with the number of farts that I shot on that date Well here I have a new CSV file that says farts.csv and basically says date farts 013 01025 01034 I mean, here we have the amount of farts that I threw myself that day and next to it we have the date Ok, so there are two data What is that we want to do? Basically, we want to find the days in which I had stomach problems First we import pandas import pandas as pd Then we import a library that I showed when we were working with modules that I told them that we were going to use it, which is matplotlib But we are going to access pyplot promptly and let's name it plot lt This is a display library of data, basically to visualize data graphically And then we are going to import cia-borne as sns This other library is a graphics library statisticians It allows us to give more statistical graphs And if we run, it will tell me that matplotlib I do not have it installed So we are going to install it We are going to copy this and we are going to come to cmd And say what we already know we say py-m pip install matplotlib We press enter and it is installed There it is, it's installing, great Done, installed And now we are going to install cia-borne The same py-m pip install cia-borne There it goes cia-borne installed correctly Well let's check it out If we now run this program Ok, it does not throw us any error then it works Well, the first thing we have to read now is the file So let's read it DataFrame is going to be equal to P.S read.csv files problems graphics bar bar p2.csv Let's see if he reads it If it reads it we will give it printf If you read it, everything is fine. Perfect Everything is alright Reads Here I will say below sns We are now going to access to work with this object And we are going to give it a point lineplot And let's create a line chart This tells us What are you going to have in x? Well, in x we ​​are going to put a date And what are you going to have? Well, in and we are going to put p2 And what is the information? Well, information is information of DataFrame the value of x That is, in the Cartesian graph x will be the date find me column dates That column is going to be x And then find me the column p2 And that column is going to be and Where do I have to look for those columns? In DataFrame So we say date Equal DataFrame There it goes And now we have to show it We have to tell him plt.show Because with show we show the graph Ready we run this And now the graph opens Ok, It's right we have the graph Well, obviously we can already see if it we enlarge The dates, right? And evidently between the 8th of the 1st and the 11th of the one This person has screwed up like never before in their life He has obviously farted 17 times But what I want to do now is mark that point I want to mark 17 with a point Ok, in this case, as we know We could do this dynamically. Detecting what is the maximum point But in this case we are not going to look for it so much And just as we know it's 17 And the date is 0109 Let's create a plt.plot below And we are going to tell it that the first value has what to be 0107 Sorry, 09 And the second has to be 17 And then we are going to give you an ova to tell you make a dot There we run the program and there it shows me the dot up there They see him? I have the marked point To identify that the highest point was That's it, we did it Creating a point at the moment of more farts creating the chart And here showing the graph So we already have the first exercise solved Well, the second problem tells us the following Cofla has already been received and is working programmer All right For those who don't know, Cofla is our meme From the javascript course if you don't see it see him In which he is a character who has various problems And we with what we learn in programming during the course Let's solve it in code So the dynamic is good It's in the javascript course If you come from there, spectacular But well, ultimately Cofla graduated and now has his first I work as a programmer But in addition to being a programmer, he has other sources from income Because as it appeared in the javascript course That left him royalties He became an influencer Advertise and earn well as an influencer and else Also invest in crypto And he does other things that serve him and generate income So we have this CSV called Coflaingresos.csv And the first value is source and the second income A source of income is permanent work And it gives you 3000 dollars per month Fairly good Then he is freelance in his free time And it generates you 800 dollars per month cool The course you use generates YouTube royalties I did And basically it generates him 350 dollars every month So go for it And then as an influencer doing advertising and else Earn $600 per month And also invest in crypto You have an investment in a common fund there investment Which has a fairly high compound interest And it gives you 150 dollars per month jodj What we have to do is show these sources of income in a graph Which graph is apt to show data from different places? the bar chart For this situation it comes from 10 So let's copy this And let's save it as bar chart.py The difference is that instead of putting lineplot Let's put barplot Bar graphic And instead of putting a date and farting The data we have here are source and income So we just put source and here we go to put income There is And the data is this that is here So here we say creating the graph The point here does not need to be believed Why don't these have points? It would be strange to create a point here Basically we create the bar graph With the data and we show it So we run this and it tells us that I don't know can interpret source input Why? Because we are importing p2.csv and we have what to import kofla Income.csv Now yes We run the program back and we should be open chart There is Beautiful, look at the kofla source of income He has a steady job, $3,000 Freelance, 800 YouTube, royalties, influences Now we want to know by the way how much he earns total We also want you to tell us how much is the total of everything Well, let's show it in a print Let's say that total income is equal to def income.zoom This is a method that what it does is Adds all the input value data Or that you have a numerical value Or that there we add all the numbers so let's do Let's say showing the graph And down we go here above everything Let's say showing the total Obtaining the total income And here below we say showing the total Print f Total revenue is two points And here we say total income Here we are going to give you the dollar sign of currency actually Here we are going to put USD So now we run this And when we run it On the one hand, the graph opens And here in console it tells us Total revenue is $4,900 Well, kofla, a big one Well, we already have this exercise resolved 10 So let's go with the third Well, here we have the third problem And it's simple, it's not that troublesome we just have data Ok, data that are points, are coordinates Coordinates on a Cartesian graph We have time and we have money Let's get a file Let it be called a scatter plot .py, sorry, here it goes let's grab the code And we are going to show the same code There it goes We are going to remove this Because we don't need total income We are going to remove this too. And simply here we are going to say cater plot There it goes This is a scatter plot What is this chart for? Ok let's show it first and put scatter And it's time and money Time and money Let's pretend let's run this This and I will explain it Here we open this graph Ok this is a very used chart by artificial intelligence Especially for early algorithms What are linear regression And plenomic regression and so on. And basically it serves us to trace Different types of lines And be able to predict and so on In fact, in many cases It also helps us to classify But basically here we have several points Arranged in coordinates And it helps us to find Relations between two variables It can be two or it can be more And here what we can do is Just draw lines, draw stockings And many other things But they know that if they want to work A scatter plot For those who know them And they even have SBCOM data Many points This is the way Use a scatterplot What exactly is a scatter plot? Ok, to begin with, what is programming? object oriented? Object-oriented programming is a more way to program but concepts appear, which come from there all the other concepts we have in Object-oriented programming, which are class and object, which are the bases on which we can later build and design any software we feel like. Each object is an instance of a class. A class, in other words, is like a kind of template that we have, that we created us, that defines the properties and behaviors of the objects that are created from those same classes. We say that humans are going to be white, black, chinese and so on. We say that humans are going to be round, They are going to be of a certain level of intelligence. All of that is defined by the class, like the formula to be human. And then each human has their own things. We have our own hairs, our own eyes, our own size, height and so on. But more or less we all follow a rule, we are all human, we come from the human class. What is this for? Ok this is for organize structure and organization of our code. Which makes it much easier to scale the code, i.e. extend it optimally and also be able to maintain it. It also allows us, for example, to reuse code, because if we constantly create objects of the same class, We don't have to go around defining its properties nor its methods, because it is already more or less all set in class. That is, if I want to cook a soup, I notice that is creating the recipe every time it is I am going to cook. I create the recipe once and then simply mix the ingredients, I give them the ingredients and it does itself. I just cook it. It also allows us the code, for example, be safer, since we can encapsulate it and has properties and methods that only can be accessed with specific methods. And basically many languages ​​are used programming, including Python, to create, let's say, programs much more complex but also flexible. Since you can create objects that interact with each other in an organized way. Ultimately, oriented programming to objects is a programming style that focuses on developing software based on classes and objects. Allows for greater security and encapsulation Of code, It also allows you to reuse it and is one of the most widely used paradigms around the world. And in fact, being such an important methodology, I'm going to show you. If you want to learn it and want to work with Object-oriented programming, I recommend that you do the course that I already I did and you can see in the description. You go to the description of this video, look for OOP course, which means programming object Oriented, and there you enter the course. It is a course that I also did and it is in the channel. If you don't see this course, forget it, don't worry. It's not like it's the end of the world if you don't see object-oriented programming course but believe me it will help you a lot with logic, it will help you a lot with other programs and it is something that sooner or later, if they want Being expert programmers, they have to know. I did not include it in this course because it would lasted much longer and it is not the idea to have a course that does not enter us. Remember that YouTube videos only can last 12 hours, and with that course surely we would have surpassed. It's also good because I'm going to be able to expand, I will be able to do exercises and I am not going to summarize oriented programming objects like that very fast, very fast, very simple. We are going to give examples, we are going to practice and many other things. Pause, stop and go see that course. Ok, if you already saw it, you can continue. And if not, you can also continue, but particularly My recommendation is watch it. Ok, don't lose anything, it's good and you learn something new that will help you a lot because it is used a lot and when we work particularly with, for example, web development and so on, yes we have to use it. So learn it, learn it 'cause Besides, once they learn it, it changes completely view of everything. Believe me it changes them, it's like automatically they start to think about programming things as if they already do it for programming oriented to objects. So nothing, I see you in the course, good luck. Alright guys, we're about to finish this section before starting the section advanced and I want to say goodbye properly because what we are going to see in the advanced section Already it starts out spicy. It's not like what we're going to see next It's a very advanced topic. but when you see it in depth and when you make it more complex and as an element apart from nothing new from what we've been seeing yes it can be, let's say, taken as such as an advanced item. And more in fact when we are working with object-oriented programming because what we are going to see next no need for object oriented programming but if we mix it with oriented programming to objects we can do many more things. That is, all the concepts from now on more, if we mix them with POP they will be the most better. But let's go once and for all with the section advanced. I'm going to say goodbye very epically. wait for me that I brought rockets and bombs to explode everything. Here I have it guys. Welcome. I'm going to show you and I'm going to present to... Snap Boom. I know that this is very epic and I know that you did not expect this for the course, but damn, he deserves it. We are entering the fucking advanced section from the Python course. So let's go fuck. I see them in the advanced section of the course from Python. Come on fuck. And the effects, master? And the effects? Can we change publisher? Oh, okay. Good forgiveness. I'm going to do it now all right. Let's throw two greens because the greens are signs of... You are doing things right. So now yes, I fire you and see you in the advanced course of Python See you! I want to welcome you to this section Advanced Python course. That is, we are entering a different world. We get more tryhard so this section, like this with these colors, this wardrobe. And in fact I'm more broken than ever, I let my beard grow. Because we're really at a point where that we don't care about anything but the code. We arrive at this singularity of not knowing what is what will happen to us. But I don't care at all, I'm in a stage What am I going to focus on in the section? what we have to do now And we are talking about exceptions. The issue is that to understand what the exceptions are, first we should understand what an event is. Ok, an event is basically anything what happens in our program. This normally sends us a notification in order to act accordingly. That is, click, move the mouse, type any letter, release any key. Anything you can imagine anywhere event within a program is an event. Some languages ​​support more events What others. That is, for example in some language I I can press a button and that is already an event whole. And in other languages, for example, we have the event of pressing a button, another of holding it tight, another to loosen it. And several other things, the same with the mouse. We have mouse events, keyboard events, events of a lot of things that are imagined. Every occurrence is an event. In programming languages ​​what we do is to capture these events, these occurrences, these things that happen to act accordingly. For example, if I type something, the program detects that the user typed. So what do you do accordingly? It shows me what the user typed. For example, the function input, in which We work with data provided by the user. When the user types, the program detects it and automatically displays that digit that the user entered, right? So, for that me and the events, for understand that something happened and act accordingly. In Javascript we saw it quite a bit when we looked at goodbyes on Instagram, for example. What were events that we said if the user if you click on this button we do such a thing, and well with a lot of things. Elections, on the one hand, are also events. Events that occur during execution of our program. But what this event does is interrupt the normal flow of execution. I mean, it's something that makes it stop all action in the program. If we have 10 instructions and the instruction 5 throws an exception, the others don't go away to run because the program ended there. The goal of learning to work with exceptions, basically, it is knowing how to act accordingly of these same That is, if we have an exception, know handle it so that the program does not end and we can do something about it. Let's see an example. Well, here I am going to create a new folder which is going to be exceptions. Well, here we have the folder and I'm going to create a new file inside this folder. exceptions.py And to understand well what we are going with this, I want us to purposely force an exception. That is, let's make the program launch us an exception. To begin with, let's create the sum function. And basically, this function what is going to do is ask us for a number. Then what we are going to do is obtain a result. result is equal to a plus b. And then we return the result. So far everything is fine. If I, for example, tell you to add 2 and this function run when run. That is, number 1 I am going to pass it and 40, number 2 20. Up to here all good. Nothing happens, everything is fine, it does not launch us exceptions. In fact, if we give print add 2, this it should show us what is returning. So let's do the same test. 40 20 and gives us 40 of int. Why does this happen? And why don't we convert it to integer. Let's convert it whole. int a plus int b. Here we are making it whole. Perfect. So number 1 40, number 2 20, we have
  5. This works perfectly. Ok, so far everything is fine. Now let's run the program again. But now we are going to tell you that the first number will be equal to Hello teacher, haha. And the second is going to be a number, for example,
  6. What just happened here is that we are finished to throw an exception. Because it is telling us that it is a literal invalid for an integer. Why? Because what you are asking of us here is a base 10 number. The base 10 number is the system we know. 1, 2, 3, 4, 5, from 0 to 9, let's say. That's a base 10 system. A decimal system. And we are passing it on . Hello teacher, haha. This is not within the base numbers

11600 07:11:49,130 ​​--> 07:11:51,270 That is, it is not a common number. So it threw me an exception. So far everything is fine. The exception type is value error. Now, how can we go about telling him to the program. Che, look, the truth is that I understand that you threw me an exception. I understand that we can't use int to convert to integer. Something that is not a number. So please let me do something in consequence. How can we do that? Well, for starters we have to use the try statement. It is a sentence that says, che, look, what it's down try it. If you know that he may be going to throw you one exception. Try it, okay? There is. We basically tell you that. Che, if you know that a possible exception. Let's try to do the same. The other thing that we have to pass is the except. Because exception handling takes two parts. One part is trying to do the following. In case we throw an exception. Let's do the following. Let's tell him print, please don't stop. And now it will show us the result. So, let's say, add 2, we execute. We run program number 1. We are going to say, hello, number 2, paint. And now if you look closely, he tells me that it can't be done access the local variable result. Because it has no associated value. But this exception is not being thrown anymore more. What we should do last is until we don't have the result value. We are not going to return it. How do we do that? Well basically the correct way to handle it is we can put it in a loop. Tell him, look, let's do something. This, while true. This will always run. It's not going to end, okay? This will not have an end. All this we put inside a block. What's more, now we are going to tell you that the exception it will show us something else. We are going to say che, look, let's see. If you throw an exception it is because you are so silly that you did not put a number and put a text. So let's tell him, I asked you for a number Salame, don't be funny. So if this is executed, for example, there we say, number 40, number 2, 20. Perfect, there is a number, nothing happens. It's all good, it works. And indeed this runs me an infinite loop that doesn't end anymore. Because this worked, but the loop didn't get me will never come out So we have to tell him che, look, to see, if this can be executed, it won't throw an exception. So we give it a break and with this break it goes to say che, look, if the result worked, then we end the loop. We run back, we stop the program to that does not break us all. We run the program again and now I says number 2, hello. Number 2 and 30. I asked you for a number, salami, don't play the role funny. What is happening here is executing me over and over and over and over and over and over again this, this here. What is happening here is that actually the numbers we are not asking for back. We should ask for the numbers back, so we're going to put it in here. There it is, so we put this here inside, there it is. And what we do here is tell him che, look, Let's see, I'm going to ask you for number A, number B. Let's try to add them and convert them integers, sorry, convert them integers and then add them. And if this throws an exception, we tell it I asked you for a number, salami, don't play the funny. And the loop works again. In case it doesn't throw us an exception, then this continues and tells us break. So if we now run and update, number 1 is hello, number 2 is 20, for example. I asked you for a number, salami, don't play the role funny. So now I spend 40 and below I pass hello. I asked you for a number, salami, don't play the role funny, now I text and text. The same, now we are going to pass numbers really. 40 and 40. And now it tells me 80, perfect. There it goes, I jump in and we manage to handle the exception. If something happens to us that is not a number, basically We're going to tell you I asked you for a salame number, don't be funny. Now, this break here is not the best out there way of acting, but what we should maybe use is an else. It's like, let's see, else break. So after we know that this It didn't throw any exceptions at us, here we throw the break. Why? Because you can use an else. Just as we use an else in the for, we use an else on the try. If the except is executed, the except is not executed. else. If the else is executed, the except is not executed. Now, the except will only be executed when try throws an exception. In other words, if try does not throw an exception, this runs. What does it mean? what if this worked correctly and he did not throw us errors because the moron did not you entered data other than a number. Then it ends correctly, we exit the block, the loop and return to the result. It looks complicated, but it is quite simple. In fact, if we discuss it, surely it they will understand better. Creating function that adds numbers, starting a loop, asking for numbers, trying to convert them to integer and add them. If it threw an exception, ask it to reenter the data. If everything went well, we end the loop. This is easy, you don't even need to comment on it, but we're going to do it anyway. Showing the result. And then we have an extra clause. Suppose we give it return result. Here what we could do is use a finally. And what the finally is going to do is a statement that runs no matter what. That is, if we throw an exception, it will executes the except and the finally. If it doesn't throw an exception, it doesn't run the except, if the else, but also the end. I mean, no matter what happens to these three, the ending will always run. It's like saying, let's see, I don't care if you Are you going to throw me an exception or not? to throw an exception. But the end you show me the same. So here we are going to put in the finally print, this is always executed. If we now run the code back, number one is hello, number two is 234. Come, I asked you for a number, salami, don't be that funny. This is always executed. If we now pass a number to it, 20 and 20, this always runs. It will always run. Here we can put, for example, management of exception ended. So we know that everything that comes after it is not inside this exception handling. Number one is hello, number two is 20, drive exception ended. We put 30, we put 20 and now it tells me I drive exception ended. And after that it shows us the 50. The final and rare is sometimes useful. That is, it is a rather strange sentence to find a useful use case. But occasionally they exist, so I they will find when they have to use it. It is not very well seen in programming to use exception handling. I mean, it's not the best they can do, but sometimes it is quite useful. Speaking of utility, we can actually even Access exceptions. That is, if I say here, for example, except, exception. This is basically an object of the class exception. The exception class is the class as parent of all exceptions. Why? Because all exceptions are derived from the exception class. Or they are derived from a subclass of exception. That is, they are exception objects or a subclass of exception. So if I can show this here even. Here I can tell you that exception will be renamed how do you do It is the unusual name that we give to the exceptions. E. Don't be funny. And below we will show the error. Wrong, two points. Here we put F. And here we say E. Error, two points, E. We run the program and we are going to make it we are faced with an exception. And here it says error, invalid literal for int, with base 10, hello. That is, the exception was thrown by this value. When we try to use this value in the int function, this value was thrown. If we wanted to know the name, what is it? the name of the exception. We can tell it type, E, me on bass, me on under. Name, me on bass, me on bass. And in this way we have the name. If we run the program back. Here's a point, sorry, period. There you go, we run through the program again. Number one equals gola, number two is equal to 20. There it says error, value error. Now we know that the name of the error is that. So even if we wanted to, we can give it here in value error. And now when we show the exception. Let's show E, for example. We make the code run again. Hello, O. And here he tells us the same thing. Only now we understand that the exception that is launching is this. Several exceptions can be used. That is, if I know that in addition to the number that I pass is a number that is divided by zero. For example, here it says number one. And here it will say, for example, 10 divided zero. Here he is going to tell me that it is a literal invalid for int. Because it says 10 divided by zero. And this is an integer. But suppose we do some operation which divides us by zero. And that cannot be. Does not exist, cannot be divided by zero. Well, there is a name of an exception that is named. For example, zero division error. It is another name of another exception. And here we are going to act. And we tell it, if the exception is zero division error. Don't divide by zero. So knowing what the exception is that throws us We know the reasons why he launched it. And we can act accordingly. Several exceptions can be used. And there we end. Then we can access the exception of this form. It's interesting. Here we are going to put, this is always executed. So that they more or less understand that it is executed forever. Finally is always executed. Let's create another file now. What's it gonna be. MyException.py. And we're going to create our own exception. How do we create an exception? Good. Let's create a class. Class MyException. This as you already know is to create a class. If they saw the programming course oriented to objects. They will know that we are creating a class. Which is called MyException. The classes are normally created with CamelCase. But in addition to using CamelCase. The first letter is capitalized. So it's not real CamelCase. But it's like all the first letters with capital letter. CamelCase would be like this. But it is correct and it is recommended to use for classes. Capital letters. And this is going to inherit the exception class. You are inheriting the class. That is, all properties, values, and attributes. Of the class for the exception. We are going to inherit it. So we can make it an exception real. If they saw the programming course oriented to objects. They will know what it is to inherit. Here we give you two points. And we start to create the class. Let's go with the builder. DefInit. Okay. We give it the parameter self. That self, as you already know, we have to give it to you. Always no matter what the class. Here it is not working for me because I gave it capital class. What a fool I am. Lowercase classes. Self. And here we are going to say error. This is going to be our mistake. And we're going to create this constructor method. Let's tell it print. Error is error. No, we'd better give him an impression. You made the following mistake. Two points. And there we will pass the error. And here it is. We already have a class. Which literally creates our own exception. Let's try it. Since we have not yet defined where it should be launch. We are going to launch it on purpose. Let's give it a try. Okay. Try. Two points. Rise. Rise is the keyword for throwing exceptions. If we wanted, for example, to launch The exeption. Value error. Okay. And here we will say except. What's more, you can't even use a try. If we used the word rise here. Value error. Only here. For the simple fact of putting the rise here we He says an exception has occurred. Value error. If we now say zero division error. And here we give you a description. For example. What a jerk You divided by zero. We run this. We update and it tells me. Exception occurred. Zero division error. And here it says What a jerk You divided by zero. This way we throw exceptions. So what we are going to do now is launch an exception. Let's say. Try. Two points. And we're going to launch it on our own. Rise. My exception. And we're going to tell him. Ha ha ha ha ha ha. taradito. Nerd. It is very aggressive. LOL. little hidden person And below we will say. Except. Let's handle the exception. And we're going to tell him. How are you going to make that mistake? We run and he tells us. Awesome. You made the following mistake. Hahaha. little hidden person This is the way to create exceptions and throw them. So here we are going to put. Comments. Throwing my own exception. Here we are going to put Managing it. And up here we are going to put. Creating my own custom exception. So now if we run this program. What is here throws me the exception. In fact we are going to discuss it. So it doesn't throw the exception. And everything else can be executed correctly. There we have basically. Our own exception. And how is this file outside. We are going to put it inside exceptions. I don't know why I put them outside. I thought I had put it inside. There we are. Ultimately the exceptions. Although they are useful. And even if they are not widely used. Since they allow us for example. Know how to act in the face of errors that are thrown at us. For example, before an interaction in a database of data. Or to the input of user data. Or for internal records. Sometimes we have internal systems that do not The end user needs to be shown a message. Rather, it is an internal program to handle my business. So it's good that errors are shown to me. So that later the developers even can correct them. And understand what is happening. And it has those uses. It is not always the best option to use exceptions. That is why you have to know when to apply them and when to use them. Like any programming tool in reality. But now they have one more tool. Within your state of knowledge. And from advanced Python. So it makes me very happy to say that. Now we go with a section that I like a lot particularly. And it is the section of regular expressions. And these regular expressions. Look what we are going to see now. Watch it. Regular expressions. This that is here. What are they watching now? They are regular expressions. Okay. They are all characters. Just as if we were speaking Chinese. But they have a use. We are going to see it, we are going to understand it. They are literally like grasping a language tiny. And put it into a programming language. To make it work and behave on its own form. That is, we have the first Javascript course which lasts 10 hours. The second lasts, I think also about 8 or 9 hours. Among the three Javascript courses. They last, if I'm not mistaken, about 30 more hours or less. And of those 30 hours I couldn't explain to them. What now in Python I was able to explain to you. I'm very happy. But not so fast. I haven't explained it yet. So let's go. Sorry, sorry. I know I know. It's okay. I got too excited. It happens that I had left over. I wanted to take advantage of the situation. That's it. Forget it. Beautiful guys. She had recorded during a whole hour all sweating, all sweaty, being... And it ended and my power went out. This shit from the in... Oops. Power went out. What the fuck? Well guys I continue the course when the light returns. The whore that gave birth to him. This is scary on top of you alone, there is no one. But hey, never mind, here we are back. We have this regular expression file, okay? Let's put first and foremost import re, which is the module we use to work with regular expressions. We have more, but this is the most common, let's say, the one we use the most. We also have regex, it's not official python that one, but we use it too. In this case we are going to work with the official that the library brings us incorporated by default Python standard. To begin with we have different functions, okay? Such as split, search and so on. But you have to keep in mind that mainly what matters most is that they have to understand you have to find matches. That is, what we work here when we work with regular expressions is patterns. For example, I want to find an S with a dot with an A So with regular expressions we say we want to find that. And what can we do when we find a match is just returning it. Return all matches, replace it on the other, use it as a separator. I mean, there are many things we can do. So to start we are going to put a text simple and let's make the text be... Hello teacher, how are you? My captain. Eat. This is chain 1, how are you? My captain. Here we are going to put a question mark. In fact, I want this to have multiple lines text, okay? I want it to have multiple lines. I want it to have multiple lines, so We are going to use triple single quotes. There it is, to make room online. Here we put this is the second line of text and this is the final final, my captain. Well, for starters let's start with something simple. And that is, equal result re.search. This is the first function of all. This and find all are the ones we go to the most to use. But basically we're going to start with search. Which basically what this does is find matches and return them. If I'm here for example, look, look for me hello. Just find me hello in the text string call text. So if I show the result here, print result. This shows me something simple. He tells me, hey Look, I'm giving you a match object back. And here it basically tells me, I found it. Ok, match hello. I found the first hello. Easy. If I said find all, it finds me all the hello. If I give him, for example, that he look for me is, now he is going to give me back all the is. Why? Because it is and you are. There is no more, the others are with capital letters. If I put them with a capital letter for example. Here we are going to see what it tells me is and is. Easy. In fact we have an extra parameter which is flags. What is flags is basically for us to use certain parameters. For example re.ignore case. What he does is, look at me, ignore my upper case and lower case. So in this way I update and it tells me it is, it is, it is, it is Returns everything regardless of case and the lower case. In this case we are not going to use it because is what we want. But now let's start with the expressions regular. Here we are going to do a search simple. This is the simple part of all this. Let's start with the first expression regular. Hold on because regular expressions they have a lot of backslashes. The first is lowercase slash. And this basically what you are going to look for is... Search for numeric digits from 0 to 9. It's what you're looking for, okay? Numerical digits from 0 to 9. It's pretty simple. So here I tell you, the same result re.find all. Here is what to do, before how I used the F. Do you remember that if I use the F I can here for example concatenate. This we know. Here I can concatenate. Well, now if I use the R I am indicating which is not that I'm going to concatenate. What I'm going to do is use regular expressions. With the R we say, or it is possible that we use regular expressions. So we put the bar and we say bar of. So what you're telling me is... I'm going to look for numbers, numerical digits from 0 to 9 in text. So now we run. Let's comment on the previous result. This will show me 1. Because he is telling me look, I found myself just one. So if I put more here. For example this is string 1. This is line 2. Line 2 I will put here. And this is the final parenthetical line 3. So here I have this. 1, 2, 3. Because there are three numbers. You see? First he gave me back this one, then this one and after this. The funny thing about Python is that it uses the expressions regular with lowercase and uppercase letters. To make contrary cases. Not always, but in most cases. Or in the main ones at least. That is, if I wanted to find now all the coincidences. Not numbers... Numeric digits. I just capitalize it. Well if now here I say with a capital D. Find everything except numeric digits. If I now return this. I comment on the previous one. I discort this program and it returns everything the above. Everything. Why does it return all matches? what did you find. Everything but numbers. Notice that now there are everything except numbers. In this list that is returning to us. There is everything except numbers. In fact, the first number is after of the word chain. String. Space. One. String. Space. And now there is a comma. The one was between the space and the comma. And he didn't show it to me. Because it is returning everything but digits numeric. Then we have the character W. W what returns us is looking for characters alphanumeric. In this case it is, for example, all that has been. From A to Z. From A to Z. From 0 to 9. And also the underscore. It's funny, but the script also works under. That is, A, B, C, D. So up to Z. In lowercase. A, B, C, D. So up to Z. In capital letters. From 0 to 9. And he also looks for the script for us. In Python, the underscore is considered... It can be underscore, floor. As you want to say. It is considered an alphanumeric character. Not in other programming languages. But in Python particularly yes. So if I here, for example, I show you. I ask him to pass me the W. Okay. Here we are going to do the same. But make this with a capital W. Guess what the capital W is looking for. Everything except alphanumeric characters. So let's discuss the one below. And show with lowercase W. Let's run. Come? They show us all the alphanumeric characters. They do not show us the points. They don't show us the commas. They don't show us the parentheses. But I already tell him to show me everything except alphanumeric. I comment on this one and I comment on the one above. Now it is showing me all the alphanumerics. With a capital W. Let's check it out. to check There is. It's showing me the spaces. Because these that are here are spaces. Each space I left here is a character. So each space shows it to me. Commas are also characters that are not alphanumeric. The bar N? What will it be? Well, this is the online space. Do you remember that I told you that the bar N is the universal way of representing the online spaces? Well, here we have an online space. What is this here? And here we have another online space. What is this here? So this is here. In fact, when we do this. What do we do? We represent that with the backslash no. In fact, if I take out the spaces online. And run the program back. We run. Notice that there the bar N does not show it to us. We leave it again. We update it. And there he shows it back. Because it is representing the spaces in line we just gave you. Remember that it does not matter if it is not uncommented this. That is, if it is like that. Or so it is almost the same. Because here we are overwriting. Assuming all of the above are executed. This here overwrites all previous. So it doesn't matter if we forget to comment some. It's better because it takes less time to run. Remember that what the comment does is ignore the code. So, you completely ignore it. It doesn't run it. So if this has a thousand lines. It will always overwrite it. Only if we discuss it. The program is faster. So we're discussing it for that reason. Then we have another. Which is also precisely the S. The lowercase S. What it does is Look for blank spaces. The S looks for blank spaces. Which in this case the blanks are. Common spaces. Everything that is the tab. Tab. Tabulation. tabs. And also look for line breaks. That is, line breaks. The new lines. So if I check here and put the S. And we show the result. Come. It shows us the blank spaces. The jumps online. That's all it shows us. And guess what happens. If I pass him the capital S. The capital S is looking for us. Everything except blank spaces and so on. Come. Now he is giving us back. Everything that was not returned to us before. It is like. All that before gives us back. In which it is capital letter. It gives us the opposite. That's why it's good. That what Python does. To characterize it this way. You see, it wasn't that complicated. This from regular expressions. It seems really. Crazy. But. When we seriously learn it. It's not. The big thing. The point is what it does. Look for jumps online. Or line breaks. Or online jumps. The same. Same re point. Find all. We are looking for all matches. Point. There it goes. We simply drop a point. We run the program. And shows us There is. I ran the program. And he showed me everything but online jumps. This is search. Anything but online hops. There is. In reality, he is looking for the opposite. Quite the opposite of online jumps. And guess how we should do. If we want to search for jumps online. To search for jumps online. We just use bar N. The famous online jump. Well, to look for it we use the same thing. In other words, if we put the bar N. We literally look for jumps online. We will check it. We run the result. Bar N, Bar N. It's true. He looked us up two hops online. And if we left a few more. There is. It's showing us all the breaks online that we are leaving Let's go back to how it was before. There is. We run back. Now it shows me the two that were before. It would have been good just like that. Just as it was before. Lowercase uppercase. Lowercase uppercase. And else. lowercase n. It will search for jumps online. Uppercase YN will search for everything but hops online. Let's talk about it too. And let's go with the following that now I know It's starting to get a bit complex. If we only put the bar. What we do is cancel special characters. With the slash we cancel special characters. In other words, here I can say results. And the bar here if I, for example, use the point. Special characters are all those they are not alphanumeric. From a to Z. Upper case and lower case. From 0 to 9. And the underscore are alphanumeric characters. That is, the question mark is not alphanumeric. It is a special character. Comma or parentheses are special characters. They are not alphanumeric. Underscores are alphanumeric. oh! I shut them up. Middle hyphens are not alphanumeric. But underscores do. Remember that the underscores are the sign strange that it is rarely alphanumeric. But hey, it's an alphanumeric. For Python it is alphanumeric. So everything that is not alphanumeric we can cancel it. How we do? Well, if I now tell him to look for the points. Here I am going to put several points. I'm going to put hello teacher, period. This is chain 1, period. Now I run this and it will tell me. Che, look, I'm going to return everything except spaces online. Che, but I'm looking for points. Not. 12310 07:38:19,130 ​​--> 07:38:21,048 You are looking for everything except online jumps. I mean, what are online jumps I don't know you return. Everything else yes. Not skinny, but I asked you for a point. How do I search for a point? Simple. You cancel, you are cancelling. With the bar in front you tell him. Che, the functionality you had by default you don't have it Now we are going to interpret you as if you really you were a point And we are going to look for a point. F5 and there it returns the points. In this case it cancels special characters. Comma canceling the period function and searching points. There is. So in that way the fact is literal that we are looking for points. Ok, now more or less with what we have We are going to put together a fairly good chain. Let's see, putting together a chain that looks for a number followed by a text, followed by a space. No, followed by a period, period, and a space online. No, and a space, a space, a normal space. How do we do this? Well, we give you results. Let's cancel it. We are going to put together a chain that looks for some number, after the number there is a point. And it is that after the point is a space. How do we do that? Simple. Find all. Remember that if we want to look for a single match we will use search. But we want to find all matches. R, single quotes and we say look, I want search to start a number. We look for the numbers with bar D. Ok, a numerical digit, just one. And also I want to look for a point, but no we can give it point We have to give it a bar, period, because if we give it a point, it looks for us anything but tall online. And that it is also followed by a space with a bar S. Any blank space. It can be a line break, spaces in white, others So in this way we are looking for the set of all this. Let's see what it returns us. We text him and run to see. And here it is. In the string that we had him analyze, he found a one that follows it a dot that follows it a blank space. Let's see if we can find it. Here it is. There is a one that follows a dot that follows a blank space. If we now delete this space and update it the program back, he stopped returning it. Why? Because it stopped finding a matching string with the pattern that we passed to it. The pattern was. there has to be a chain that has number, point and then a space in white. And here is a number, there is a point, but it was missing the white space. There we leave it again. We run back and there he throws me again actually the pattern you found. Let's understand it, right? little by little let's understand Good. Well. Let's go with another extra thing. How do we find the end of a line or the beginning of a line, for example? Well. Use a sign that is worse than the backslash. It's B, but reversed. B, turned around. It's the one here. That same one. We grab it, we copy it, we close the tab and we use it. Find the beginning of a line, okay? The beginning of a line looks for it like this form. And well, oh. Another curious question is that if they wanted to know what this disgusting sign calls the circumflex accent. It's disgusting, but hey, nothing. It's strange to say. We are going to put a circumflex accent on it, but hey, nothing. The same for us because we are used to to the names of parentheses, square brackets and the rest. But brackets, brackets. Well, it doesn't matter. Finally, let's continue. Let's pretend that nothing has happened. Good. Here what we are looking for is the beginning of a line. And it returned the beginning of a line. But this is to use together. We cannot use it alone. Because yes, obviously all the chains of text have a beginning. How can we use it? Simple. I want to know if, for example, Hello is at the beginning of this string. And I'm going to say, well, look. Hello. And if I show the result it will tell me, Yes, it's at the beginning. Ok, it's at the beginning. If I tell him, che, let's see. Are you teacher? Let's check it out. Teacher. Not. He tells me teacher, we can't find him. That is, he is a teacher, but he is not at the beginning of the line. So if it's not at the beginning, don't get it. I will be able to show Is that how it works. Basically. Okay. Looking for Hello at the beginning of the line. Now, a curiosity. Okay. It is that if I, for example, want to check this. Is. This one is here. Let's tell him, update. It does not return matches. But because it is a new line. Well. This has one parameter. Remember I told you. flags. This, this Flags parameter allows us to modify the way we interpret it. In this case, if we give re. 1243 4 07:41:59,860 --> 07:42:00,860 Ignore case. Remember that this does Ignores upper and lower case. He also ignores it. But we have another. Okay. What is re.m. Simply the m that says che, I want you be multiline. That is, I want each line. After bar no. I interpret each line as if it were a new line. What does that mean? What if what it does is look for the beginning of a line. With this parameter activated. When we update it will tell me. This one brought me back. Why? Because now the beginning of each line goes To be. This, this and this. Here we have three different beginnings. If we take the parameter. The only beginning will be the chain total. It will be taken into account as if the chain was a single line. To at least use this little sign. The circumflex. But, now if we activate this parameter. We can put. Twenty lines. That it will have twenty different beginnings and twenty possibilities. If I actually put two lines. I update and it returns two this one. Why? Because there are two that are the beginning of A line. I mean. He found the pattern twice. Of this, the chain is. That is at the beginning of a line. It's really good. And here we say Flags equals re.m activates the multiline. We leave that. Let's discuss this here. And now we move on to the other. Which I imagine they will imagine. What is it. Let's copy and paste this. And we're going to use the dollar sign. Or the currency. That what you are looking for is the end. End of a line. Okay. End of a line. We are going to disable this comment because we have it upstairs. And now what we do is look for the end. As with the dollar sign. Let's see, let's check if it appears at final. No, it doesn't appear at the end. Well let's see if captain. Appears at the end of some line. Well let's check it out. We hit. It doesn't give me anything back. Because captain supposedly does not appear at end of a line. Why? And why the end? This that is here. It is not the end. It is a space. The end is here. So let's put it last. We close. And he calls me captain captain. Because there are two times. Oh look. I just realized that. Oh it's true. Is repeated. Captain here. And captain here. There are two matches. With the pattern we ask for. What is it. A text string. Captain. That it is at the end of some line. We found it. Then we have what have been the groups. That is to say. This. Let's put it no. Repeat. N number of times. Search. N number of times. The value on the left. That is to say. If I say for example Let's try. I will show you. Code easier. If I for example have this. Okay? That's it. I have this. And here I usually ask him to show me. digits. Well. Ready. We grab and he shows me the digits. But now. I wanna. Don't search Single digit. Look for a chain. Where. is. 3 digits together. This has to be found 3 times. update. And he doesn't give it back to me. Oh ok. But if I put the chain now. Okay. these numbers together. I run the program and now it throws me. Why? Because he found the condition. What was the condition? And the condition was. find me 3 times. This. I mean. For you to find a match. There must be. 3 numbers. And now I tell him. I want you to find me. 3 numbers together. A space. And so. That's it. It's finding me. 3 numbers together. And a space. Well. Let's check. He found it for me. Fine. For what? Because up here we have 3 numbers together. And then I say a space. If I will delete this space. The same as before. He stops showing me. Or that it does not meet all the conditions. It just shows me. 3 numbers together but no space. So the chain is not fulfilled. We run and there it shows us. 3 numbers together this time. And then we have to make ranges. For example. We want you to search. At least. N number of times. And at most. M number of times. I mean. At least. m. At most. m. So this is what you are looking for. At least there is. A coincidence. And as much as there is. 4 matches. So this is going to give me back. And here we have One. Here we have. Other. Here we have. Another and here we have another. It's giving me back All values. Okay. Where you find At least 1. And at most 4. If I told you here Nerd. I want them to be at least. 2 characters that it is showing me. And he's going to show me only this one. Because this. Everyone else has 1. And I need you to show me at least 2. Well. I'm going to add to this. 2 more characters. And now he's showing me 4, because he's displaying a maximum of 4 characters. I add more numbers. Now he's bringing me back. Found the maximum of 4. And then he returned another 3 numbers. Why? Because you found this. This is here and we told him. Oh no, stop. Give me back. Four. That's it. He gave me back the 4. Minimum 2. Here he found 2. 3. And he gave me back the 3 he found. That's how it works, let's say. Is. This function. This regular expression, sorry. Then we have sets. If I, for example, want to tell him to find me. Easier, see. May A, B find me. May he find me A, B in this order. What he is doing now. It is looking where we find B. Only the B. That is to say. If I put here for example. B, B, B, B. And here I put B, B, B, B, B. I run the program. And this is not looking for me the A. The A is looking for me. Followed by a B. Where at least 2 or 4 times. So I'm going to put the A. And here I am going to put the A. Run the program. And this tells me A. B, B, B, B, B. A, B, B, B. Why? Because this is looking for me the A for a side. And this only affects the first character. If we wanted to make it also enclose to the a We lock him in something called a group. The groups are made with parentheses. Just like when we do combined calculations. What do we say for example? In brackets. A plus b. And outside the parentheses. All this for 5. For example. So it is the same. Then. Now I want this. As a whole. look for it At least 2. May you find it at least 2 times. And maximum 4. So here. We update. And it no longer shows us. How do we get him to show it? And now it doesn't have to be A, B. It has to be A, B, A, B, A, B, A, B. There we run and he shows me. You see? A, B, A, B. Well, let's go... Let's see what happens if we say 3, 4. We run the program. And it doesn't show it. We are going to show only 3. What is happening? Four. one. And what is happening in this case. It is something else. He is giving us back. A B. Every time you find the a,b For 2 for example. Okay? If I here for example. I say look. Let's see. If you find 2 times. A, B together. You give me back only A, B. And here we are going to check it out. A, B, A, B. It returns me an A, B. Another one. A, B, A, B. It returns me another A, B. And then another one. A, B, A, B. It returns me another A, B. That is what is happening in this case. He's not going to give me back... A, B, A, B. In other words, what he found does not return it to me. One thing is what you find. Another thing is what returns me. Here we are not telling you to give me back 2 times. A, B, A, B if you find it. Not. We are telling you if you find. what is A, B, A, B. If you find it 2 times you give me back only a, b. Brackets. And now if we run it gives us everything back find. The square brackets serve in this case to say that this is going to apply to each of these. That is, we are going to try to find 2 times the A. 2 times the b And every time we find a match let's return it. So this is how this one works. But we're not going to screw up that much. We are going to stay with the former. There it goes. So we're just looking for this quantity because otherwise we are going to go crazy Really. In fact to complex a little more and finish making us close this. I will explain the last one which is enough useful too. What is the O property? This is easy. Look for one thing or the other. What is to the left of that operator. Or whatever is to the right. We're going to put this back and we're going to paste it. And here we do the same. We say, let's see. You're going to find this for me. That he is going to give me back what he already gave us back before. Or if you can't find that. You're also going to say hello back to me. For example. Then it returns me both. returns hello. Because he found her. And it also returns this to me. The interesting thing is that no matter how much we have said to return this to us first. First he returned this to us. Why? Because the string appears first. So as much as we put it later. He will always return it first. So that brings us back. One thing or the other. But it's not choose one. It's not if you give me one back. Don't give me the other one. It is you find alone return it. Ready. Jewel. You find this return it. It's like running it twice at the same time on one only. It is not either this or the other. It is the or condition. As long as one of the two is fulfilled. We are going to return an object to you. If the two jewels are met, we will show you the two. Now with all this ready. What I came up with to be able to be more practical. It is to parse a couple of text strings. It seems to them? Let's look at a couple of regular expressions which I am going to download now. And when I have them. Let's analyze them. Well, let's analyze this one here. I created these regular expressions with ChatGPT. That we will explain how to use it at the end of the video. So quickly I told him that we create expressions regular and created them for me. Well let's see if we guess what it is that we is asking for this. It is simple. He's telling us look. Find me a chain where D. It appears at first, then you have to find anything that is not a space online. The asterisk. What the asterisk does is, it's interesting because I can explain it to you. It affects the previous operator. And basically what we tell him is che mira. Let's see you're looking for anything but high in line. Well find me zero or more occurrences. In other words, if you don't find any, I'll leave it to you happen. And if you find more than one occurrence. Well give them back to me. It is so. That is, if for example you find a character that is not an online space give it back to me. If you find zero I forgive you. If you find thirty, give me thirty. Or give me the most characters that match this. When one arrives that doesn't match, that's it. It's okay, we finished it. But that's what this operator does. This operator is basically an expression regular. Which tries to find zero matches or some. If you don't find matches it doesn't finish you the text string. The coincidence I return it to you the same because It's like it allows you. But if you tell him, find me the lyrics A. And you have a text that your sister says with thirty. With this operator you will return the thirty. And if you put ten on it, A will give you back ten A. And if you told him, your sister will let you pass the same Because even though I haven't found the You allowed it. You told him if you find any, put them on. If you don't find any, it's all good. nothing happens. I take it the same. Then we go back. The text string has to start with T. It starts with perfect T. And it has to be at the beginning of the line. It's 10 ready. Then it has to be followed by characters that no line spaces you want. These are all characters that do not have spaces line. So so far the condition has been met from 10. It was fulfilled. Only this would return the entire string of text. Ah but there are more conditions. Ok there has to be DOG. I mean ok let's see if it finds it. Well DOG perfect. Found DOG so D is at the beginning. Find many characters and also is DOG well. Ah but DOG has to be at the end. Ok it's also at the end. Ready then this entire chain is going to return correctly. We update and this will return yes. Why? Because this returned us a match. First regular expression. validated. Let's go with the second. This one is more complex. It says the date is 23 of 6 of 21. And the phone is plus 1 55. Perfect done. Well this is the pattern to look for. Well here it is basically pattern. We create a text string with the expression regular. We create a regular expression pattern. And basically here we look twice for a number. Then we look for a bar. Here is a bar. Then we look back twice for a number. Here we find two other numbers. Then another bar. Another bar. And then we search four times for a number. Here we find four times number. So indeed here you will find A coincidence. Why? Because this has twice a number. A bar. Twice a number. A bar. And four times a number. And that's what we told you here. Twice a number. A bar. Twice a number. A bar. And four times a number. So he finds me. Perfect. Found the date. It is a valid date. And here we are creating another string that says... Replacement chain. Hidden date. Okay. And what it says here is to replace all the occurrences of the pattern in the text string. NewText is equal to re.sub. Sub basically what it does is... Find the chain and make a replacement. First this is the pattern. The pattern we are going to search for matches is this. What we find we will replace with this. In this case you are replacing it by date hidden. Where are we going to replace it? In the text. So what we're going to do is... First we grab the text. Then we will look for the pattern. It is this that is here. And if it finds a match it replaces it by hidden date. So that? To hide the date. So the end result will be... Modified text. The date is hidden date. And the phone is the phone. So in this way we were able to detect which is a date format. And change it to hidden date. Fascinating. Let's go with the third regular expression. Replacing all the vowels by the asterisk. Well, re.sub. You will find all the vowels. The A, the E, the I, the O and the U. Any of these characters give them back to me. They don't have to be all together. It can be any separately. If we told him like that... I should specifically find myself in this order. The A, the E, the I, the O and the U together. But here we tell you to look for each one of us separately. And replace it with the asterisk. Where? In this chain. So if we find... If we execute new text. Replacing all the vowels by the asterisk. Or easier, by asterisks. We run. Replacing all vowels with asterisks. Perfect. We understand how it works. Let's go with four. Here's a... This is a very long one. That is validating mails. Well. Here we tell you. The middle hyphen is used to make separations. Okay. On the one hand he is telling me. Matches may be valid have from A to Z. From capital A to capital Z. From 0 to 9. Everything that is not an online space. Underscores are also allowed. We have this that is here of the percent sign. Let's say it's a wild card. It's like everything I find before and after he will validate it. We have the most. The most what it does is... Do you remember that the asterisk was looking for us zero or more matches? Well. This finds us one or more matches. That is to say. The asterisk was flexible. He told us to look and see. If you find a match, show it. And if you don't find matches, I'll leave it to you happen. The most says no. You find me a match or more, show them. You can't find matches for me, I won't leave it to you happen. It is almost the same only that the minimum of coincidences is one. It is not zero. one I mean, if it doesn't match, I won't let you go. one Okay. one And we close this set. one Then here the same. one Tells us. one Find me at least one match to everything this pattern. one In other words, one of all these has to be at least once. one The plus modifies in this case the whole bracket together. one Because since it is enclosed in square brackets, change everything together. one Find me at least once one of all these characters. one Perfect. one Here he found it. one For example, at example.com. one This is an email that at least the first We validate part. one Okay. one Until the at one The arroba found it. one Before the at sign there must be at least any character that meets these conditions. one Here he fulfilled it. one Later an arroba was found. one The same output was then executed. one Okay. one The same result. one Only that he took the percentage. one Also works. one Okay. one He also found the conditions. one Then we use a point, as we put the front bar. one Now we're not looking for everything but spaces in lines. one We are specifically looking for the point East. one Here we find it. one There is a point. one And after he returns me. one Okay. one Values ​​from A to Z lowercase. one From A to Z capital letter. one At least twice. one What does this mean? one Clear. one Why does a domain have to be for example google.com, gmail.com, facebook.com. one And the emails are something at something.com. one We have.br,.ar,.co from Colombia. one But there are no domains that have only one letter. one The minimum you have is two. one So we have to tell him that at least this is found twice. one Which finds at least two alphanumeric characters. one Which are not actually alphanumeric. one They have to be characters. one Okay. one Of the letters of the alphabet. one From a to Z. one It doesn't matter if it is uppercase or lowercase. one Twice. one And why is it coma and easy? one Because we are saying and without limit. one Why? one And because it can be.tv. one It can be.online. one It can be.something. one .god. one We don't know what can. one We are not going to give you a maximum. one But there is some domain that is that I do not know. one Facebook. the teacher is very hot. one And we don't know the limit. one So the limit doesn't matter. one We left it open. one It can be two, three, four. one We are not going to put a maximum. one Remember that it is a range. one This is already a range. one So at least have two letters. one And then the ones you want. one And it complies. one So what we do is try to find with match. one What we are looking for is to find a match. one If it matches, it tells us that it is valid. one It will return us that it is the valid value. one If it does not match, it tells us that it is invalid. one We run. one Perfect. one It is a valid email address. one If we send you any email. one It says it's an email. one An invalid email address. one We are going to pass him. one lucasdaltonuevoshemail.com one Let's see if I create this account. one It tells me that it is valid. one It is a valid email address. one Let's see if I put.c. one Let's see if I take it. one So with regular expressions. one We have just validated that a text string. one be an email one That is to say. one We just found a way to validate. one A mail. one An email field. one Perfect. one We're going to close this and we're going to open the last one. one Here what we are looking for. one Let's see if they notice. one Is. one Let's see. one HTTPS. one That's it. one We realize that we are trying to validate a url. one Good. one It has to boot with HTTPS. one This question mark is one This question mark means one If you find HTTPS go ahead. one show me. one But. one Nothing happens. one It's perfect. one The question mark ahead. one What it does is. one Remember that the asterisk said. one Zero matches. one Or some. one The most said. one At least one match. one Well this tells me. one find me one No match. one Or one. one If you find more one It doesn't matter. one Don't show me. one I'm not interested. one After this match he found. one In case you found it. one If not, nothing happens. one There must be two points slash slash. one And then there has to be at least once. one This that is here. one What is the character of the domain? one Not. one At least. one Once. one Perfect. one Good. one Then there has to be a point. one And then there has to be the same. one The format. one Which in this case is one At least twice. one Letters. one And then whatever. one So for example. one HTTPS. one Two points bar bar. one Facebook. one Point. one With. one I take it. Valid. Of ten. one We will check it. one Let's see. one If I find a web page. one example.com. one example.org. one Let's show him. one Let's see. one dalto project. one Projectdalto.com. one Let's see if this detects us. one If not the HTTPS. one I don't detect it. one Because we didn't put the. one Two points bar bar. one HTTPS. one Two points. one I run the program. one And now if it detects me. one It is only detecting addresses for me. one What are they. one valid. one This is a web page. one In fact. one Note that it uses Studio Code. one It underlines it. one It's excellent. one And there. one Basically. one We just more or less understand how they work the regular expressions. one So now what I'm going to do is. one Create a file that will be. one creating. one Expressions.py. one detecting. one EITHER. one A number. one caba. one And hiding it. one Let's hide the number. one The text will be equal to. one My number is. one Let's leave it like this to make it more complicated. one Good. one Let's create the pattern. one Pattern. one Stop in English. one So that it does not carry accents. one And we're going to say that. one First. one It has to start with a plus. one Okay. one One more. one Like the most. one It is a special character. one We have to cancel it. one We canceled it with the bar. one So to start. one Search this. one We are going to show the result. one Replacement. one Same. one We have to import the . one The bookstore. one Import. one Re. one There is. one Re. one Sub. one Let's try to find. one This pattern. one Replace it with. one Number. one Hidden. one In. one Text. one Let's see if it actually works. one Good. one Let's show it. one Print. one Replacement. one We run. one Y. one Hello Pedro. one My number is. one Hidden number. one Good. one So far found the most. one Perfect. one Well. one Now in addition to the plus. one After the more. one A 54 has to come. one How do we do that? one Well. one D bar one And we run it. one This twice. one We want you after the most. one is. one Twice a number. one In this way we are changing. one Let it be a number from Argentina. one At least. one If we want to vary specifically. one Let it be Argentina. one We can put. one 54. one For example. one But in this case we are going to say that. one There has to be at least one. one And maximum three. one To validate the characteristic of a country. one For example. one Well in this case. one We are going to validate that it is Argentina. one Have two numbers. one We are searching for it. one I like it for that. one Could be 54. one But to make it complex. one We check. Let's see. Good. Now she found us the 54. one Plus 54 replaces it with hidden number. one Let's go for 11. one We have to find a space. one Bars. one To find a space. one Now they have to find a space. one Then they have to find one. one eleven. one In this case. one And instead of 11 we are going to do the same. one Let's give it one Ask for two numbers. one Let him find us two numbers. one After you find us another space. one There has to be another space. one Then they have to find. one Four numbers. one Then they have to find a script. one But the script remember. one Which has an effect. one Of a special character. one But let's check it out. one Come? The script is replacing me. one Okay. It has no special character effect. one Why? one Because it is not inside a bracket. one Then. one let's get out one And if we now ask him the same. one That is to say. one Let him give us another four numbers back. one There is. one We did it. one We managed to replace this number. one Okay. But what if the guy puts. one Twice the number for example. one There is. one And there it is. We have other numbers. one Good. one If you put it twice. one Ready. one Replaces it twice. one Now we have a regular expression. one What it basically does is search. one Numbers that have this format. one From Argentina to Buenos Aires at least. one And replaces it. one This was just the expressions section regular. one If you want to investigate. one They have a huge section. one Because there are a lot of regular expressions. one They can really go a lot deeper. one It could be a whole two-hour course of regular expressions. one I didn't see her either. one It was not going to be specific courses of everything. one Because it gets out of hand. one We are not going to focus for now on expressions regular. one In fact, when we work intelligently artificial. one Not even there we are going to work with expressions so regular. one Because it is not very normal to work them. one But with this we have what it takes. one We know it is a powerful tool. one And if we have to work finding matches or others. one It's a matter of searching the internet. one Search the official Python documentation. one And look for other regular expressions that still we did not see one That they will find them. one But if I continue, it will take us very long. one But there we have a lot of expressions most used regular one The most common. one And with which they can already work. one Put it to use and do a lot of things. one So I'm really happy to have been able to explain regular expressions one For a long time I wanted to explain to you in some language one At least regular expressions. one And that they are Python made me very happy. one So good nothing. one Now we go to the next topic. one Which is excellent. one We need to see everything. one We need to see decorators, generators. one Closures and so on. so good we continue with the next topic. one Let's go with this advanced section that we are with everything. one Go! Well, now the truth is that as you can see I got quite tryhard Because the time has come to explain Hey Dalto, that's it. What are you doing? Hey? But what are you talking about, boy? Yes, that's it. Finish the course here But how am I going to end up here if the people want to continue learning? But if they already learned a lot, you sent yourself of terrible course, man They already learned crazy, you surpassed by far to the other courses Let's see, overcoming is subjective It's not so good to be comparing yourself either with others Dale Dalto, did you see the quality so obviously visual as material in this course? Yes, obviously, let's see, but it's not that bad Ok, so tell me another python course that it took me three hours to do it Let it be 4K, let jokes get in the way And that it has dynamics as marked as the of this course Yes, yes, it's okay, it could be, what do I know I And another channel begins to explain concepts advanced in a course What was supposed to have arrived until intermission I don't know, what do I know, I don't know, I wanted to to continue explaining Dalto, you made them beasts in Python Even they are already ready how to know even even how to find new material Yeah, yeah, okay, that's true We all know that those who watched this course they will want to continue learning They will be on your channel pending because they know they will continue to learn They even know how to do it, so what more are you waiting for? Oops, we didn't do a final project You are loading me, you did several exercises with each point that you were explaining Well yeah, okay, but a final project to close the project, unite all the knowledge You have just created a program that through expressions regular Identify a number and replace that with... Hidden number Yes it's alright that's true Also, you told them, everything you told them I teach, put it into practice So, technically they should already be doing their own projects Writing your own code and what else powerful than that Well, yes, but a final project for, what I know, unite all the knowledge, I don't know, anything else Don't forget what you told me, that the first time they see this course they will understand stuff But the second time they see it they will learn even more Yes, that's true, this course is done so that people see the course twice And that the second time they can learn and see things that they did not see before, that is, that before passed by Exactly, so when you see him back they will know more than they already know listen let's do something Let's see Look, close the course here, okay? Give a closure to everything, people have already learned a lot, she is happy, she is satisfied and will wait more, ok? Give an end and a closure to this cycle I wanted to continue, well, but what then? what's next now? And follow the next course, that there is no one good or good on YouTube, you know what I am talking to you And that you know that people are waiting for it and it will break everything if you throw it Ok, okay, but what is it? I'm talking about what everyone asks you, what people do not stop telling you Take the course, take the course, we're talking of that, that it is counter-powerful and that people need it But what are you talking about if the continuation of this course is oriented programming to objects? Let's see, I'm referring to that, let's see, it's well, this is a useful course, great for complement this course But answer me this, what were you up to working all this time? I don't know, in the new studio, in the new channel, in the high project, there are many stuff No, no, I'm talking about courses, about courses I don't know, the same, I have several in mind, I don't make say it Which? Node, I'm going to say there is a course so you don't react Because it is that anyone, but even DJ Ango he knows Did you just reveal? Yeah oh well you're carrying me You know what is best, the time has come that we talk less and do more Yes, it was the same that I think so, that's true what could be one of the most unbelievable things useful for people who follow the channel And in fact you could put the link in the description so that if someone is watching This video, when it came out, I can see it You're right, and I might as well tell them that they go to follow me on Instagram, arroa SoyDalto Yes, yes, still don't spam, please I said that to Instagram SoyDalto because there is where I put all the news, where I communicate with them and because I deserve it, damn But relax me a bit, skinny, calm down a bit little, calm me down Think that if you achieve this you would close cycles that you started a long time ago, you would complete stacks and you would make sense and unite all the technologies What have you been teaching on this channel? It's true, you're right, but then what are you waiting, dad? And now yes, okay, what do I know, what is what he dedicates to you? did you motivate me That's how I like it, well, listen to me, but first I want to ask you something What you need to know? Who were you? oh! I am... Not to me, to the camera I am Dalto With more desire, skinny I am Dalto And where do we meet? And see you in the course of... In which course? In the course of... In which course? In the course of...