Python Programming | Jason Drake | Skillshare

Playback Speed

  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Python Programming

teacher avatar Jason Drake

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

58 Lessons (8h 5m)
    • 1. 00 Intro and Course Overview

    • 2. 01 Get started by installing python 3

    • 3. 02 Setting up sublime text to build python

    • 4. 03 First program in python

    • 5. 04 Data types

    • 6. 05 Variables

    • 7. 06 Indentation

    • 8. 07 How to clear screen

    • 9. 08 Singleline comments

    • 10. 09 Multiline comments

    • 11. 10 Basic arithmetic

    • 12. 11 Division characteristics

    • 13. 12 Operator precedence

    • 14. 13 Complex arithmetic

    • 15. 14 Binary number manipulation

    • 16. 15 Basic string manipulation

    • 17. 16 Using the format method

    • 18. 17 Specific characters

    • 19. 18 Logical operators and conditional statements

    • 20. 19 if statement

    • 21. 20 if else statement

    • 22. 21 ifelif statement

    • 23. 22 ternary operator

    • 24. 23 For loop part 1

    • 25. 24 For loop part 2

    • 26. 25 For loop part 3

    • 27. 26 while loop

    • 28. 27 Break and continue statements

    • 29. 28 Defining and calling functions and returning values

    • 30. 29 Passing arguments default parameters scope and nested functions

    • 31. 30 Recursive functions

    • 32. 31 Lambda functions

    • 33. 32 Exceptions and errors

    • 34. 33 Handling exceptions

    • 35. 34 Throwing exceptions

    • 36. 35 Data input setup and input function

    • 37. 36 File management reading

    • 38. 37 File management writing

    • 39. 38 Tuples

    • 40. 39 Tuple functions

    • 41. 40 Lists

    • 42. 41 List functions

    • 43. 42 Dictionaries

    • 44. 43 Shallow copies

    • 45. 44 Sets

    • 46. 45 Set functions

    • 47. 46 Modules

    • 48. 47 Packages

    • 49. 48 Builtin modules

    • 50. 49 Introduction to oop

    • 51. 50 Class definition and object instantiation

    • 52. 51 Class methods part 1

    • 53. 52 Class methods part 2

    • 54. 53 Operator overloading

    • 55. 54 Class inheritance part 1

    • 56. 55 Class inheritance part 2

    • 57. 56 Extra notes in python

    • 58. 57 Visualization, Object, Libaries, Patterns, Other Topics

  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.





About This Class

This is the most comprehensive, yet straight-forward, course for the Python programming language. Whether you have never programmed before, already know basic syntax, or want to learn about the advanced features of Python, this course is for you! This course will teach you Python in a practical manner and learn in whatever manner is best for you!
I have cover a wide variety of topics, including:
- Command Line Basics
- Installing Python
- Running Python Code
- Data types, Variables, Indentation
- Comments, Basic arithmetic, Operator precedence
- Conditional statements, loops
- Recursive functions, Lambda functions
- Exceptions and errors, Throwing exceptions
- File management reading, Tuples
- Lists, Dictionaries, Sets, Modules
- Packages, Class methods, Visualization, Object, Libraries, Patterns, Other Topics 

Meet Your Teacher

Teacher Profile Image

Jason Drake


Hello, I'm Jason.

See full profile

Class Ratings

Expectations Met?
  • Exceeded!
  • Yes
  • Somewhat
  • Not really
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.


1. 00 Intro and Course Overview: thing. 2. 01 Get started by installing python 3: Hello and welcome to our python tutorial. Siri's to start off. We're going to show you how to install Python, so it's pretty simple. So you're just gonna head on over to your Web browser and we're going to search for we're going to just shove it down. We're just going to search for ah, download python click the first link, Donald Python a python dot org's. So the version we're going to be using in this tutorial is 3.5 to even find it downloaded from this When you click this button right here, so just click that it automatically gives you a file. You say that sweet for the download. So just gonna wait for that? So we're just gonna be using 3.5 because, um, they're obese. You'll noticed throughout the series will discuss some differences between the version 3.52 and version 2.7, But they should They're pretty similar. Just some minor differences. Some pop, arguably pointless differences, but whatever. So we're just gonna wait for this downloads, Taking some a long time for some reason, I don't know. But anyway, just waiting, so waiting. OK, there we go. So we're going to run this file. We're just gonna install. Now, say yes to all the dialogues were just doing express express installation. We don't need toe tweak with anything. And while that's installing, we're gonna just close the browser. We don't need that anymore. So we're just gonna wait for this to install? It's pretty simple. You just have to install, like, any normal executed filing windows. And, uh, we're going to be Ormond after that. We're just after this insult. Just actually show you something else we're gonna need for later one building file one building python scripts through both the consul and in our I d. Which will be talking about in the next video. So this is about finished up. There we go. OK, so now we have python installed. So when we set search for in the start menu P why we have python. So what we're gonna need we're gonna need to add environmental variable toe windows for python itself so we can actually run python through the through the windows Command prompt and use it later. Use it later in our i d e s o. First, we're gonna find the location of Python. So it gives you a shortcut. You're just going to go once again, Open file location. And here we have this directory. So we're gonna just keep this like this, set this aside for later and what we're gonna do now we're gonna open the start menu, and we're going to search for E N V I. So if you don't have, if you don't have it automatically for some reason, you can just go to you. Just find that this PC, the more the longer way. So you find this BC, you're going to right click and you go to properties and you're going to go to advance system settings. And here we can close this. Now we're going to see environmental variables. So that's what we're looking for. Okay, So down below here, you can see you're going to click this edit you not the one love the one below. Well, actually, we're gonna look for one called path and that we're going to click at it. Path is all is Capital P and lower case a th. So here we go. Here are some environmental variables from path, and we're gonna add a new one. We're gonna create a new one. So we're going to do Click New and then we're gonna copy this directory. So we're gonna copy that. And OK, so new copy. And that's that's it. And in case for safe measure, sometimes I'm mushroom myself. But I like to add the actual execute herbal file so we can do the following on. Let's just let's just let me just find the actually, let me just take this and we're just going to say slash and I'm casting up on the keyboard , so slash python dot e x e you and I think I've really at that checks out. So Okay, so just in case we need something. So now everything set up and ready to go for pie using python. And in the next tutorial, we actually showing how to set up our customized I d which which I hope you tune into. So that pretty much conclusive tutorial We hope you enjoy this. Siri's 3. 02 Setting up sublime text to build python: Hello, everyone. Before we move on to developing further programming further in Python, we are going to set up our I d. E. Now I like to use sublime texts. So we're gonna open up our Web browser and search for said I'm sublime text to download. So supplying. I'm learning on a 64 bit machines. So I use 60 forbid. If you're running a 32 bit, just install 32 bit version. So it's downloaded. We're going to download it and we're gonna install it. And you'll notice later that we all have to manually implement the Python interpreter so we can actually run python files in sublime text. So we're gonna install it. All right, Close that it's all finished. Now let's find our python interpreter path. So when you search for python in the start menu, open fire location and now before for convenience sake, we're going to rename the Python file Execute will file. That is, to python with lower cases. So in my case is already done. But if it's different, right click rename and type in python lol, lower case. Moving on. Let's open. So oops, I for actually got accidentally closed it so, python. And then you go to open file location and then on the shortcut you see from that search, you do go to properties, and there should be a target field. You're gonna want to copy this for later. Going to say that for later we'll show you what to do. Just keep this. Save this for later. So was open. No pad. So we have this on the side. Just keep it. No pad window open to save this path for later. And remember, this is arbitrary. So it could be different on your machine, depending on where you installed Python. But on my machine, this is what it is. If you can't see right now, don't worry. We'll zoom in and later, so we're gonna minus that. All right, so we have the target. Now let's open sublime text. So some line. All right, here's sublime text. Pretty simple, right. But first, before diving into things, we're gonna have to set up the build a build system that is so here. It says python already. But dont this problem. This doesn't work because we tested it and there are some issues with the path, So we're gonna manually make a new build system. So you're gonna go to tools build system and that on the bottom, you have new builds. Have some, like I just did. All right, So here's our new bill is empty right now. So what we're gonna do, we're gonna open this. I have this piece of code to this piece of text saved and this You gonna want to copy this exact texts and I'll explain what it is in a sec. So we're gonna copy this and paste into here and you'll see where our path comes into play already. Have it paste it in here for the sake of time. So we're gonna You're gonna have to pace the path from this file. We opened a note pad. The rumor, the file We happen to know, Pat. We're going to open that and copy it to here. This is the path and you have to remember that we're in windows, so we have to use back slashes and were using double bag. Slash is to use because their escape characters. So be sure to use the double slashes in the path portion of this piece of text for the build. So when we're done, we have this copy pasted and everything. All the path is set. We're going to say this and then we're going to save it as python with a capital P price on dot sublime dash build. So what? This is we created our own build system We're gonna save. All right now, we have sublime built. So what's make a python file? So, what we're gonna do, we make a new file. We're going to first save ass. You don't have to do it, but like this, But this is how I do it. Save as. And we're a name it test dot p y. That's a python file extension. Oh, and of course, don't forget if you're automatically in this inside a folder, go to the desktop for simplicity's sake, so save it has test up. Ey. All right, so here's our python file. And don't forget to apply the bill. The build system itself. So system, as you can see, we added another python built system. The 1st 1 as I said before, does not work. So here's the bill. 2nd 1 choose the 2nd 1 All right, so now we should have color coding for functions and stuff. So let's do welcome. So here's our line of code print and python and order to run this. We're gonna do control B which is built and, as you can see, welcome printed in the console. And so now we have ah wolf Working Python I d. You with sublime text. That is all for this to tutorial. Please tune in next time. 4. 03 First program in python: Hello, everyone. Today we're gonna make our very first Python program. To do this, we're going to simply use print. What print does is print a string to the screen. Now, inside the parentheses, we pass whatever string or other value variables or arguments that we want to pronounce. As you can see, after writing the statement in pressing, enter it displays. Welcome to the screen now in older versions of Python Sorry. In version 2.75 On this in tax is a little different. This is written like this print. No pregnancies. Welcome. I can't type today. Sorry about that. I'll get better, I promise. So, as you can see, we wrote with the old syntax. But it didn't work in the new version, as it says says missing parentheses in call to print. So that concludes this tutorial. We successfully made our first program where? Prince, Welcome to the screen. I hope you'll join us next time where we'll be talking about data types 5. 04 Data types: Welcome back, everyone. Now we're gonna talk about data types in order to help us illustrate what data types we have. We're going to use the function, type my that. But this function does. It tells the interpreter to output the type of whatever is in the parentheses. So let's start with Type two. What this is is a neuter. An integer is any number whole number, no decimal points. Let's do type Now with 2.2. This is a floating point number. As you can see, there is desperate Boy and numbers coming after the decimal point must do a really long in future now to with lots of zeros in version 2.7, this would be a long and bitter. However, in version 3.5, this is a regular integer Let's move on to type of truth. If you're familiar with this, this is a Boolean. Boolean is basically true or false one or zero. Now, a special specific thing in Python we have is do how we deal with characters. My bad. So let's see here a single character is interpreted as a string. That's because in python, single characters are considered single letter strings and we'll see the same type come out when we do a B C. It is also a string. So that concludes what data types were going to be dealing with in Python. Next time, we'll be doing variables. 6. 05 Variables: Let's talk about variables. If you're not familiar with with variables themselves, that's OK. We're here to talk about them, so a variable is basically preserve memory location with with some value in it. So let's write. Our first variable number equals two. All right, So if you noticed in our previous tutorials, values we've used before are basically gone once were used, but in the case of number, right here to community used over and over again. So let's make some more numbers. Variables. My back rial word equals, Say a word. Okay, Now let's see how these can be reused. So let's say a word. I mean, he seaward. So let's do a type of word and we get class string. So basically, we re use word again and again. Moving on. Let's try applying, assigning one value to multiple variables, so let's say a equals B equals C. Now. This is pretty logical, isn't like in mathematics. You just have multiple variables and you sign one value. So let's demonstrate and see if this works. Print a 1.5 print, be five and friends. See 1.5. As you can see, this worked. So let's talk about the common operator Now what this does basically we have. It can take multiple variables and assign multiple respective values to them. So let's have one to three. Those are three variables and we have one, as in the number two, as in the string, the word and 3.0 as in three and the floating point form. All right, so how we have our variables. And now let's see if this works souls to print one. We get one imprint to we get to and print. Three. We should get 3.0. All right, so now let's demonstrate the dynamic nature of variables and python. So let's say Let's reassign number as one. And then let's do Let's make a string called STR called an inside its strength and then let's say number again. But this time, equal strength. And if you've noticed and if you're familiar with other programming languages, this might kind of look weird to you. But in python, this kind of this is kind of what you it's unique to python, so basically, you could dynamically assign variables you don't have to basically, first to find the type and the variable name to initialize it in Python, you can just write a string variable name and its value. You don't have to worry about initializing it. And that's what makes Python pretty dynamic. And it's also important to know that variable names should be pretty descriptive, self descriptive that IHS. So be sure to name, for example, string String. If it's gonna be a string, be sure it's pretty logical, so you don't have to. You won't get confused later, like don't name String if it's a number and number. If it's a string, just be sure that you make variable names that are pretty logical and easy to understand. So moving on, let's see what things we can't give name as names in variables. So first we're gonna do import keyword and keyword dot kw list. So these are keywords, basically their specific words reserved in python for specific purposes and functions like as we saw with print and type. So don't give any names to your variables, that is, that are in this list. And that is all for this tutorial on variables 7. 06 Indentation: all right before moving on and digging deeper into programming in Python. Let's talk about the importance of indentation. If you're familiar with other programming languages, blocks of code are separated, for example, in C plus plus and C with curly braces and pls Q and Pascoal used. Begin and end Now in Python, we use indentation so we pray that basically press the tab key to have a blank, empty white space in front of, ah, pseudo code here, as we can see. So here we have to do functions. We'll talk about functions later. Don't worry in our later tutorial with pseudo code statements. As you can see here, the the indentations separates the blocks of code. As you can see this statements 123 are one block and statements 4 to 5 are another block. So, as you can see, this code is a lot more readable and aesthetically pleasing. Unlike before we're or in other cases where we have jumble code just all over the place, this is actually it helps us read it better, and it's more organized, and that is all for this tutorial. We'll see you next time 8. 07 How to clear screen: Hello, everyone. In this tutorial tutorial, we're going to learn how to clear the screen in Python. So first we're gonna type out import less press, enter clear equals lambda, uh, semi colon or sorry, colon os dot system in parentheses, single quotes, CLS, close parentheses, press enter. And when we use clear every time now it'll clear the screen. Now, if you're wanting where I got this from, I just looked on the net for clearing the screen. And python is pretty simple, and that is all for the signatory. 9. 08 Singleline comments: Hey, everyone. Now we're gonna talk about comments. So if you're familiar with comments, what they are, basically they help us organizer code until other programmers What our code does so in python comments are notated with the hashtag symbol or friend, your older generation, the pound key. So when you write this the hashtag symbol or the pound key Azaz, I might say sometimes anything afterwards is a comment. So this is a comment. As you can see in sublime text, it's notated with different colors, so you'll know this is a comment if it's a different color than this anyway. So anything after the hashtag is a comment, and this is actually an in line comments. So anything after the hashtag on the same line is that hash tag is going to be a comment. So if he wrote something afterwards, like just random text text, see, as you can see, when I write the letters, it just it's white again. So that's on a common but one. Add another hashtag. It's going to be comment and then again, suit again. As you can see comment. And if we run, this code was to control be we're building in sublime text. As you can see, we're now working with comments and the hashtag anything behind the Hashtags are not seen at all. They're not interpreted by Python. So let's erase those. All right, so there to recap their one line only and any you there written as a hashtag and anything after the hash tag is a comment. Now. This won't work in the middle of a string, so let's see that. As you can see, it's in the middle of string. It's not different color, anything. Let's build that. As you can see, the hashtag is included in this string. So remember the hashtag must be kept out of sight of quotations in order to be a comment and they're in line so they only work a line for line. And that's it. That's all for this tutorial. See you next time 10. 09 Multiline comments: Hello, everyone now say going from LA The last tutorial with in line comments. Some of you may ask, where the where are the multiple line comments? Multi line comments? Well, in python there're in like this, so we're gonna use three quotation marks. So that's the quotation key. Double quote key without the shift. So basically apostrophes three apostrophes. So you go. So this opens the multi line comment, and we close it with another three quotation marks as conceit. E inside is a bunch of comments. So this opens three, opens them, and three quotation marks closes them. This is comparable to the slash star. You see characters in other programming languages. If you're familiar, so this would open and this would close. This is kind of the same as the same functionality. All right, so this could be used to maybe block out a piece of code that you don't a large piece of code that is that you don't want be to be compiled or interpreted my bad interpreted in python or you just like you want. Just write a long string of code of comments. So as you can see anything comments, let's write some text. All right, so, as you can see there mult alliance multiple lines. You don't need to have multiple hashtags like the last time. It's just everything between this is just comments. So let's build this. And as you can see, the comments are not interpreted. So that concludes this two tutorial. We hope to see you next time. 11. 10 Basic arithmetic: Okay, let's continue. So in this chapter we're going to talk about manipulating numbers and python. What this means is basically will be demonstrating basic mathematical operations characteristics of dividing numbers. And then we'll talk about advanced arithmetic and operator precedence. But we'll also be talking about manipulation of biter numbers later on. So let's start with basic arithmetic. So we're talking about addition, subtraction, multiplication and division, which are all simple and intuitive, and this in taxes pretty much similar to other programming languages. So let's start with what addition we're going to do print in order to see our results on the screen. So print two plus five, for example. So this result will be an integer because both operations are an integer. But if we add, for example, 2.2 will get 7.2 from this, as you can see. So if there's even one floating point number in the operation, then the result will be a floating point. C. I added 2.0. Here it will be. The result now will be 7.0 moving on to subtraction. So subtraction is going to have a similar thing. Similar similar event going down So let's do 10 minus five and we're going to build out its five. And if we had 10.0 two instead of 10 we So if you're gonna dry 10.0 minus five, that is we're gonna build, and we're to get 5.0 moving on to multiplication. This is the same case with multiplication Celeste to 40 times 30. We're going to get 1200. And if we do this times 0.5, we're going to get 600.0 because 0.5 is a floating point number. So let's talk about now of interesting specific thing to python that is called the Upper the Exponents operator, which is basically written as two stars. So let's write something else. So we're gonna write to Star Star five. This is basically two to the power of five, which is 32 and so in python. You can't write this with the carrot symbol. This won't work and said you should be using this will be. This is actually a binary operator which we'll see later on. Sorry, this is using binary logic ritual see later on. But what this cut is called in programming languages is a binary operator because it has two symbols in it. So star star. So as you can see, we will get 32. All right. And that concludes the tutorial on basic arithmetic. We hope to see you next time in our next tutorial. 12. 11 Division characteristics: moving on. Let's talk about division characteristics. So if many of you were wondering from the last tutorial, we didn't talk about division. Well, now we're gonna talk about it, so we're going to write an example. Division is written with the slash key print. Let's sue to divide by five to die before, for example, right does division. But as you can see here, we're doing with teachers. And if we build this, we'll get 0.5. So in this version of python, it automatically interprets it a 0.5. But if we do something like this, for example, lost to 23 plus two go on a sec, 23 divided by five. We should get we get 4.6. So in other older versions of python, we will see that this will return for pride six. Rather, it'll turn four. But in this version we're dealing with, it automatically doesn't for us. So this is division now, when so in this case, we don't have to do in order to get the full and in order to get the floating point, we don't have to at a floating point number anymore. So we got the same result. So in this version of Python, it does it automatically moving on. Let's talk about another by an air operator with two slashes What this is. It is the floor division operator. What this does means the upper the result of this division. We'll always be round and down. You'll get the floor value. So let's build this. As you can see, we got four. So we forced the values to be rounded down. So even if we do floating point number, you will get four instead of when we do without, with a single slash, we will get 4.6. Moving on. Let's talk about the module. Oh, operator, what this is is you divide and you get the remainder of the division. So let's give an example. Let's do five module. Oh, for what this will do, it will give us one because four goes into 25 6 times, which is 24 25 minus 24 equals one. So we get the answer one and module. Oh, the rial number having floating point numbers and everything applies here too. So if we did 25 module 04 we build Who will get 1.0. We'll get the result as a floating point number. Moving on. Let's talk about variables again. So when one of our previous tutorials are previous to two around variables, I mean we will be talk. We can actually save our results of mathematical operations. So let's have variable a equals two plus five. Let's have very will be equals 3.3 times. Three. Let's have C equal See equal 10.0 divided by 25. All right, so we have our say variables. So let's print these out. So we're in our I d. You know, so we can write the multiple lines of quote. Remember, Python does not use semicolons. It works byline. So let's have print was to a and less to built and we get seven, which is 2.5. So the results of the mathematical operation was saved to the variable. Analysts do the same for B. So we do print be. We get this result floating with the floating point number, unless to see and we get your 0.4. So that concludes. Our tutorial will help to see you next time 13. 12 Operator precedence: Let's talk about operator precedence. So in Python this kind of work similar to Pem Dassin, Rio mathematics so the the hierarchy goes order of precedence. The priority goes parentheses, exponents, multiplication, division, module. Oh, addition and subtraction. So let's demonstrate how some of these work well, just so you know in the late territory will be talking about parentheses later on and more complex arithmetic. So let's do some mathematical equations. So this falling mathematical equation let's to print in front of seats less to 25 times 15 plus 33 divided by 2.0. This is the same as having a equals 25 times 15 b equals 33 divided by 2.0 and then adding the two together. As you can see, the president's is 25 minus 50 times Myth 15 My bad 33 divided by 2.0 and then you add them . So this is basically a simple demonstration of some of the precedence in python. So let's build that as you can see it, what it did 25 times 15 33 divided by 2.0. When we got, uh, we go yielded a real not a real number. And then we're also going to demonstrate how this precedence is demonstrated in a A equals . This expression B equals that expression a plus B. So let's do that. A pause, a beat. We're gonna rude this line and then built. As you can see, we have the same result twice. So this basically the same presidents demonstration as this line of mathematics here and that couldn't go includes this tutorial. 14. 13 Complex arithmetic: So now let's talk about complex arithmetic. This will be done with basically the parentheses. So let's take the example from last time. But this time we're gonna add parentheses around a certain parts. So we're gonna have 25 times 15 plus 33 all divided by 2.0. That's what that means. Basically. So what? This is the same as this isn't the same as the previous to talk in the previous tutorials. Example What? This is basically so we're gonna said a equal to 25 times 15 apples, 3 33 Like as so, What you can see here is with parentheses. We take even higher presidents. So everything inside the parentheses is taken as one result while still abiding by precedence rules. So this because one result and then this is another result. So everything inside the parentheses is calculated first and then everything. The outside is calculated then, so this is the same. Well, let's write this out. We'll demonstrate this. This is not this will demonstrate that this is not the same as the in the previous tutorial . So we're gonna print that, and then we're gonna print a divided by B and we're gonna build. As you can see, we don't have the same result as last time. We have a different one. All right, So now let's say we have something even more complex like, let's let me just write this out. So we're gonna have 5.0 times opened more parentheses, As you see. Concede. We're going to use a lot of parentheses now to show how complex things can get. Minus two in parentheses, of course. Divided by four plus one, all divided by two. All right, so what we did here is that we are dividing everything with. We're actually doing operations with different kinds of mathematical formulas. So let's demonstrate this whole and I'm missing a parentheses somewhere. Just give me a sec. So that's the parentheses. So we do have one around or were missing an eight hoops. I have forgotten. Eight eight. There you go. So now we have a bunch of parentheses here. As you can see, there are very lots of Renzi's. I keep repeating myself here, So prophecies inside parentheses, inside parentheses are gonna take priority despite the mathematical operations involved. So let's do this. I forgot prostheses. All right, So this parentheses bunch is gonna be calculated, and this one is going to be calculated, And this result is that gonna be calculated? And then this enemy added to eight, and then this whole thing is anyone result multiplied with five and then divided with two. And then this whole result is going to be module. Oh, for we'll write this out, Don't worry. So we're gonna do a equals 16 minus 2.0. Then we're going to be equals four plus one, and then we're gonna have C, which equals a divided by B, and then we're gonna have d equals eight and that we're gonna have e equals d plus see? And then we're gonna have F which is equal to e divided by two. As I'm kind of skipping here. Something's I'm kind of mixing it up a little, but this is basically precedence how things go. What you could do for E instead is something like this. For example, um, eight, he is equal to eight posse, so in F is equal to e divided by two. And G is gonna be equal to 5.0 times e. I mean, f my bet and I made a mistake here I for about the equal sign. I forgot one here too. So C equals not plus cut my mistake. So G equals five times this whole thing. And then we have finally h which is equal to G module. 04 So, as you can see, the precedence is as follows A So you take the very inter parentheses and you do the operations regardless of the ones out of the operation outside. So let's print this out. So let's print the 1st 1 The first line of code sprinter. Don't forget to close your parentheses and open the proper ones. And then we're gonna print my bad print h. As you can see, we got the same result. So these letters demonstrate the precedence with parentheses and complex arithmetic. And this concludes our tutorial. We hope to see you next time 15. 14 Binary number manipulation: Now let's talk about binary numbers manipulation in this sort of manipulation. In this operation with binary numbers, we use bit wise operators, which will talk gold dive into right now. So let's type out the print statement like we always do to display our results print. And now, let's far first operate bit wise. Operator is the left shift, which is written as less than less than so. The first number on the left is our number to be shifted, and the number on the right after the operator is the amount of places the shift. So this number in binary, let's say, is Let's say we have five bits. We have one. It's gonna be shifted to the left three times. So one, too. So 123 Which gives us eight because this is to the power zero to to power one to the other two and to the power of three, which is a. And as you'll see on the screen below, you'll get eight moving on to the right shift operator. It's the same thing. Just it works the same way. Just it shifts to the right, so let's take two numbers are our number and question is very to remember this number is converted to binary. So we have 32 in binary shifted five places to the right. So we have six beds, let's say, And this is 32 with six a bit 1123456 Yep. And then we're gonna shifted to the right. So what this result is going to give is 12345 It's going to give one as you'll see in the build below. As you can see, we got one moving on to our other bit. Wise operators, the logical ones and or an ex Or first, let's talk about end and what it is, it takes two values and they're both are true. Then the result is true. So basically, if you have Onley either to ones on either side, then you get one as you'll see here. So we have these two numbers. Oops, my bad. I changing changed operandi. So on both sides. Now, these are both two numbers in binary, so let's right the mountain binary. We're not gonna build this right now. We're just gonna demonstrate how these numbers look like so one with nine zeros, I believe. 123456789 Yes, one with nine zeros. 123456789 And then we have zero with lots of one's trust, our one zeroth England's. So when we end this, if since none of these our 11 we're just gonna get zero. So you compare each one each pill bit place so 0101 and so on 10 all the way to the end and you get the and a result, which was yield zero because none of them are 11 So none of these are 11 They're all 10 or 00 or whatever. So as you see the result zero, which is just 10 zeros and you wait moving on, Let's talk about or or is it another logical operator? Where if one side is true, then the rest is all true. At least one side is true that ISS, so let's take our number from before take our number, but this time we're going to or it that's no Tater. With this line is shift and the American keyboards a shift backslash That's right, owner the backspace button. Usually, Um, now let's talk about or operating, operating with or so 10 is one. We have all 10 so that means we have one on every time. So our result will be 5 11 which is 511 which is basically all all these places are going to be a one now. So that's the result. Or right? Okay, moving on. Let's talk about X or X, or is kind of different between from end and or it's notated with carrot and what's to actually change the numbers this time to demonstrate a little better. So 60 exhorted with 13 what that's going to give us. Let's do them binary first. So we have 02 zeros for one's two zeros again, and then that's 60. This is 60 and then let's do 13 4 zeros, 11 to I mean to one's 01 All right, so here's our numbers in binary so X or what it does. The two sides must be different in order to yield one your true. And if they're not, do you have false, which is zero. All right, so 00 which is zero 00 which is zero 10 which is 110 which is 1112 wrote the same. So a zero 11 again. 000 You get zero again. And 01 you get one. And this number should be 49. We'll test it out right now. As you can see, we built it and we got 49. So that concludes this tutorial on bit wise operators. We hope to see you next time. 16. 15 Basic string manipulation: in this chapter, we'll talk about strings and how to manipulate them. We will go over some basic formatting options, and in the end we'll demonstrate one useful method that works with strings. So we're going to start off with basic string manipulation. If you remember that in the previous tutorials we have demonstrated how to define strings and had to assign a string to a variable. It looked like this. So we're gonna have a variable called string. Here we go. String See cleaners So that okay, so street straying equals and we use single quotes. I am a string in python. Another way of defining a string is doing the falling so you can also use double quotes and python. So in Python Dora's there is no difference here. So we're just going to copy this And there you go. So build that there's no problem. So they basically open. I should change the name of this. We're going to call this string one. Okay, so with strength and python, you can access a specific character in a string as fall in the falling way. So we're gonna say string and they're going to use the square brackets after the name of the variable, which is a string, and then type in an index, which is an R integer. This is called indexing. It starts from zero and goes up to the length of the entire string minus one. So to access a character, just specify the position or this index right here in the string to get the length of the string. We use the function Elian Len. So we use the land function, for example, we're going to say the following. So when my length is 15 so we can also pass a string variable to this function as follows. So instead of actually directly passing a string, we can just use this variables that, let's say, string this variable right here. Python also supports another way of indexing, which is not standard. For example, we have string in square brackets minus one. The result of this character is in which this is called inverse indexing, and it returns the last character of the string. So let's see over the side on the one. Here you go. So let's actually print out on, see what happens. So print you are a print function from before and be lips. That's not there. We go when we got in. And as you can see here, the last letter is. And so, for example, So by using this, if you wanted to get the second to last character, you would put minus two instead of minus one. So and then we got one. And we got the O from Python right here and you could do my his three and so on. So moving on. If you try to assign a character using indexing, he would get error. For example, let's do the following. So let's stews. So it's a string index minus one. So the last character it's going to be we wanted to be equal to X and let's build that. So what we get here is a type air str Object does not support item assignment. These types are called immutable types later on will demonstrate how to assign specific character if there is a need for it. So anyway, moving on. Another interesting thing about python is the so called string cutting. For example, we're going tohave Spellissy Race this, we can resolve the snow. We're going to have string Great! So string, we're gonna have string in square brackets five. Colon 11. This will return string, that is, It will return all characters that start with the fifth Index and end with the 11th index. So let's do that. So it's going to return this right here. This saw part of the whole string. So? So if we print that out, we're just gonna print this out. We get Oh, my A string of because a put a string pope. So if you say without the A, we'll get strength. There we go. If we don't specify the value of the first index, it is considered that it starts from the beginning and that is, goes to the second index and goes to the end of this index. So let's do that right now. So let's do blank Colon five and then we get I am. So we get everything up to the fifth Index that includes the space. So and if we do this for, let's say, let's say 15 at the beginning and the other side is blank, so we're going to get Python. So we went. We started to fifth Index 15th index my bed and then going all the way to the end. So we have something called cat concatenation in strings. It's basically adding strings, putting strings together and so we could do it. It's pretty simple in Python. So what we do, we're just going to say so let's make a new variable called String To and we're gonna come , Captain A into this. So we're going to say we're gonna add these two separate strings together, so we're gonna say calm and then we're gonna use a plus op around in strings. This is concoct Nation who will say Captain Nation concatenation. All right. And then when we print that, keep in mind, there's no space here. If you want to add a space through this operation, you have to do it manually. So if you do con space, but at a space But anyway, you get the idea. So let's do statement. As you could see, it gets added together. We also have something called repetition where you can actually repeat a string multiple times. So let's do it with this example. Now we're going to use to that we needs a star operandi with string. What this does it makes it repeats this string right here that this number of times so is going to repeat concatenation actually, because here, because it's kind of like operandi, So it repeated con twice and then kind of contamination once. So there you go. You can use pretty much like math off Iran's you can use thes two. So this using a two star repeats the string after the star number of a certain number of times based on this number. Anyway, keep in mind that you cannot use this syntax when content contaminating. Wait, No, sorry. So anyway, so I should move back to communication for a sec so you can community contaminated string without this plus right here. But you have to keep in mind that you cannot use the syntax when contaminating a string variable. So if we did this, we get the same results so we can caffeinated without the upper end. But if we say have con and we call this con should be one in, and then we have What's this called cat. We're gonna call it Katyn eight. We cannot have them contaminated without in operandi. If we're doing it over the variable Sophie right con cat, you'll get an error But if we do a con plus cat, you'll get the proper result. So you have to use the plus sign one dealing of the variable. This also works so you can if you have any where you have a variable, you have to use the plus science of a variable plus a string like without a variable. So con captain eight, Captain eight. This works, but without this, plus it won't work. All right, so now will demonstrate how to replace a character in the string. So let's start over. We can just leave that. Okay, so let's say declare new variable called word, and then we're gonna call it. We're gonna say Ford, and then we're going to say a word. So we're gonna sign the value, the falling value. So I'm going to say l plus word from the first index all the way to the end of the next one all the way to the end. What we did here is create a new string, which is contaminated version of a specified character and other unchanged characters. So what's gonna happen is gonna copy org. It's gonna come, captain l with o. R d So we're going to print, and then we're going to say a word and never get Lord. So those are basic. Those are the basic string manipulation techniques we have in Python, and that pretty much concludes this tutorial. 17. 16 Using the format method: So when working with strings, the format method is very useful. Here's some examples to demonstrate that. So we're gonna use the print function to display these statements directly. So print and we're gonna inside this point, we're going to see how this formatting method work. This format method works. So let me type out the fall example. So you may have seen this before in your programming life, career, whatever you call it. Um, in a string you're gonna have. You might have encountered curly braces with a number inside it. So we're going to say today had curly brace, zero curly brace, cups of curly place, one curly brace, of course. Yeah, so here the format. So what's gonna happen here after this string? We're going t to find We're gonna type it dot format dis method right here. So inside this we give certain parameters to be passed. That will replace these right here. So we this is something else is but to be expected here in this number, this is going to replace by three. And this one's going to replace by coffee. So let's build that. So I ask you see, instead of saying this it says I today I had three cups of coffee. So that's basically simple way of how format the four member that works. You could also use this method to assign values to the parameters in the string. So instead of using in like these index numbers, we can use actual variables. So let's say print and that we're going to say we're gonna have a list of prices. So let's say a list of prices, price prices, colon and more open some parentheses is just a string don't need for parentheses, Really? So we're gonna open curly braces for X open, curly braces, inclusive for why and likewise for Z. So we have three variables and then in the format method in the format method we're going to define, we're going to sign values to these variables, So X is going to be 2.0. Why is going to be 1.5 and then Z is going to be five and then when we know that you'll get the's valid, these variables replaces the actual numbers. Another thing you can do is have positional and keyword arguments together at once, so you can use you can use this positional and this keyword arguments, these variables right here are key or a tester called. So let's do that with another example. So we're gonna print inside that we're going to say the following. So is that why should open quotes The open. Our curly braces vehicle had curly races. Zero crashes in curly races one months. So, as you can see here, these keywords aren't sort of indexed with these the's positional arguments right here. So when we do that, we have to keep in mind that 00 position must go first. So we have five, which is going to go here, and we're going tohave six, which is going to go here. And then we're going to define vehicle so vehicle is equal to car, and then we build that everything gets filled in, as expected, moving on. You could all use this method to align the text in a certain manner. You can lie in it to the left or to the right. So the left assignment is going to be used is going to be enabled with the falling syntax. So we have in the string. We will keep this outside the string just for the syntax demonstration. So we have colon character, some sort of character, and then we're going to have left this left. This is the left alignment is the less than and then for right alignment. We're going to have a greater than symbol like that. So So in this, when defining the alignment, we have to specify the character, which will replace the empty spaces and the number of places that the string will occupy. If that number is smaller than the string length in the string will be printed out without alignment. So let's let's do this. Oh, so we have this in Texas and then we have dot format. I forgot to mention this. My amount, my apologies. And in the format we have actual string. So first we do. We define the alignment dot format, the actual string itself. So let's see. Race that and see how this actually works in action. So print and there were going to have and quotes Curly brace colon left alignment 20 and then so left Climate 20. And then we're gonna dot format and then inside format. We're going to just say example text and you see, it's left a line. So let's see the same thing with right aligned now. Okay, right away. That's and as you could see, it got this is left. And that's right. Alignment. Okay, moving on the format method is useful. One formatting binary hexi decimal octel numbers and so on So we can see this in the falling way. So let's see. Format print, actually, and then we're going to use a similar sin Texas before. But this time we're going to say colon X going be. This is for binary dot format and what we stream We want to modify great office inside the string. My bet. So we have that dot format and inside that we have 21 let's say and we get and error Oh, that's because I made it straining. My bed should be like that. There we go when we get the binary form of that. Sorry about that. And we have a similar syntax for Hexi decimal, which is notated with X so beat. It is for binary format excess for Hexi Decimal, and we get the Hexi decimal form of this integer. And then for Octel we use cold and who, using oh, instead and then we get the Octel for so with that, that pretty much conclusive is this tutorial 18. 17 Specific characters: to conclude this chapter on strings. Who will talk about some specific characters in strings such as quotations? For example, if you try to type something like this, so let's say we have in quotations we have, we have the contraction. I'm I strained in python post off to place on. So as you can see from the highlight, its in Texas, we don't get the result. Be one. So in order to Prince Singhal quotations like in a contraction like this, you need to put the entire string within double quotation marks. So that's the difference here between so and this will build without a problem. So if you are expecting a single quote like for apostrophe inside a strain, you should use the double quotes. And if you want to use the quotations, for example, you want to say python with quotes around it, you should use single quotes. So that's where really the key difference between single quotes and double quotes coming. So you should be aware that so let's change this to I am a saying. This quote works builds without a problem, and you know how that looks like so But if we want to use both quotation types. Then we would have to use the following. We have to use the back slash before the quotation in case of the backslash sign creates problems. We can put the character are before the string, for example. Well, actually, let me just just display the backslash first. So, uh, so I backslash quote, you can see it's highlighted here him a string and spice on and this builds without a problem. So this backslash actually it's called Escape. This is called escaping characters. So we use that backsliding on the character we want display that wouldn't otherwise be displayed in a string like this. So anyway, so in the case of the backslash sign, if you want actually use that, it creates problems. So, like I say, we put the are in the string, for example, print. So what? They are C colon decisions, an example number slash nan. And then we get the proper text from using this are also, if we wanted to find the output of a string ourselves, we can do so by putting the string inside triple quotations. So let's get rid of this. So there s a print and we're to say three quotes once. So three quotes. Let's have a backslash backslash and then we're gonna have some. So let's say hello, Colon. And I was going to say, user defined look python out, but press enter, and then we're gonna build that. And then in there you go. So with single quotes with triple quotes like this, you can define the actual output off the string itself. So that pretty much concludes this tragic chapter on strings. Thanks for watching. 19. 18 Logical operators and conditional statements: in this chapter, we will talk about loops in python to get a better understanding of how loops work well. First go through conditional statements in logical operators. We'll use thes when creating complex, conditional statements, and once we're done with that, we will be explaining and demonstrating three different ways of writing loops. In the end, we learn about the turn every operator, starting with logical operators and conditional statements. We have the following symbols that we use in conditional statements, less center equal to less than greater than less than or equal to. I made a mistake before part in, so we have less than greater than less turn equal to greater than or equal to not equal to an equal to. Now let's demonstrate some examples with these symbol with our with ease conditions, conditional conditions. So let's print out. Five is last stand six. This is going to return true. So with conditional statements, we have Boolean values. We have false or true or a zero. So we have false 60 and true is one or any other number that is not zero. So as you can see, five less than six return True which is a bullion value 10 greater than 11 which is false. What's to look to equal to, To which is true, then we have moving on to greater than or equal to. I will say to is great angle to three, which is false. What's to less than two, less than or equal to three is true, then we have not equal to so let's to four not equal to two. They want to change it up a little. Which is true because for is not equal to equal to one. We can also use strings in this case. So let's say ABC equals ABC. As you can see, it returns true because these strings are of the same length and have the same number of characters and keep in mind, we can also use variables in conditional statements moving on. Let's talk about logical operators. We have the following not and and Or and as you can see, I wrote them in operator precedence. So not has the highest priority then and has the second highest priority and or has the lowest priority. And let's illustrate now, with some, let's illustrate some examples with these we just what we just said this time we'll use variables. So let's say a are variable, A equals true variable B equals false and we're gonna print not a So This is not true. Not literally. Not true. So a is true. So not a is true. Let's do something with. And now so A and B Brooks on a A and B is false because with an logic, true and false yields false unless to something with false and false, which is false and do true and true, which yields true. Now let's do or so true or true is true. True or false yields, false in or logic and false or false yields false in or a logic moving on? Well, we can talk about now using parentheses in order to make more complex statements so we can change the order of precedence in a conditional statement. So let's start off by making some variables declaring some variables. Pardon. So let's say five D is five equals one f equals false, which were having a couple mix right here. As you can see, f g equals Hi sahn. Age equals some like words, the words some industry and for to make our job easier. Let's have another variable was called Z, which is going to have our complex statement inside it. All right, so let's type it out. So we're gonna start off. We're make something quite complex here, which we don't recommend. It's not recommended actually to write such conflict statements, cause you'll wind up getting confused in the end, your programs. So just keep if you're going to use complex statements, be sure you know what you're doing because there's with the more complex A statement is, the more room there is for errors. All right, so let's do this. Sell us to e less center, equal to D inside this not statement. Then we have, and we're gonna have g greater than equal to age. And then we have we're gonna keep that closed, and then we have four f. As you can see there, variables are being used here, and on the other side we have one. So we have a large ands and operation going on here with one side with one, which, as we said before, is true. And it's always true. And on the other side, we have this big, complicated statement, So let's break this statement down, we're gonna start. Since we have privacies, we have the order up order of operator precedence. So let's see. We'll start with this, not statement right here. So we have not e lesson equal to D. This means so not one less than or equal to five. So this statement is true and then we use not, which means we we get false. So we're how false and whatever this is which we're going to say right now, so d greater than or equal to h So sorry, g greater than equal to H G is a longer string than H. So we get true here. So we have true, it's part of false and true which yields false. And then on the other side of this or statement, we have f which is false. So we have false or a false which yields falls in this hole in this whole parentheses section. And then we not that which we get true, so not false is true. And then we have this whole side is true. And then we have this one which, as I said before, keep repeating his truth. So we're gonna print out our results are variable As you see you, we get one which is true and that concludes this section We hope you tune in next time. 20. 19 if statement: Now, let's talk about if statements if statements are used together with conditions to determine which part of the code will be executed next. If the evaluated condition is true, think of this as a sort of conversation between two people. So let's make a variable called passer by speech, just like in a normal conversation, we're gonna set this equal to Hello. And now we're gonna check this. Oops. I made a typo with the G. Excuse me. All right, so let's make our if statement. So we're start with writing. If then we're gonna write are variable. As you can see in sublime text, we have auto fill, which is which is a miracle. Kind of makes her life a lot easier. One programming in sublime text brining programs. Excuse me. So if passer by speech equals hello, which it does or organ says you you can see the or and the a logical operator in our conditional operator used before. So are using these if statements. All right, so hello. If passer by speech equals hello or if passer by speech equals high As you can see, they're both to greetings. We're gonna The result is going to be print. Hi. How are you? All right. So basically, this is illustrating a normal greeting. So if someone says hi to you, you will. Depending on who you are, you just say hi back. And how are you? So let's build this. As you can see, there is a syntax area here. So let me just check my syntax. I believe it is the indentation. Oh, no. As you can see here, this is a common mistake. Sometimes with programmers what they do, you have to make a double equal sign and not just a single one, because in if statements, this is actual condition. So be sure to memorize that. And this is in a declaration of a variable and setting a equal to a value. So just remember, in if statements and conditions use the double equal sign All right, so let's build it. And there's a high, which is something. Oh, in python. We also have to add a colon in the if statement. I forgot to add that. Call him before, So let's build it now. As you can see, since pastor by speech equals hello, which which yields true in this if statement we get? Hi, How are you? So anything within the if statement is processed when the result of this condition is true ? All right, moving on. So, as you can see, we'll just Let's just write our condition, state our if statement formula, sort off. So we have if we have a condition and then we have to in Dent, Remember, indentation in python is very important. So anything indented. Oh, and of course, again, I forgot the colon. So we have condition. Let's say statement colon than anything ever. That indented is within the if statement when that condition is true. So we have some code here. Let's just write some comments code and we just have some pseudo code like print and so on . So this is just how our if statement works. So he right. If our condition than colon and then after that we use we use indentation, Teoh sort of contain whatever we process what to interpret Whatever code is to be executed when we have the condition equal to true. So to recap, just remember that invitation. And if statements like in most of python is very important, so, like this, let's write something if just some pseudo code. If true Colon and we didn't intend print test. This is not the right way to write an if statement. So we're gonna need indentation here. And that is all for this tutorial. We hope you tune in next time. 21. 20 if else statement: cycling from our previous tutorial with, if statements, we're gonna talk about the else statement now. So, as I said before in the previous tutorial, the code within the if statement is executed. If the condition is true, if this statement here is true now, if it's false, we have the else statement. So let's right that else it's written like this else Colon and your code indented, as in the if statement, let's say if it's not equal to hello or hi, we're going to say some sort of like Curt reply with Hey, all right. So I changed the passer by speech to say nothing. So obviously it's not hello or hi anymore, and it's going to be this condition is going to be false. So let's build this. And as you see, we got hey, so as you can see else, any code within the else statement is printed out, which means the conditional is false all right. And, as with the if statement indentation applies to the else statement. So let's make let's make some some new state if statements right here. So I delete everything here. All right, let's have let's say we have if five, less than seven throughout the shift. Five less than seven We're gonna in den here, we've got the colon. If in den. If again, let's say five greater than six. There were in debt again. Remember, in Python we have to in Dent for each new statement. So this ifs This print I'm going to print out right now I'm going to type right now is applies to the second if statement. So let's say we're gonna right five greater than six. And let's build that. And as you could see, nothing was printed out because the indentation we see here has no other conditions, and it Noel statements. So first it checks this, which is true, and since that's true, it checks this statement, which is false, and so there is no false, like nothing to do when it's false. So it's has left blank and there's no result printed. So, in orderto use a false use, have a statement. When it's false, we use else. So let's see a road else like this, and when and when it's when this condition is not true. We want print five less than or equal to six, and we're gonna build this nice. You can see we got the same result as before. That's because we didn't indented l saving properly. So we have tohave if an l statements with matching indentations. So let's do that right now. So let's invent this else to be paired up with this second if statement and we do this here in den properly, As you can see, it looks orderly and you can as a logical flow. So let's build this now. And as you can see, it printed this second line of code. It printed the second statement. As you can see here, that's because we indented properly moving on. We can also do this in a block code. We can have several hell statements. So let's say we have this whole thing right here. If else and then we have on the outside of that, it's just an example. You could do this with variables. You could do this with the larger, more complex conditions, and so on will say we have else here and we're going to say I don't know, cringe. Not true. This is just an example for the sake of the example. So let's change this to five greater than seven now, and let's build that. So, as you can see, the indentation matches the indentation of the if statement matches the indentation of the else statement, as you can see here. So as you can see, that pretty much concludes this tutorial Tune in next time. 22. 21 ifelif statement: All right, let's use our conversation example from our previous tutorials. So we have the passer by speech. This time I modified it a little, So it's equal toe high and we have the previous if an l statements from before. But we just modified a bit. So this time, if passer by speech equals Hello, so for saying hello, we print out high and if he doesn't say alot, we'll just give a reply. Hey, like sort of casual, All right, But here in this case, it's neither one. It's not. Hello. It's not gonna be hello. But we have another condition. We want to make another condition because we actually said something. So in this case, we're going to use what's called, LF the LF statement which is basically it's used when we have a condition that didn't pass , so it was falls, but we want to check for another condition. So in this case, we have passer by speech equals Hi. So as I put before it says hi and we're checking for this condition. All right. Hi. And when it says hi, we print Hello. I didn't want to sound like a parent, so we say Hello. All right. And this is pretty much how it works. We have if checks for if pastor vice speech equals hello. Since it's not, it goes on to the else the LF statement which is high. And that checks out. So it's gonna print hello. For some reason, it's I don't know why it is giving me as syntax error. Just give me a sec. I'm forgetting. Hi. Hello. Oh, I made a colon here. See? There you go. So, as you can see, it printed out Hello. Because the else if the LF statement checked out So from this example, we can see this falling struck short of structure. Of how if, in l f are used together. So you have If with this just a pseudo code. So don't mind that it's not real code that will be built. So it's a condition, condition, and then we have under that some code. Then we have If LF my bad elliff condition let's escape condition too. Let's call that condition one some code then LF condition three and some code and then finally R l statement. Keep in mind that we're also using indentations here to match which pieces of Kogo. With which conditions, All right, else code. It is important to know here with okay with these that else if statements should be mutually exclusive, which means that Onley one condition should evaluate the true within within this block. So if we have, for example, let's do another example here, let's erase all this. So we're gonna have a variable called Numb equals three and then we're gonna if enter if numb greater than one and numb less than five. We print no. And then it will have l l f statement. Elliff hope for at the Colon. Don't forget your Coghlan's in your conditions now, if numb greater than two and, um, less than four. Colon and statement lists a print no, plus one. Then we finally have our l statement, which is just else, and we print no, um, minus one. So let's build this. As you can see, we have three. It will never be numb plus one, even though this condition is actually true, because the condition before it is true. So it immediately goes to it, immediately finishes this condition and prints out our results. This just illustrates how else LF statements should be mutually exclusive, so this should be some sort of other statement. Instead, that should be kind of fixed around adjusted, so they're not true. At the same time. Another poor note is with if LF statements is that, you can also have necessity of statements as we've seen before. However, it's kind of sort of not recommended because things could get complicated. But you can use this by your own at your own risk, into your own disposal. It's all up to you. So that concludes this tutorial. We hope to see you next time. 23. 22 ternary operator: to conclude this chapter, we're going to talk about the turn Eri operator. This operator is used when there is a decision to be made when assigning a value or to a variable. For example, we have passer by speech from our previous tutorials set to hello and then we're gonna have our response. That's a called me equals high. If so, we're writing the conditions in line along with the value. If passer by speech equals Hello, don't forget the double equal sign Hello or passer by beach equals high else. Hey, so what we did here? We're going to set this variable me toe high. If passer by speech is equal to hello or if it's equal to high, otherwise said it, too. Hey, so let's break this out. So we're going to just do a simple print statement of meat, and when we build it, I forgot the equal sign again. Don't forget the equal sign. It says hi, and if we wrote for example, it's close. If it's nothing, then we'll get Hey, so it kind of works as if conditions statements, but in line along with the value. So this can also be done with numbers another variable. So let's do a equals three a equals. And then after that, we said a equal to seven. If two to the power of three. Our sorry three to the power of to that's better is greater than nine else. Otherwise we get equals 14 and then we're gonna print a out. So in this case, a is going to be 14 because to the power 332 power to is not greater than nine, in fact, is just equal to nine. So we get 14. So if we changes to, for example, three to the power of three, which is true, will get seven. So we basically reassigned A's value using the Turn Eri operator. So to recap, Turning Operator is basically having signing a value to a variable you and using conditional statements like if and Ellison inside in line with the value itself in order to set it to a different value. And that concludes this chapter to the next time for our next tutorial. 24. 23 For loop part 1: in this chapter, we'll be talking about loops and python. So what? Loops are basically blocks of code that are executed a number of times so far. I mean, rather we'll be talking about four loops and while loops, and in the end we'll be talking about break and continue statements. First, let's define what we're going to be seeing in four loops called Range. The Range Function. What this is is basically it defines sort of range of a loop T to iterated through, so our prototype of range looks like this range start, stop and step. So Start is to stop, start and stop. Are there basically the rain, the actual range itself? And remember, it's inclusive. So if we had range one 25 it's going to include one and go all the way to four, which I'll demonstrate later on. That step is the amount of increments to take in each iteration. So, for example, if we have 1 to 5 and the step is to, it'll go from 13 and then it will stop because four doesn't really it's not. It doesn't reach that number in two steps or let's do actual better. One let's say 0 to 4 with iteration of to it, go zero to and then eventually four. So let's actually demonstrate that how this works. So it'll you'll see better. You'll see a better in a federation. Actual illustration. So as you can see in sublime text, it actually did it for me by auto filling. Let's say this is I and we'll just erase all this garbage. How about we do range from 1 to 10 and then we're gonna print? I don't forget your colon after the four Loop statement. This is what it looks like basically. So we have four. Any letter variable I like to use. I like in most programming languages we use I use in the in keyword And then here's our range function. And then here's our actual range of numbers. All right, so let's print. I will build this now, as you can see below. Let me just go up. You can see here 12 all the way to nine. And as you can see, it is inclusive. So includes one, but it finish at end minus one so we can say the ranges from from the beginning to end minus one, as you can see here. So our stopping point was 10. But here are we actually see it's nine, so that's n minus one. So what's at a step to this? Let's say, two. It's gonna increment in numbers of two. So let's build that. And as you can see, it goes 13579 in increments of two. And let's actually so that's basically it for that. And let's just do another example with other numbers, let's say 0 to 12 with increments of three. Just so you can you just get the point of this whole to get the gist of this whole how four loops so as you can see in increments of 310369 and since remember, it's inclusive, so the final number is not included itself because that's how these work. Now, if we did, for example, 13 here, you would get 12. So in four loops in the range, keep in mind that if you actually want this final stop stop number, be sure to do a number one number above it. As you see in other programming languages like we use. Traditionally, we use in like anti, for example. Whatever. And then it's, for example, up to 10. That's like this. Basically what we did this is equivalent to this. Let's a step one. You actually have to include the one. This default is one, and then we just have I plus Plus, this is basically how it's done in other programming languages. And this is how it's above, is how it's done. And python. So this is this. What I wrote down here is basically this up here. And if you want actually sorry, this should be 10. If you want actually to go up to 10. You do this when I forgot zero. Here. It just This is just illustrating how it will works. You do less than or equal to 10. And so you have this. This is basically this and that pretty much concludes our tutorial on four loops. Please, student. Next time 25. 24 For loop part 2: So let's continue talking about loops in this tutorial. We're just going to show some more advanced examples and then the next one in the next one we'll, ah, apply what we learned. So let's say we have this string given here. It's a string diverse away. We are going to iterated through this using a loop. So here we have. I just I type this ahead of times just to save some time. So here we have a normal four loop with the range function, as we saw before, and this time our range is actually going to be the length of the string. What we use is the length blank function, which is just l e n the Len and inside the argument here is the actual string itself, which we called string. And then we're gonna print string with square brackets and I so kind of like it looks kind of like an array, since the string is an array of characters. So let's build that. And as you can see, it looped and printed out the actual string. So keeping this kind of method in mind, we also have another way of doing this using characters for the loop iterations instead of using range instead of using the actual range function. So let's do that. Let's you raise this whole thing. We're gonna make a new four. Loop was so four. I actually for char in string. So we're saying now loop through the characters in the string and then we're gonna print shar and I have to build that. And as you can see, you got the same result. This is a simpler way of writing what we just had before instead of writing. Let me just do all this instead of writing this. So you have this cleanup cleaned up neat explanatory for loop instead of what we had before , which is kind of complicated, but it's all up to you to choose what you're going to use. You can also do what Another thing we have in four loops is you can have nested for loops. So let's write an example out. So let's say we have four I and range three. As you can see, this writing of loops is more simple than is simpler than in other programming languages. Because I thon works with indentation and colon and Coghlan's like in the statements. So let's do it. I forgot the end. All right, So for J arranged to hopes for range tube and then we're gonna print so in sublime texted automatically intends for you. Be sure to keep your Indians. Be sure to keep your lines of code indented where needed. All right, let's build that. As you can see, this is our results. All right? So next time we're gonna actually apply all the stuff everything that we learned in a sort of bigger examples, so you can see kind of how four loops can be used in real life applications, and we hope to see you next time. 26. 25 For loop part 3: So now we're gonna actually apply everything we learned from four loops to a real life application. In this example, we're gonna we're gonna print out a 10 by 10 multiplication table. So let's start off by making our first main four loop. So we're going to four in I in range. We want a range of 10 Azzan, the 10 by 10 table. So we're gonna do 1 to 11. Remember? Stop Point is and minus one. So 11 minus one is 10. That we don't have that colon in Dent print. I'll explain in a moment what this is. I'm just going to write it out first, curly breeze. Cool. Well, actually, quote less than three curly brace, and then we're gonna have a line in their separator. All right? And then we're gonna have docked format. Hi. All right. So what? This did what I'm gonna do? What we're gonna do here, actually is this is gonna print out from 1 to 10 for our, like, indication of the first rope. What? This does right here. It it aligns three places to the left, and we need to make this display on one line. So first, let me Put this out. As you can see here, print kind of makes a new line after each iteration of printing. So we need to do is make everything in line what we're gonna do, at least in pipe version Python three. We need to do this. This is how I do it. I'm sure there are multiple ways to do it just right after after this format function, we do comma and then end equals blank strength. So let's build that in print. As you can see, we have ah, whole everything is printed in line and you'll see as we move on, you know, you'll start seeing the actual table itself. So moving on, let's make our nested loop. Now we're making the rows and columns. Now with this with this new for loop inside the nest, the nest loop I mean, so this is always gonna be a range of 10 because we are also, we're doing a 10 by 10 table, so 1 to 11 Samos before colon and then we're gonna print were to do a similar thing as before. But this time we're gonna have alignment with four places to the right. So let's write that out. So open your quotes. Begin your curly braces, colon greater than four, and then close it again. Call your curly braces and then outside the quote dot format. And then we're gonna do high times J in space it out to make it more neat. You don't have to, though. And then again, once again, we need everything in line, so end equals empty string. And let's print that out. As you can see, we have a sort of we're starting to see the table. It's not space correctly in, aligned properly on its non aligned properly. So we're just gonna were gonna fix that right now. So on the next line after that print, we need an if statement aligned with the nested for loops so indented with same level as the four loop. As you can see here, we'll spend another space so it looks more readable. All right, if I equals one, this piece that out. One colon, we're gonna print something else out. What we're gonna print, you'll see in a second. So print. Let's see New line Open your curly brace Colon. Hashtag. Now, in my case, it's gonna be 44 here, but depending on your window size, it could be different. But you'll see it. You'll see how this looks at the end docked. So we have print whips dot format and then we're gonna have open are format function with empty. It's gonna be empty and don't forget and at the end, because we want it all in line once again. All right, So what this did it prints 44 hashtags and it aligns them to the center and occupies this many spaces, All right. And then after this was print that out and there's error here because I'm not done yet. Just hold on one second. Let me just finish the soft with print. Open your quotes. So let's just review our code right here. Oh, and of course, I believe I forgot something. Hold on one second. I forgot. Oh, that's right. I forgot the carrot symbol with inside this. So be sure to write it like this. We'll explain later in future tutorials how this works. So as you can see here, we finally got our table. Those hashtag filled up 44 spaces on my on my screen. It's 44 on your screen and may be different depending on your window size. So as you can see here we have the one row and and then all the way to 10 and we have 10 by 10 and so that pretty much solves that example, and that's pretty much it. 27. 26 while loop: All right, We're gonna talk about while loops now. So what a while Loop is unlike a for loop is used. It's used when we have a repeating block of code in cases where we usually don't know the exact number of repetitions and the repetitions stop when the US Aaron condition is fulfilled. So let's say let's write some sample code help. So we're gonna have here Variable called condition equals 10 right? And then we're gonna write while condition not equal to zero. So regardless of the value condition were just iterating We're repeating a block of code when condition is not zero and we're gonna print Don't forget your Coghlan's and then print condition. And then afterwards we're gonna iterated condition equals condition minus one. So let's print that out. So what this did basically, is print condition counting down from 10 toe one, and then when it reached zero, it stops completely. So without knowing in advance the amount of it orations to take We we subtracted one from 10 from condition. So we did. 10 987654321 and so and then to the end to zero and 10 it stopped. And what, while could be used for, is used for infinite looping. So let's do this. Let's do while remove that while true and what this is going to do print infinite, infinite Andy Spahn. All right, And we're gonna print this out. And as you see, it keeps on going forever. So while committee use for making infinite loops, it's used very often in practice. But how would you exactly stop this? This is it stopped by the break statement which will be talking about next time. 28. 27 Break and continue statements: to conclude this chapter, we're going to discuss the brake and the continue statements. First, let's start off with break. Okay, so what break is going to do it is used for. We want to stop an execution of a loop. So from the previous tutorial, we have this infinite loop or a printed if in an infinite, an infinite amount of times. And when we use break, for example, let's right now break and then we're gonna print. As you can see, it only printed out once. So after printing, it broke the loop and it finished and only printed infinite once. And that's pretty much how Break works. So if you want to stop a loop, just use break like you have a condition, another condition within the while loop. And after that condition, it breaks. So let's talk about continue now, so it's gonna erase that. And if you want to skip a certain step in the execution of a loop we use, continue this command What it does. It skips all the commands that come after continue all the way to the end of the loop. So let's write. This is and it's used often. Four loops. So let's write for it. Kind of filled it already when you press tab in sublime text. But let's just don't worry about that. Was just right out what we need. So we're gonna do 1 to 11 and then we're gonna have If I equals five Colon, we're going to do continue. So what? This does its gifts printed in or course at the end? We're not print. What this is going to do is it's going to skip where I equals five. So let's do that. Let's print that. Let's build that and we'll see our results. As you can see, there's No five here because when we use, continue on the condition. If I five excuse me, we don't print it out. We just skip it. And so that's pretty much a break and continue. That's pretty much it. We hope to see you next time 29. 28 Defining and calling functions and returning values: Welcome back in this chapter will be talking about functions in Python. We'll be learning where to use functions, how to define them and how to pass parameters. And we also conclude this chapter with the Lambda Functions To start off, we're gonna talk about something which is called decomposition. So what that is is basically segmenting the code into smaller parts, mostly for easier reading and maintenance. And we'll basically be using this for functions which are portions of code that are set out to do a certain task. Take retort to return a certain result. So let's start off by defining our first function right here. So let's go here. And so in python, we start of with death, which is sort of a built in kind of function, as you saw here deaf. And then we're gonna have a name of a function. Let's just call it function for now in sublime text. You know, you did it right. But when you have different color text for the name of the function and then you add parentheses and then you have a colon and then it's in you in Dent, and then you add whatever code this function is supposed to carry out which, like what portion of the tasks this function is going to do. So, for example, this is going to print. This is our first function. Okay, so this function is it's sort of code within the code. So it's a portion of the full program that does. Just printing this out, printing out this statement. So let's. And now we can call this function So we called by B. If you're familiar other programming languages later on, we can reuse this this function by calling in the falling way. So you, your type the name of the function in sublime text we have auto fill, so we're gonna function parentheses, and that's pretty much it. And then when we build this, as you can see, we have a pre defined function, and then we call it and that code is read by the interpreter and it you see your results here. So what we also have with functions is returning results. This is another service purpose of functions and what this does, instead of having basically a fun this print inside the function, we actually have a return value, which is another purpose of function to give a return value of some sort of code. That's to be carried out t that is to be read and interpreted. So let's let's do this. Um, let's define our function deaf and the name of this function. Let's say it's cold. I don't know, return returning parentheses and then colon. And then inside that we're gonna have return a string, for example. And let's say I am a result. Okay, so in this case, since we have return, it won't pronounce this super turns of value. But you have to print it out manually. So let's do this. So we have print and inside that we're gonna have returning. As you can see it, auto fills for us. So returning over, get your parentheses. So, as you can see here returning, and there you go and a good habit toe have one. Programming is that you store the result. You store return functions with the return value to a variable of some sort. So let's say we have a variable called Result equals two and work on a call returning with parentheses. Don't forget, and then we print it out. We print out the variable result. As you can see, it's the same thing. But this time it looks more orderly and clean set of having it the way we had it before, which is like from function within a function with, like, a double horrendous, he said. That's kind of confusing. So as like this, it's pretty clean and moving on. We also have, and it's something interesting in Python, which is we can return multiple values. So let's make another function so deaf and we're gonna say Multi, we're gonna call this one. I don't multi. Let's say multi Val, open up on the seas colon and then we're going to say so. Return. Oops, return. And then let's say we have us to values a string called this. This is a result and then two separate them. We have a comma, let me add to fix the string. We have comma and it's separated by another value, the other value. So as you can see here we have two values and they're separated by the comma and notice that this function is printed out in parentheses, which you're going to see right now. So let's do this. We're just gonna do it the messy way. So let's do print, multi vow and thats print buildup. As you can see, it's sort of here's our first return value and here's our second. And so that's it. Just This is how they're separated and then later we'll we'll learn how Teoh actually extract these values. And that pretty much concludes our introduction to functions. Please tune in next time. 30. 29 Passing arguments default parameters scope and nested functions: all right. Moving on from Teoh. Sort of piggyback off of our last tutorial. We're gonna talk about parameters within functions. So we learned that, Ah, how to define the function and call it and return a value from the function. So what we're gonna do now is pass an argument to a function so that we can perform a certain manipulation on that argument or parameter, as it's called here. So let's write our first example defined function called parameters. And in this in this function, we're gonna have our first parameter. It's gutless this. Call it a right, and then we're just going to print a print. Okay, so and then when we call the function so it's called parameters, we need to define a So let's say a, for example, is a strand called This is a parameter. As you can see, this string was passed into the function and manipulated somehow, and in this case, it was manipulated through print. All right, so we can also pass more than one argument and less user. Let's make a new function. Now, let's just erase this. Defined it as ad, for example, and where they were gonna have to functions called A and B. I mean seek. Use me to parameters inside the function called a and B little tongue tie, say so lets you see equals a plus a for us and be and then we're going to return, see? And so one we want to. So this timeless Let's do the right way the proper way and say we have a result. Variable result equals ad and don't forget we need to new parameters now. So let's say 12. And to separate them we do comma and then five. So a sickle to 12 and B is equal to five. And then so we have that result, and then we're going to print this result. Print result. Let's build that. Oops, I made a mistake here. Oh, I forgot the colon again. Of course. Silly me. Don't forget those Coghlan's. So, of course 17. We can also do this with strings, so let's do that. Instead of having numbers, let's have one, and then this be a is one and B is word, and then that sort of adds them together in one string, and that pretty much concludes that part and let's move on to the next part. So this part is for default variables. Default parameters. Excuse me? What these are are basically the default values of a parameter defined in a function if they if that variable that parameter is not manipulated. So let's called default Param. That's our function. And then we have the parameters a the see, and it's going it be written in the falling way. So in this in these parentheses were our default parameter with our perimeter is you write b equals our default value for and C equals our default value. Five This is just an example. So it could be anything whatever to whatever your hearts content, sort of All right, So keep in mind that parameters with the default values should be put last. So as you can see here a we wouldn't have liked be before a and and so on stuff like that. So here we go. So we have our default values defined. So let's continue and then we're gonna have return a plus B plus c. That's X C. All right. So let's see. Let's ah, both stories to results again. And then we're gonna do default, Paramjit And let's say A is equal to three. And as you see here, we're not going to define these with commas and then a value. So let's do that. Build hope, forgot the print, whips my bed print and then results. As you can see, it added three plus four plus five, which is 12. So the default parameters were passed into the function and which is printed out. And so keep in mind here, as you can see, um, functions in Python Pass by value. So and we also talking later about passing my reference, which is for complicate but will be done later. But in general, functions pass by default by value, so literally we took four and we passed it all right. Moving on. Let's talk about scope. Scope is sort of is like the range of use of, ah, parameter inside of function. So within a function, the scope of a parameter is within the function itself. So, for example, let's have a new function here called Scope. So scope Call with a perimeter A and let's say equals April's one is just some examples, so don't worry about specifics. So print, we're gonna print a lower case a and then return. Hey, so, scope, then we're gonna call scope, and then a is equal to five. As you can see, it did it did everything for us. Now, if we wanted to call a, we wouldn't be able to call a outside this because A is only defined inside the function. So let's say if we try to print out print Hey, where's my caps? Lock on. Hey, as you can see it, it gives us an error. A is not the find. So remember, in parameters in the function our only within the scope of the function and now moving on. Speaking of scope, actually, um, we have something we can use nested functions like we had nested loops before, like a loop within a loop. We also have functions within functions, and the scope of these functions of nested functions are only within the function that's outside. So let's define a new function called outer outer with the perimeter a again colon and the inside that function, we're gonna define another function called nested, and that's gonna have its own parameter B. And then we're gonna define as return B equals a, and then to keep in line with the indentation. We have, um, this the actual code in the first outer function. So a is gonna call nested in return value with with the parameter a and then it's gonna return a. Now this looks kind of confusing, but basically the thing to see here is just necid can only be used with an outer and an outer utilizes nested as a part of its code. So let's do this. Let's let's print this out. So print outer with number? I don't know. Four. Let's say print and I forgot something. Hold on a sec. I forgot to semi colon. So here we have to use with nested loops. You're gonna have to use semi colons. So let's make that clean and just give me one second. Oh, my bad. I made a mistake. I'm red. Wrong is supposed to be multiplies. All right, so 16 So, as you can see four times four is 16. So, as you can see here of outer used the function necessary which took argument for a and it was for which be was also for, So as you can see it, it did everything as it should have should have done. All right, So the whole concept of Necid functions can be used for aggregating more functions as a result and get with another function as well. So this could mean this might be a little complicated. So let me just I think, yeah, let's do it now was just get it over with. So let's say we have a function called F and with the parameter A and they were gonna have inside that called a function called G, and it's gonna have so kind of a similar situation as before. Okay, so what we're gonna do now, we're gonna define both parameters by in the falling way. So let's first make her function again. Return a times B. So don't forget your semi colon if you're using a function within a function. So actually here she might be an Arab whole lot. Well, we'll see in a second return, G. All right, so let's actually remove that. Maybe that was a typo. Um, so we're gonna print now, So we're gonna call of function, the main function, our function, and then we're gonna have to arguments in parentheses, so to parentheses, groups of parentheses after the other. So first argument A is five and the 2nd 1 is too. So was billed this. As you can see, we got 10. So it took We actually made our new the second argument the nest in the nested function we do if we defined Excuse me. So we defined it and thats be done in the falling way. So we have the first function, the outer function and then the nest function can be defined like this. And you can also do this again. Aggregation. So let's add another function here inside F So we're going to inside a G. Actually. Excuse me, we're gonna have define So we're having a loop within a loop within a loop. So it's kind of like glue perception right here. So h c and then we're gonna have just a semi colon, and then we're gonna have After that, we're gonna have returned return a times B times, See? And as you can see here we have that. So we're going to Then after that, we're going to return h and then outside of that, we're gonna return G. So we have three arguments now and you just add the process is on us. Do that. As you can see, we got five times. Two times 30. So I pretty much concludes this section to the next time. 31. 30 Recursive functions: alright, continuing with functions. We're gonna talk about recursive functions now. So what these air known for their note for their top down approach to problem solving recursive functions basically break down a problem into more sub problems and then solve them? So what recursive basically means is is I Is that a function calling itself so it uses itself over and over again. And what we need in these is a base case and a recursive call, and I'm going Teoh Right now I'm going to just define a function of recursive function so you can actually see how this it works. So what's let's do this so deaf? We're gonna is gonna be for factorial. So this will demonstrate how to calculate a factorial with the help of recursive with a recursive function. So let's say we have our argument or parameter called n. And first we need the base case, which is if and equals minus I mean one thing. We return value one which helps us exit the Rikers in going on return. One else we're gonna do return return and equals factorial. Oh, and wait, there shouldn't be equal sign there. That was my mistake. and times factorial and minus one. So, as you can see based on this code, if and isn't one is going to do this returns damit multiple times, so it's gonna do end times factor function itself over and over again. So this basically divides the calculations into some problems. So let's actually demonstrate this right now. So let's call our function. So let's say print factorial. Let's say we're gonna do the factorial of I don't know. Let's give us the number Let's say the factorial of five and then we're gonna build that and I made a mistake. I should've wrote. Let me just see here about the colon again. And, as you can see 120 which is correct. So as you can see here, basically, it's just does what it says the factorial does. One times it goes from 12 times to actually goes from 5432 and all the way toe one which and finishes. So it does five times four times three times one. That's basically how factorial is work, as you probably already know. So let's actually look at other kinds of. There's actually a couple times of Rikers in we have regular Rikers in, and we also have tail Rikers in. So let's first demonstrate regular rickerson. So deaf some. This function is called some now with the parameter and with colon, of course. All right, so if and equals one, we're going to as before return one and then else let's see, we're going to do like before in the factorial problem. Turn and waas some and minus one. So we're doing. For example, if it was five, we do five plus four plus three plus two plus one. And this is basically regular occurs in and tail conversion, for example, we're gonna do tail some now tail underscores some parameter. What? This does your in a seeing the fault. It's gonna do the following. So we have will have the following parameters and it's gonna this one's gonna be called accumulator. He calls. They felt the default value is zero. So inside this function, if an equal zero, we're going to return the accumulator, and then else oops else. Then we're gonna return. If it's not zero, we're going to return. You're going to use Rikers in year function within the same function within itself and minus one with arguments and accumulator plus n. So let's just build and check. Everything's okay. So everything is good. All right, Now let's print them. Print some and with the argument 10 and then print tail some with the argument. Samos 10. So my 10. Right front, as you can see here, why didn't give me none. So let me just check my code Kenya later. So here we go some. So here is You could see some as a pre defined function. Now I'm just checking. Why? It gave me none. We just checked my coat again. Did you do to? To To death. If you call zero community er accumulator. That should be good. Yes, all right. So Oh, of course. Um the indentation. I believe in some or something else. Oh, the return should be, uh, no. Oh, right. Silly me. I forgot the return on the other part of this statement. Silly me. As you could see you, we got the same results. So sorry for the delay. I just kind of had a sort of brain fart. So what we did here is that really we did this to We did the same thing, but in two different ways. The first way is just ready to Rikers in the second way. And we had tail with Taylor incursion where we actually used repeating parameter, as you see here with this with this accumulator and so that pretty much I hope you kind of got the concept that occurs in through these examples. We hope you tune in next time. 32. 31 Lambda functions: welcome back. So to conclude this chapter, we're gonna talk about Lambda Functions or the Lambda operator. So what we're gonna do? Basically, I did here already. I made I basically what I did, I made it like a sort of in line function. So our function call is going to use af actually, So let's see how this works. So let's actually I already tight it out. So let's just call F with our arguments two and three and we're gonna build that. As you see, we got five. So lambda just a nameless function. Since we have the name for the variable outside, just it's called anonymous or just nameless function and you have the parameters. Then you have a colon, and then you have whatever code is to be executed, which is to be interpreted. And so it has how pretty much. That's how that much this how that works pretty much in Python. So this is probably similar to the arrow operator that other and like Cruz and we'll see. But just what to take away from here is that you could make a in line function, and this also applies to also applies to nested functions and will show that right now. So let's erase all this. All right, so we have f again and then we're new Lambda. As you can see, it highlights highlighted in blue and in Tallis size, which means you did it right. So let's have lambda with parameter a inside that we have another Lambda function or its Hubble and the operator could be and then land Ah, see XY So we have a function within a function within a function again so and after that, we're gonna have a times B times C. So this is a simpler way of writing. Of example, before where we had three the functions the three Necid functions function within a function with function. So this is pretty much easier way to write that example from before. So let's do this print and then again, once again, we're defining nest through defined parameters and the necessary function. Necid functions. So let's do that right now. So so open parentheses like this. 53 and then two So and then we're gonna build that and we got 30 so five times, three times to fill 15 times two, which is 30. All right, And then we're also going to do another example with the following. It's just pretty simple, pretty simple stuff. You just write Lambda for your function and clauses and I defy said already, so no need to repeat myself. All right, so let's just write another example. So you kind of just grasp this stuff. All right? So, Lambda see Lambda a then comma for the argument and then side is another function Lambda. Let's call it, I don't know slammed, uh d and that inside that we have C hopes. Actually, I know friend Assisi times, and we're actually using our printing press in order of precedence from before. So check out our previous tutorials for that. And what's dio remainder d? All right, let's just clean this up a little. Okay? There you go. All right? No, it's called us. Let's see. So f were using f so to and then for three. So the practices air following the order of the Necid functions from left to right. So first argument see, is too the 2nd 1 A. It's four and then three is the next one. And then after that, we have 11. So was built. That as you can see you, we got three. So we got to times seven. Remainder. Wait, no, Whatever. You just you kind of get it here. So there you go. And that's pretty much just illustrates Lambda Lambda operators or limited functions they're called. So with the take away from this is that they're not exactly the same as Lando's and other programming languages. But, ah, the whole concept is used together with something will actually learn later, which are filter map and reduce concepts, concepts and that pretty much conclusive chapter. So see you next time. 33. 32 Exceptions and errors: hello. Everyone in this chapter will be talking about exceptions and how to handle them. We will learn about what exceptions are and how to basically handled such exceptions that keep being myself with handing the exceptions in errors and Python and then on the the end will also have no learn how to create an actual will. Learn how to create our own exceptions and Python, so to start off, will be defining what an exception exception is. Exactly so what it is is basically an error that occurs when a program during its execution is run into a situation that is not defined. So that kind like a kind of text booked textbook answer. So let's just demonstrate what that looks like. So let's print the following print. Five Divided by zero. Well, obviously, that Simon defined because anything divided by zero is undefined. So it's Bill that let's build that control be all right. So here we go. And here's the Here's the exception. Zero Division era division by zero. So as you know, like I just said to keep repeating myself, that this is an exception and it is undefined because dividing by zero is undefined So that's basically this. It's, um, zero division error. And we also have that. If you remember, we worked with former previous tutorial. You can watch that, too, Um, about working with flat files file management. We also have the following error. If we have open one, open a file that doesn't exist. So let's say open and what's the file is called. I don't know. Let's just call it file just random and then we want to see in read mode. But what's gonna happen is is the following you get falling file, not found error. So that's another air. So we can also. This also occurs when we want to convert. We also have another error where we have we want to convert a string into an integer. So let's do the following. We have int, and then we have one C 1.2 and then be lips be. And, as you can see, value error. Because 1.2 isn't actually an Inter juror. It is, um, it's ah floating point number with a decimal point after there's number Have a decimal point. All right, Now, um, if we type out the two following lines so Let's do that right now. So let's say a equals but a a equals five divided by zero. And then we say print after error. So let's say we have that. Let's do this as you can see anything. It will identify actually where the error occurred, so as you can see here, it says. And it has traced back. Most recent call as blah, blah line to it, says where there occurred. So and then it identifies which error actually occurred. So now that we've introduced ourselves to exceptions and errors, we'll try toe how to learn them and to avoid such situations with these errors. But keep in mind that these errors do not happen very often. But ah ah, good programmer will make sure they're handled their handled and dealt with beforehand. And that pretty much concludes this tutorial. See you next time 34. 33 Handling exceptions: So now let's talk about actually handling exceptions. So if you have some suspicious code that may raise an exception, you can defend your program by placing the suspicious code in a try block. So we're gonna start off with try, try, and then you add a colon. So actually, let's start off with our actual suspicious code. So let's say that from the example from four A equals five divided by zero, Right. Okay, so we opened the try block and after the try, we include we include an except statement followed by the block, a code which handles the problem as elegantly as possible. So actually, I should be writing this as follows. So first we start off a try when we put our suspicious coat. Don't forget to invent suspicious code within the try block. So here's our sufficient suspicious code. And then whoops. And then after that, we do an except statement. So except except X satisfied, except we'll call it exception. And then so an old in the older version in version two of Python we have this syntax would look like this exception comma e with colon, and then you print and then you do the whatever your code, whatever code you want to execute. If the exception occurs. So we want to print what exception occurs if if there is an exception, there's an error. So as you can see it says Invalid Harris syntax. So let's, um, let's do it in this version in, ah, version 3.5, which I'm using in sublime text three you have to use as eso. Let's do that right now. As you can see, it says Division by zero. Now we can also specify the type of excited exception to be thrown. Now This is being called throwing an exception. So you throw the exception, for example, let's say let's do the following So it's doing all this that we're going to say n equals and so we're typecasting to end input, and then we want to say we want to prompt the user to enter an integer, and then we're gonna after so we're gonna This might be suspicious code because what if the user enters a character of some sort and non integer? Well, we're going to say OK, so let's try executing this code with keeping in mind that keeping a mind that value error can occur. So let's say value error And then So this time you don't have to define a variable because last time we defined basically, any exception can occur. But this time we're looking specifically for a value error. So if if we expected integer but we don't get integer, it will say print. We're going to say, Hey, this is an integer that is not an integer. And remember, we're working with the data input from one of our previous tutorials from the data input tutorial. So you're gonna have to build since we're using input this time, we need to communicate with the console. So what we're going to do, we're gonna go over to supply reply R p R E p l and then Ron current file. So let's say I write one in text. As you can see, that's on integer. Okay, so moving on, we also try. We'll also do an example right now with multiple accepts. So we're gonna type out the fault line code. All right, let's give me a sect that was code. So it's a sum equal zero and then so we have a couple things going on we're gonna try to open a file, and when you open a file, you should probably It's good practice to try and accept and do throw the exception if there's no file available. It's good because in case you're doing something and then a file is missing or remove, you can say something like your file when we don't have this file in stored on the on the Machine or it's not, it's not found, so you could just say something like you use an exception. So So what we're gonna do with this code we're gonna basically so we just write it out. So four number and file. So we have a four loop and then in Dent, and they're going to say some we're gonna make working. Accumulate a some of Juan plus 0 1.0 divided by integer. So number drops I did. There you go. Oh, hopes we want to typecast number because remember and files it's some, it's actually it's a character, so we want our string part of a string. So we need to typecast it, too, an integer. All right, so we're taking this. Were commuting the sum of numbers inside off one divided by whatever numbers in the file started file. So we're gonna Then we're gonna print the some. All right, so here's a code. And now we have a couple except statements. So except zero division error now in sublime text, it's not auto filling for this part. But when you type it out here, let's try. Actually, no, it's not fulfilling, so let's just type it out. Division Zero division error. Okay, so we're saying, OK, we're gonna will be expecting a zero division arrow pop error possibly inside this in this coach. So let's respond, which be on the lookout for it. So it's a number in file, equal to zero, and then we're gonna another one that says, except and I o era. This is another type of error that's going to say, Uh, okay, so the file does not exist. File. Let's just say DNE just a short in our tech typing. All right, so let's build this. As you can see, there's a mistake here. Hold on a sec. Um, line six syntax error. Invalid syntax. Okay, there's invalid syntax error. So of course, for at the colon again, i o era for about another colon. So don't for your Coghlan's kids. All right, so file DNE because the files on there to begin with and you can't do this, you can't catch. Try zero division error. You can't check for it because, well, there's no file. So it's good to the good practice to give us more information about the error included. So that's why when you have except you should also print out whatever, whatever happened to tell the user or the programmer to tell us what happened. And we also have one more thing. It's called the finally Finally block. This is executed. Regardless, this block of code is executed regardless of whether or not there is an exception. So we're gonna add to this code. Ah, finally, statement finally block. Excuse me. And then what we're gonna do, we're going to say we want the some. Anyway, from this from this code, we just did, and then we're gonna If there was zero of some sort or something, we're just gonna close the file anyway, just for safe measure. So let's do that and let's see what's OK. So as you can see, there was no file the close, but it's still gave us zero anyway. So C five says name error file is not defined, and therefore we couldn't close. But anyway, since there was an error, it still gave us some because we said, Print out some and as you can see from beginning, some is still zero. And that pretty much concludes this part this section, um, tune in next time. 35. 34 Throwing exceptions: So now let's talk about throwing an exception. So even if your code doesn't really have an exception to be expected, expected exception or error, we can throw on if we actually need one. So what we do, we raise the statement, and this is done with the actual in the falling way. Let's just say I'll just skip to the code itself. So let's say equals one. There's no there's obviously no nothing, no problem here. So we're gonna say death and thats so we're gonna define raise exception and it's gonna say a has the parameter. So in this exception, we're raising acceptance. So we're say, if if the type of a it is not equaled to the type of character a, then we're going to say raise here is that raise were keyword now value error. This is not a string. So what we're saying now is if a isn't a character spoke, well, actually, string type that we're going to say, Well, its value our that's wrong raised the value because we want a string. So all right, so let's actually and then Okay, since we have this error, we're gonna raise your throwing. This exception I mean, we're also going to try. We got to try the code now, so we're gonna try raising the exception. So try so, actually what? We kind of made a function right here. It's actually a function if you're familiar with functions from last time. So we defined it. This the name of the function. And then there's a raise, the raise key word inside that function. So this function is going to check for this value error. So let's So we're gonna try. We're gonna try doing the function, raise exception, as you can see and then with our variable A And then after that, we have except and then we have value error. Trump's ever at the space value error. See, auto feels for me, all right? So, actually, Soulsby, except my bad, not exception, let's do this. So, except value error as he coolant, then print E. So we're going to say OK, so we're gonna try doing this running dysfunction, and then we're gonna print on what would happened if there was an exception. So let's do this. As you can see, it says this is not a string, because it's so this error actually worked, But let's say this is actually shrink A So let's do that. As you can see, everything checks out. So basically our code works. So you knew that that's his non string. So if you pass a string instead of integer, then we won't get an exception, as I just showed you. But, um so another way to test the program instead of using raise we have these cert statement. This statement one encountered causes the expression to be evaluated where if the result is false, then basically an exception is raised. So let's write an example. Just erase all of this. So this time raising it looks like we're gonna have So it's called assert. So as you can see, it's highlighting. So it's a keyword. All right, so we're gonna define a new function called deaf since a test case. And then we have two parameters A and B. You can space him out was clean it up. So let's say a search a less than be a is greater greater than be so what we did. We basically it's like we did everything in line, as you can see with this. So, um, let's do this now. So we have try, and then we're gonna try, were gonna run this function because it might be suspicious. I've said so. Quote unquote suspicious code. So we're gonna have test case with two and one other parameters. So equals two and B equals one, and then we're gonna say, except non exception, except and then assertion error. So assertion we are using it has its own type of error exception. So, as e and then print flips her at the entrance, has he as French? And then Okay, so here we go. That's build this. As you can see, there's a Cenex Aero Forgot the colon has even at the corn there, too. All right, there you go. A is greater than be so We asserted that if this doesn't occur, if this occurs, actually, we're going to say a is greater than be so that's basically it. So assert will assert a sort of exception what that happens. So if we versus around, what's this keyboards kind of weird. Um, as you could see, nothing happened because this checks out. But this thing's doesn't check out. We're going to say a is greater than be. And that pretty much concludes this section. We hope to see you in the next chapter. 36. 35 Data input setup and input function: So now let's talk about data input. So data input basically is. Is the user in putting some sort of data and getting some reply backrooms from from the council or the system by It does, like some sort of calculation or manipulation of the input data and returns some sort of output. So this is done with the falling to function. We have both input, and Ron put functions. Now the difference between the two. So I have some code right here we're gonna work with later. Input itself is Ah, it's It's the current on the current version, Python three. It's used for input and for prompting the user to input some sort of string and getting a reply back of the string in old, Over in the older version of python like in Python version two, we have raw input, and in version three, this doesn't work anymore because they completely removed it. So now we just have input. So before I continue, we're gonna have to set up how to allow sublime text to have, like, a sort of council input, because, or like, like as it is when we build it, it doesn't work as it should. As you say. As you can see, it prints out this string prompt string, but it doesn't do anything. So what we're gonna do when first show you how to actually enable consul input data input unto in Python version, this is Python. Excuse me. Sublime three Sublime text three. So, what we're gonna do first, we gotta install this package package control. And what I did. You just go to Google and let me open this. And thanks to our friends, a package control that I o we, um we they get pride, provide everything for us, and we just download the package control splint text package. And, of course, you download it, and then you have to find a directory for for sublime text. So let's find that right now. And you know, I'm Mike is 64 bit, so it's in program files and under sublime text three, there's a package, this folder, and here I already have a place. But here, as you can see, I'll just drag it in for you. So let's see. Okay, so here we go. We open the containing folder and it's in downloads. Of course. Then we just we're just going to drag it into our sublime text directory. So it's and that's it's It's what I did. I actually skipped. Um, so here we go. We just copy that, and that's pretty much it. And then once you have that installed, you have to reset. You have to restart sublime text. You're gonna close that, and then we're gonna come back. So let's open up. Sublime text again. Okay, so now we're gonna have this thing called sublime reply, Ari pl into under the tools tab. What? This is it a lot. It's gonna allow us to set up constantly, but for Python, So you go under sublime R p l. And then we have the Python sub tab, and then we're gonna have to choose Python Ron current file. But when we click it, it says file, it found error. So in order to fix this, we're going to do the following. We have to basically ad ah environment variable in windows. So what we're gonna do, we're gonna have to head over to our system properties. This is done by finding your PC. So this PC in my case and you go to properties of your system, and then you have advanced system settings. And over here in the event system settings, you have environment variables. And then on the lower part, or it's a system variables. You're gonna click on the path variable. And here you have a bunch of various options and we're gonna have to add a new one right now. So we're gonna click on new. But before doing that, we're going to have to find the path the the path of python where it's installed. So we're going to find that right now Just a short cut way. We're just going to search for Python here, but it's on, as you can see. And then we're gonna go to open file location. And this is my keys Shortcut. So you do that, you do same thing again. Open file location. And here it is. And then up here and Windows Explorer, you just copy. Click on the search bar. Copy this whole address this path. Copy that. You can close it. Then when you add new environment variable, you paste it. Okay. Okay. It should be added. Now you can close this and then we're gonna restart sublime text. So called that. And then we're gonna open sublime text again. I should really put a shortcut on the desktop. All right, So now here's our code again. So, what we're gonna do this time instead of doing control be or building it? We're going to go to sublime reply, go under python, and then run. And as you can see, this is a new sort of console and give us the prompt. And when I'd write the answer 20 it echoes are apply, and that's pretty much it. So now you're set up to do Consul data input in sublime text. So remember, don't build. You have to actually go here sublime reply and go to Python and Ron current file. And that pretty much concludes this introduction we hope to see next time 37. 36 File management reading: Now, let's talk about file management to start off, we're gonna learn about how to open a file. So first, where to start off by making a variable called file and then we're gonna equals to function called open. So before I move on, I'm gonna just talk about the product, how the prototype open and how it wouldn't supposed to look like. So let's make this a comment. Um, open. It's gonna the parameters go in the falling way. So we have the file name, then we have the access mode which can be read or write or both. So access or let's just say, keeps it actually, just say, read or write. Excuse me. And then we have an optional one, which is buffering that's basically telling us whether buffering will be used and we might talk about let later. But we'll just focus on our focus is file, name and access. So let's open our first file. So we have our first parameter, and then, in my case, I'm using a direct path. If you don't use a path, it'll open the it opened. A text will open this file in where you're sublime. Full text project is located. So in my case, I'm using the path. And if you're using the slashes, don't forget to use escape characters. Where you have you tried in the slash twice. So we have our file that we're gonna have comma and then the mode, and we're going to save our for read. Okay, so now we're gonna print what we're reading from the file. What we're going to do with this function we're gonna have is read. That's basically reads from the file. So we opened it, and now we're going to read from it. So we're gonna print that out print, and then we have file dot Reid, Don't forget your parentheses as them. It's a method. So it's Don't raise your parentheses, that's all. All right, so we're gonna build that. As you can see in my file, I wrote Hello. So that's where that's it. And then a good practice tohave. So when you're done with the file, you close it. Now, the method close looks like this closed parentheses, and then we're gonna do so. We do file dot Close. So basically we used the variable because it's a lot easier. It's basically proper code etiquette. And so we have a variable for where we have opened or re open the file. And then every time we need to work with a file, we have the file, the variable name of the where the file is dot and the method. So we closed it and there you go. All right, moving on. We can also what we can do. We can read a specific amount of characters in a file, so the argument the parameter in Read is as follows. So we let's say we have for that means that's the number of bytes to be red, so that's approximated to every amount of characters. So, for let's say, we're going to read for by its or four characters from the file. So when I do that it Hello has five letters and now we're only reading four letters. And so let's That's pretty much it for read. So let's move on to another function called Tell What Tell is going to do. It tells us where the current position of the pointer is in the file. So let's say we have our current current code and we're gonna print every file dot tell and we're gonna print and what it says are are cursor is at the fourth position right now. So if we changes to five, it goes to five. All right, so we mentioned the pointer. So this is like indicates where where we're currently reading from the file. So we have Teoh. We have another function called it's called Seek. What? This does it. It allows us to move the pointer within the file to wherever we need to for whatever purpose. So what's? So let me just talk about the arguments parameters first. So the 1st 1 is the bites is the number of bytes for which we want to actually move the pointer and the other one's optional. So well, probable. Basically, we won't be talking about it too much, so So we have seek file, not seek, and let's say we want to. So let's take our previous example. So we take this. We have file seek. Let's just clean this up a little, OK, so let's say we reading four characters and then afterwards we want to go to the end of the file anyway, so for just some purpose, So we're gonna do file seek and Then at the end, we're gonna do file tell, and then we're gonna build that. Oh, forgot the print. Of course. So print. And there we go. That should work. Yes. So before, if we would take this out, it would have been four. But now we have five because we moved the cursor to the animal file, and that pretty much illustrates how that works. So what we can also do we can read. Um, Let's actually let's get rid of all this. We don't not gonna need this right now. All right? What we can also do We can also read the file one line at a time with by using a loop. So four lion and so we can you We can actually use loops with the file itself. So let's say you have a bunch of text. So let me just write this out first, and then we have line. So this is going to read line per line. And, of course, where after we're done, we're going to file close. All right, So let me just go back to my file, and we're gonna add some lines line, so let's just copy bunch of line All right. So we have Hello. And then a bunch. Four lines. All right, so let's print this out. Oops. And I forgot something. Hold on a sec. Close. Okay, so in file me, Just check my syntax. I forgot the colon again. All right, so there you go. It so didn't use the for loop to print every single line. Because if we just did print, if we just did print line, it would just do one line or just print file would do one line until the end. Character. So in this case, it printed every single lion, and then you just close it as we usually do in proper practice. And so now what we can also talk about is, um we have to so one working with files, we should basically no Semak trip. We should know, Get to know some attributes. So let's do the following. So we have print, so let's safe file name. We're gonna just get to know some attributes, so file name, and that's going to be Plus, we're adding to the string file dot name. Then we have print is closed, and then we're gonna do string function, so display the string off file closed, and then we have rent, and then we're gonna print the mode that we're in. So you might need the things might be proved to be useful later on in whatever programming jobs you have. So Oops, I made a mistake somewhere. Where? Oh, no. Here we go. All right. So a printout, basically, what we had in here, so we might need this. First. This stuff might come in handy these attributes for whatever you're doing. So we return the file name we returned whether it's clothes or not. So we said it returns a bull, so we want Oh, typecast It is the string. So we said, Give me the string. Is a trooper false? So is it closed? No, because we just opened it so and then we ask for the mode and I made here Modell here remote are and that pretty much that's pretty much it. So that concludes file reading. Next time we'll be dealing with file writing. 38. 37 File management writing: to conclude this chapter, we're going to talk about writing to a file. So first we need to write the file with appropriate permission. Now we have. So first we're gonna start off with our we're going to start off with starting with file equals this time instead of we're gonna open this time, however, we're going to use something. We're going to use the mode, right? W Plus, this means we can write, read and write with this file opens the file for both reading and writing. We also have something called WB, which right opens the file and by a very format. But we won't be using that. So we're going to be using W plus so reading and writing to demonstrate how this works. Now, when you open a file in write mode, it's gonna either it's gonna overwrite the existing file or if it doesn't exist, it will create a new file. So let's make a new file called right, not text. And this is stored and wherever the sublime text project is located inside that folder. So our new we're gonna open a new file called We're gonna open a file called right dot text what you wanna use for reading and writing. So let's let's do the falling. So we're gonna do right? We have the method called right, and the argument inside that is the parameter inside that is going to be the string that we're going or whatever we're going to write to the file. So we have Hello, file. I am drink. So we have that Rin. So let's say we want to read what we just wrote now. So once we write to a file the Kurds, the pointer in the files moves to the very end. So we want to get it back to the beginning. The cursor, the pointer. Excuse me Back to the beginning. So we're gonna use file dot seek and then zero to go back to the very beginning of the file . So we can actually, you know, so we can actually go back to the beginning. All right, so then we're going to print file that read, and then afterwards we're going to close part of part of it as part of good practice or in a closed, As you can see, it did it. Now if we removed, seek what's to remove, seek As you can see, there's nothing there because we're at the end of the file. So yeah, that's pretty much that's pretty much that. And then what we can also do we get Let's let's take Let's take goes to FC file, seek back to the end and weaken weaken basically right within that. So let's say we right, so once will you seek weaken right at that position. So at the very beginning of the file, we're going to write a new string as a part of the whole text inside the file. So it's too right. And then from that, right, we're gonna say this and then we're gonna build. And as you can see, it did it from that it started from that position. So lets you seek again. So it wrote this and then after writing it went back to that. It went to the very end of that position. So let's do this. And it basically overrode whatever was here. So it wrote the hell in Hello with this because we were at the beginning. So it took four characters and we wrote them. And that pretty much concludes dealing with date the chapter dealing with data input and file a management. We hope to see you next time 39. 38 Tuples: Hello, everyone In this chapter, we're gonna talk about data structures and python. So what data structures basically do is that they help us organize data in our machine so that it could be used more efficiently. But we won't be talking about the actual Serie behind data structures. Instead, we'll focus on how to actually use them in practice. So the 1st 1 we're gonna talk about is called the to Pull. What A to pull is basically a sequins of immutable objects, which basically means, Ah, once you create a variable of the to pull type, you can't change its elements. So let's define a to pull in the falling way. Let's go on to equals. So you have 11 that a string ABC comma two. And then again then c D. So here's our terp. To pull another way can be done is like this, so we have to one equals. So without the pregnancies, basically three. Yep, G. And then we say True, it's just part of the two people. And to find to pull with the single value you just do The falling so tube to to, for example, equals Capital A or It's also can be done, as so this. Also, I'm just writing comments so you could say tube too equals in parentheses, a and then comma and just keep in mind. The comma is essential when you just have one element in to pull you can so you can print out the elements so moving on actually put out the elements of A to pull using the print function, so it'll just print em all out. It's not capital print as keyboards, kind of weird, um, to pop. All right, build. So it basically printed everything out with the prophecies and everything you could also print elements of to pull. So let's to go following instead of saying the whole to pull, we just say the first element. Remember, not the first, the first. So zero is inclusive. So we have 0123 in this first to puzzle 0123 So when we said one, that means we got ABC in that to pull it. But when we say zero, we get the 1st 0th element so you can also use. And ice is to slice the two poles. So, um, zero colon. That's done by do the following zero colon to, for example. That means we just want to get a certain portion of the triple. So you just want zero the zeroth position and the second position to the second position or actually to give me. Actually, that should be saying, Why should we say that's give me two elements for the to pull, starting from zeroth position and counting up to two. So one for the zeroth and two for this first. So it's kind of confusing, but to say, Okay, starting from here, give me two elements starting from beginning. So 12 Okay, so moving on. We already mentioned that two bulls are immutable object, so we can't change him. But so what we could do? We could assign a value to a single element of the to pull, but we can't change it later, so we'll do the following. So let's race this three sec, so we're gonna do a try, and I mean and what we're gonna do this? We're gonna try assigning a value through the third element of the two poles. So 23 and square brackets equals five. And as you probably already comptel based on what we said before, this isn't gonna work, so we're going to accept exception as e colon print e and you're gonna see what's gonna happen to pool is an object that is not sport items. Items sign it. So, as we said, it's backs up. What we our claim that we said two polls can't be elements can be changed at all. So there, immutable and that prevent that solves that issue. And now what you can also do we can do as follows. So let's let's try another piece of code. So let's erase that so to we're gonna actually you zero we're not slice spiced, sliced, spiced whenever, um, plus five comma. So what we're doing here, we're going to Let's just let's just type it up. What we're gonna do, we're gonna add in element to the very end. So what we did, we got the whole we said, Okay, so the to pull now is gonna be the following, so the to pull is going Teoh from after the final element, we add another element five and we said Okay, so now we have 1/5 element. So this this means weaken conclude that all operations that are applicable to strings are also a biblical applicability to two balls, and therefore we can multiply. Use the multiple Kate multiplication print, so to times times eight times to pull to, actually, let's say, two times four. It's gonna printing out four times. Miller operator we can use is the membership operator. This operator is used for checking if an element belongs to a Tupelo or not. So we're asking. So let's print out. Does five belong to? To pull? Is there five into in the in to pull and that means it's returns a bull. So yes, it is. It's in there, and it is also possible to use to polls in oration in loops. So let's do that too. So I'm just writing a lot of code. Well, just adding things on to save some time. So in four X in us, um, a don't got a be sick and see. So this is a to pull for using a four abusing A to pull. So there's a print. Necks do that and there's a mistake here, so oh, fraught the colon again. All right, let's see what the problem is. Name X is not defined That's because I use the capital X ups keep my finger on the shift key. All right, so it said OK is that we're gonna print little to pull in a four loop so ABC and we could find we find triples very also when there are needs to return multiple results from a function. So let's do that as well. So define multiple results, actually result cancel results. And then we're gonna say OK, so give me the to pull return 12 than a and they were gonna say print multiple results. So with two pools, you can get multiple results. I forgot the There we go multiple results, and you can compare to troubles with one another if you care to 22 bowls of one another by doing the following. So you do print, um, we're gonna do a manual to pull 123 equals equals 12 for example. So you're checking if pupils are equal to each other, which these are not syntax error. Hold on a sec. I forgot a parentheses. There you go. And as you can see, it's false. So basically two bulls are pretty dynamic. You can work with them in a lot of number ways, as you can see here. So if you want to look at these again, just pause a video or whatever, just and that's pretty much it. 40. 39 Tuple functions: All right, so we have some actual. We have some functions. One working with two pools that you might find useful. So we'll just name a couple of memorable three, to be exact. So we have the length function, which returns the length of the to pull. So let's make a to pull what's okay? We have tough one. Let's say top equals open or parentheses. 12234 Okay, that works. So in the length of that, we're gonna say of tough. All right? And then we're gonna print this out. It would go and you get three. Because you have 3123 elements. A meals of another function called Max, which gets the max element. The greatest element of the function. The max element. So let's see that. Sorry. Yeah. Yeah, it gets the max helmet. And let's just for safe measure. Let's do this. And there you go. Gets the max element, no matter where it is. We also have the men function for do pal's, which gets the minimum element of the two poll, which is to in this case, and we could change it up. Let's make the last element one And there you go. So these are just some useful quick. This is a quick tutorial. Just tell you a couple of these functions that that's pretty much it. 41. 40 Lists: Hello, everyone. To sort of piggyback from the previous tutorial, we're gonna be talking about the basic data structure in Python, which is a sequence now in the sequence. In order of elements. The order of elements is important, and Python has several built in sequences and one of them from last. The last chapter is the to pull and another type which will be talking about today. Well, right now actually is a list, and that is basically yeah, so we talk about list. And what's common in all sequences in lists and two bulls is that every object that has seek is a sequence has index elements. So we saw before we actually used one sec. We actually use the following. We actually had this to, and we had index of some sort if you notice from last from the previous tutorial, and so that's index element. So each element can be accessed through this index and these objects and also be sliced like, for example, I j and contaminated with like adding on to it. So to pull equals two plus some sort of one. For example, he add one to the sequence and repeated with multiplication what you'll see again with list . Since this tutorial. Select Ramble three repeated three times. So listen, Python can be a listen. Python can be actually written in the following way. So it's a list one equals, um, square brackets. You do square brackets for lists. One, ABC to 23 this And if you noticed, this is actually a to pull, which will actually mention in a little bit. So and list can be printed on the falling while you just print and you do the name Lehman List, and that's it, and you print it out. So I just said before we talked about two pools. You can actually get that to pull because it's this and it's the element index in the second index place. So well, you go index to, and you get that simple now, since is a to pull we want. We might want to access one of the elements inside the to pull. So first we have the index of where the two bulls located in the list, and then we have whichever element in the to pull for the next square brackets, as you can see. So let's say we want the zeroth one. And we got to this time, which is which checks out here and if you want it for now, we can also add to this list by, for example, plus in the element. It looks like this. So in square brackets and see when add four as a shrink and then we build that. So we added four to the end off this list, and we go. So multiply the amount of elements analysts. So we could say we want 22 copies of the entire list. So let's see. Oops, all right. And we got C from at the end, we multiplied the same. We copied it for that it many times for this many times. And we also can use the membership operator like we did in two pools to check whether it element is there. So inside the list. So I say to in, for example, to in Liz Toe one that basically asked is to located in this less found in this list. And of course, it's not. As you can see here, it's remember, it's to pull is its own element. So it's not equal the to Just so you know, we have to check the chewable itself if you want. If you want this to anyway, moving on, we can also compare lists so we could do that in the following way. You just do list a list like we did trouble the trouble. So we did list and then we have a manually written list. So ABC and then 23 I think we did before. And it's true because they're the same, which you can see here. We can also slice lists, as we did with two pools. Get a certain part of the list. So from the beginning, you don't have to write anything before the colon thing you write to. So give me to the 1st 2 elements in the list. That's what that means. If you want to add to the list itself, had element to the analysts, that is, you have to you can use do the falling. So here's our list, and we want to add it to the end annulment to the end. So we have a function called up happened or eh penned words over way you pronounce it, and the perimeter is which what, what you want to add to the end of the list, Which what kind? What is the element on the end of the list? Then we kills through the falling way. So you do. You take the index, not my list missed, actually list. You take the index of the final off the whole length of the list. So give me on the end of the list and then colon and and there's no end here. So and then you add the element. And don't forget your square brackets in this case, and then finally we printed out. So this is two ways to do it. This is basically the equivalent of this, whichever one, it's your choice and what were based on your code. So this pretty much concludes basic manipulation and off lists and how we worked with them and what they are. Next time we'll be doing some specific three specific functions for lists, so we hope to see you next time 42. 41 List functions: All right. So there are some special functions when working with lists and python. So the 1st 1 we're gonna talk about is the map function. Looks like this map. So what this does, it takes two parameters. One is a function in the other one is a sequence of elements, and the resulting sequence it it returns to us is the past sequence to which the function past function is applied. So we're gonna get slammed us here because it's a lot easier ti toa work with them when working with map. So inversion to matt functions would look like this. So we have a map, and we in that parentheses we type in our function first of the first parameters parameter . Excuse me. So we have a Lambda of X, and then we're going to say X squared to say to We should go to space there to be nice. Proper. Okay, so x 33 Times X and then we're gonna have plus one. So there's our function, and then we're gonna have our list. So +1234 So if I build this, it's not gonna work. Just gonna show Give us this. So in order to make it work in version three. We have to. On the outside of the map, we have to add list to make sure that we're gonna print out a list. So let's add another parentheses right a year. All right. So and as you can see, it applied every every element from this list to this function. So x when X equals, want executes two and so on. All right. And so another function we have is filter. So let's erase this. So have it's called filter. It also takes two parameters and a function like like before. And Thea other parameter is a list. And the result is all the elements from the past sequence that satisfy the condition given in the function. So if we say okay, we're gonna have Lambda again. So Lamda. And this time we have some sort of condition like I don't know, like X is less than four and in common to separate our parameters than or open our sequence . And we have 12345 for 4321 So inversion inversion two of python. It's without the list again. So, like like you would just do this, he would just print out the map had turned out the filter as get this a similar result as last time. So in order to basically solve this problem in version three, you just add list this function right here. And there you go. It shows it should gives you return everything. Every element that is less than four. All right, so the third function we're gonna talk about is reduce. It takes the same parameters of before, and the result returns one value. So, in our example, the function that is passed to reduce multiple multiplies two elements. So let's actually write that out. Here we go. A lot of sick. All right, so we're going to say print, reduce, and then we're gonna have lambda x X and Y I'm sorry from you, William Lambda Lambda Ex And why they were never colon. And then say X times why? And then the other parameter is going to be on 234 set. All right, so now what reduced does is it takes the 1st 2 elements of the given sequence and multiplies them. So one times two, the result of that multiplication is now paired with the third element of the given sequence, and the whole procedure is repeated until we get one value as a result. So we're going to see that in a second. Just, um, this is how you write in version two. And but in version three, instead of adding a list like before, you need to import the function Funk tools module, we'll talk about modules and the next chapter so and we need that module in order. T Teoh use this function. So what we do, we're gonna have to just use it for demonstration purposes only. So you do import and then was a called Hauser and funk tools have tools, and that's how you do that. And don't worry if this confuses now, this is just for demonstration purposes only. So now that we have this, we can actually use reduce. And don't you need to? So what you need to do when we import of this, Will this demonstrate this next chapter? You do fung tools dot reduce. Excuse me. And then you just type everything out and all right. And then really, there we go. So we got Our final result is 24. Now we could have used other functions as our is one of these parameters. But Lando's are you basically easier work with? Like I said before, So that's pretty much concludes this tutorial elect. We hope to see you next time. 43. 42 Dictionaries: So I always talk about another data type called dictionaries, a data structure of my mandate called dictionaries. Dictionaries are basically collections off key value pairs, so I'll show you what that looks like. So we have key value pairs and they're known as maps or associative raise. So each key has a value. And these key every key is unique and valuable, so in values aren't don't really have necessarily have to be unique. So let's write our first example of a dictionary. So we're gonna call this mind dictionary equals and then he In this data structure, we use curly braces and then we define our key. So here's our key, and then we have about and we have. So we have key the the key itself than a semi colon and then value and then each each pair separated by a comma S O aqui and keys. Values can be any tight. You can associate them with any data type anything Really. It could be anything you want and you should define a base depending on your task given to you. So we have we can have a to pull. For example, you could have a number it could have whatever and really anything. And you'll see the results when I prayed throughout. So you have the key and you have the value. And you also have another way of defining Ah, dictionary by using for loop in in the in the dictionary. So you open your curly raises and then you write out whatever you need. So let's do this following example. So we have Key X and we have the value expose one, and then we have a four loop for X in range 10 and then we're gonna print these out French . My dictionary. Go. There you go. All right. And here's an error. Calm again. All right, so here you go. And keep in mind sometimes when you when it prints out the dictionary, it'll be some. Sometimes it will be in different orders. You'll see in a minute when we add when we add a pair to a dictionary, it will sometimes be added on the end or added on the beginning. So it But anyway, so this is basically how you print one out of print dictionaries out, and the index is instead of using indexes, we use the actual key So if you want to get the key from a value from with this key, we open our square brackets with the name of dictionary, and we type in the key. As you can see, Keyes associate with value. So we got value. All right. And if we try to access an element that is not a dictionary, we'll get a number of number error. So let's do the following. So we're going to quick and I think we can erase this. Yeah, So we're gonna do try. So we're gonna to some air handling here. Exception handling. So let's dio print. And they were into my dictionary. The 1st 1 we made Mara dictionary with Key one, and everyone do except And then we're gonna do make our exception as e. And then we're gonna print that exception. See what happens. As you can see, we got a one. And like I said, you just get a number air. Okay, so So what we're going to do next is we're just gonna basic. There's two functions we have If you want to separately display keys and values. You have. You have the falling functions, so you have keys and you have values. Looks like that. So you're gonna take So we're gonna print my dictionary dot keys and then we get on lee the keys from the dictionary. And if we wanted to do print, we're gonna get my dictionary dot values to get on Lee The values, all of them in that dictionary. So we got key key, the to pull key, and we got value five for valleys so And next week, if you wanna added element to dictionary, we do it in the following way. So let's remove this. We're going to take this away. Keyboards acting up anyway, So what we're gonna do, we're gonna take my dictionary over the square brackets and add a key new key. And there were net making cited equal to the value Want to assign? And when we build, as you can see it sometimes in random places. But we still got the new We got the new key value pair. And if you want to change an existing heat value to the oven existing qihoo take the keys. So we have one. Here is our one, and they're going to say equal to three. As you can see here. It changed the three. All right, so and when you want to delete a specified key, you take the following. So we made this and then we're gonna say, OK, let me delete that now. So do we do D L? It's a keyword. And then we take the dictionary and we basically over square brackets and have the key desired key. We want to you delete delete. As you could see, the one we made here is gone. And so we see that change. Apply to one object, all supplies to the other one. And if we don't want this to happen, so we want we have to create a deep copy of the object. But we will learn how to do this in the following chapter. So don't worry about, like, anything, if any, bigger ideas with changing multiple objects. So anyway, moving on. If you want to remove all amounts from a dictionary, you just It's a new function we have. We have its called, so it's called Ah, clear. So you have my dictionary and you have clear and you print it out and you see it's empty. Not pretty much concludes the basics with dictionaries to me next time 44. 43 Shallow copies: All right, So now let's talk about something in data structures that can occur when copying and data structure these we're gonna call the shallow copy. So what? A shovel copy is ice. You can see right here where I wrote. It's so basically, when you have two copies of a data structure and when you copy them, like simply, they share the same set of elements. So we're gonna demonstrate. What? How shall a copy looks like what it looks like. So hot sec. All right, So shallow. Copy. Here's our first diction. We're gonna use date dictionaries for this example. So let's hear ago. We have my dictionary. This is a dictionary we made with item shirt size, meat, size, price and price. All right, so if we, for example, want to do the following So we're going to say we're gonna make a new dictionary called my dictionary. One equals my dictionary. So this is basically just copying. So since they share the same elements set of elements so they share the same elements in memory, they're going to any changes that occur to this one. This dictionary occur in this dictionary as well. So first, let's print out both of them print my dictionary and then we're gonna say, Print my dictionary, one build, and here we go. Now, when we're gonna now we're gonna do something else in this we're gonna add We're gonna change in element. So we're remember we're using We're using this. Were using the key instead of the actual index because working with dictionaries. So we're going to say this size now equals small in our dictionary instead, off instead off medium. So we're gonna threat that out. As you can see following the code this is before this is my dictionary and below is my dictionary one. So as you can see, small changed medium changes small, the other one as well, where it shouldn't where we usually don't want that that happening for their duty to separate dictionaries, which they should be So we can see. Basically, we see that one object chain changing object applies to the other. And if we don't want this that happen, we basically use what is called a deep copy. Will should be learning about in the next chapter when we talk about modules so that pretty much that furnished concludes this explanation tutorial. We hope to see you next time 45. 44 Sets: So to conclude, this chapter will be talking about one last data structure, and that day structure is set a set, So sets are objects that contain a collection of unique elements. So before, with dictionaries, you had all repeating kinds of keys and values. But this time we have a collection of unique elements. They are used for removing duplicates from a collection and our basic and are basically used for performing some basic operations from mathematical theory upsets. If you're familiar with them, these include union intersection indifference, and we'll see how to type those out in a moment. So let's define our first set. So here we go. So let's see. Let's see here. So we're gonna call it my set something simple. My set equals and we have a function called Set. We open in parentheses to me, open square brackets inside the spread disease and we right out our about our elements. So we have one 4.5 to three and then want again. So we're in a three, and there were No, As you can see, we're gonna have a repeating value. So here are elements in the scent. So when we print that set when print that set my such they're duplicates are going to be removed. And so let's right. So let's talk about those those mathematical operations in before I call. I talked about earlier. So we have union, we have intersection, and then we have we have a sort of difference. All right, so it's so let's make a new let's make two sets. So weaken demonstrate. Thes. All right, so we have my set in my set. One we're going to make set open Renzi's open square brackets, and then we're gonna say to three for oops. Forgot quote. Here we go. Okay. As you can to see union is gonna do the falling, so let's just refresh our brains a little. So we're gonna have my set. One union, my set. And we got everything without repeating without repeating elements put together. So we had one. So it since these are duplicates, we don't display them. So we have 1234 because four is the new element being added. All right, so we have intersection now. We're only gonna get the ones that are matching. So we go 14 So he got what sorry. Got ones that are weak. So intersection, as you know, takes all elements that are found in both that are unique to both sets and displays them. And the next one difference is gonna do the following. It's just gonna get the one where there's different. That's so and this one we have when you don't have 12 and three we had on two and on three we don't have, and that's pretty much Onley unequal. Anyway, moving on the results of these operators also set and so can be assigned to a variable. So you just say equals that here. So do that. You don't and you have a they got the same thing. All right, so you can also check if a subset is in. It is a set is a subset of another subset by doing the following. So let's say we have a and those variable and we say less then or equal to my set and you're gonna get a Boolean value false. But if we did the same, I set one. We get true, let's and we could do the other Roy going on their way. So which is false? Because all the value they could do the opposite direction. So a has a subset off everything in my set, which is false because my second Danes a of the other side a all right moving on you. Also, another useful function called It's the ad function, which allows you to add element to a set. So were to do that right now let's remove this line right here. And then we're going to say, I don't know my set that ad And then inside the parentheses, we have our value to be Addis, so we have five, said hopes. And there you go. So we added, we added it to the set and that that's pretty much conclusive chapter on data structures and to didn't we hope to see you again so to next time? 46. 45 Set functions: in this tutorial, we're just going to talk about a couple functions you could that might be. That might actually be useful for you when working with sets. So if remember last time in our previous tutorial, we talked about you an intersection and differences with of sets. Now there are a couple functions to actually get return unions, intersections and differences without having to write using symbols, which, actually, we just use functions, which makes it a lot easier for us. So it's simply run like this, so we're gonna have to print it out first. So print and then we have set dot for union. We just write union and then parentheses. You ever two parameters, which are the sets? 1st 1 is a set one, which said the perimeter basically just the sets were using it to him or a print, and you get the union we also have for intersection. We basically do the same thing just with Intersection, and we also have final on, which is the difference. And you just have, well, different the difference of two cents. Let's show a cheese around so you can see a better illustration of it. There you go. So this sat minus that said, is basically just for and that's pretty much it 47. 46 Modules: Hello, everyone. So now we're moving. We're gonna move on to modules and packages. So what they do, they serve to break down big programs in the small, a logical units. And you remember from one of our previous tutorials, we talked about Deacon Mrs of decomposition of programs. And this is just that. So we can think of modules as a way of program decomposition on the file level because we'll have different thought. What? We were importing files, as you'll see later on. So what they enable us to do is they enable us to reuse code in other fought in these modules for later. So you don't have the right of function more keep repeating, you exist, writing an existing function, or like, and stuff like that. So anyway, let's move on. So to keep things brief, I wrote you wrote I wrote things ahead of time. So here's our or module. It contains functions is that it's another python file with contains functions. So and be sure to have them in the same place as your, um, your your other. Your other python filed. The Montreuil should be the same file as the same location, so here in my cases on the desktop, but it should. It could be anywhere, like in a project called or whatever anyway, So since we have done the same bowler, we're going to import used the key word import. As you can see, it's highlighted, which means a keyword. So from that we do import and we do the name of that file. No, you don't do dot p y like stop python you just to import prime. And when we use this, we have access to all the functions in this module in this file. So prime primes, too. I mean, there's no auto fill here, but it still works, and we have a great perimeter. As you can see, the function worked and that's this function right here. So going on, we could also call. We can also I'm actually import of function met with an alias. So what in aliases is basically just different name of ah of ah, file or whatever? Anything, Really. And it was name it PR. So it's it'll be easier to type out instead of writing prime prime primal time I get you might get lazy or if the file name is actually really long and just want to have a, like a simple letter, whatever. As you could see it the same thing anyway, moving on, we can also. So let's say we can also just import a funk X function in from a module. So if you just need a function, not the whole module itself, you just do the following. So we're going to say from you, start off with from its a keyword module name import skewered and then the function you want, we're gonna do primes too. And now you just write the function out crimes too. And you could do the same thing. And there you go. And we can also do. I use a function for modules and is the de ir version dear old to so called dear order, dear and dysfunction what this does It takes your parameter in the module as a parameter and returns all functions that are defined in the module. So we have deer, we have to import. Don't forget to import import um crime. No. One side, Dear Prime built Hope you got Don't forget. Gotta printed as well. There you go. And so in the next tutorial be explaining because this kind of P backs onto into packages. So we'll talk about these results in next tutorial. So to the next time. 48. 47 Packages: So now we'll brief talk about and explain what packages are, how to create them. So to create a package, we copy all the modules that should be in a package into one folder. So basically a package can be treated as a folder, but with a special file. That's a special python file with the following. So you have this. It looks like this. So three underscores, So underscore underscore of underscore i n i t. And then in it and then to underscores. And that's the name of the new Pyfrom file. So this basically treats ah folder as a package. So let's make our let's make one of those folders right now. So a package contained contains several modules which are basically files that could be that could be used when you import the whole package instead of importing multiple modules . So let's call this main. And first we're just gonna copy this on over, Rename it to whenever name it, too, that there you go. Okay, so now this main folders a package and you could also have sub packages to so folders within folders with this file so new, you just make a new folder There you go. And then So make sure you have this file of initializing file inside each folder, and then you have a cell package. Just make to him. Name them and be sure that package the folder. The whole package holder is inside the same directory as your python hyo. All right, so there you go. And you know what? For? The sake of the tutorial will also have prime the module prime from last time inside one of the sub packages so we can demonstrate how they work. All right, so there you go. Packages ready. It's called main. So now we import the package. What we do, you do import the main packages name and for sub packages for layered sub packages. You do falling. So some and the hierarchies by dot So main sub to dot module. So her monsters hold prime, right? And then you have to use an alias in this case, so as to all right, so now when we do live in sub two dot crimes to the function from our module, we did that we used from last time. And there you go. We get the function, get dysfunction and everything works out checks out here. And so that's and you could also do the same with a single function, like from before where but the summers in packages. Of course we have. From then you do the same the import from Maine sub to stop prime. We just want the function, for example, import the function name, which is primes, too, and then you just right promise to. That's pretty much it. So it's pretty much how packages work, and that's that concludes the tutorial. 49. 48 Builtin modules: So now that we've talked about making our own modules, we're gonna talk about built in modules. So in this example, will be dealing with the the shallow copy problem, which is used in dictionaries, data structures and data structures in general. So what a shallow copyists. Basically, when you copy an object or like, for example, dictionary those to the new copy and the original copy will share individual values. So but what we're gonna do now is to make a deep copy, which is basically when you make when you copied dictionary, for example, the new copy of the dictionary will have its own set. It will have everything duplicated, so each one will have. They'll be the same initially, but they'll be duplicated. So let's zuletzt jump right into it. Okay, so now is this built in modules called copies. So here's what it looks like. So import a copy. All right, so let's make a dictionary. My dictionary equals, and now we're gonna have some from fewer from last time. So key, so key value. We work. You value parents Like we said before said, Separated by the comma and I'm gonna have are two people ke ke he Why inspected Capital and Colon five. All right, so now we're gonna make war instead of copying it. We're just going to We're gonna do it Always looked like this. So we have a copy deep copy, and then the parameter is your dictionary data structure, My dictionary. All right, So this is a built in module, and it uses a crazy deep copies in the function with this built built in module. All right, so no, to make a difference, make some difference. We're just gonna add my dictionary. We're gonna set This Wouldn't do this code right here to make a little difference. We're gonna add the pair key pair 11 All right. So let's print them out and you'll see how this boat in module works. So my dictionary, the state is my dictionary. One dictionary, and then my dictionary One All right field. You go. Oops. I mean, there we go. So, as you can see, it copied everything, duplicated every single thing, but just make a difference. I added in the 1st 111 pair. So another module we have is math. The math module it's built in. So when you, Emperor import and do math. You have, ah lot of mathematical functions like co sign exponents ceiling. And we'll do those right now so we can delete all this. We don't need dictionaries anymore. So what's print and then, Oh, we should you could alias this You don't have to because it's short. So m as math as M, and then we're going to m dot coast for co sign and then you have pie in the module, so that should work. So co sign of pie is minus one and then you have exponents Expert Wait, let's do this XP, then one and you get e. So exponents is e to the power of whatever So eat it Power to, for example, is that and so on and you have ceiling which view if I might have talked about it before, but it gets round up so ceiling, I want my six is too. And you also have ah, complex number modules is called C math. So we could do that too. So import see math as C M and what you could do with this. Let's find out what's now. It's to do, dear. I remember that from CME Print that as you can see, it shows everything all off the functions all the modules we have in this package. Anyway, in this we have I mean, all the functions we have in this module Excuse me. And then So we getting you something like square root so square root, We're just gonna explain. We're just explaining all of the maybe the useful functions you need and you forgot the number That's a for to, and it shows as a complex number here. So it gets people crj um and we could also do polar in the following way to do that useful for some of you. And we're going to say so we have a complex function to Did he go 00 and wait. Oh, forgot something. Forgotten parameters. Tier one. And there you go. Here is that and we also have a random module which is called import. It's called a random, has our ran and what you can do You congenital rate around of numbers with this one. But let's see what year gran build and you have all these functions in there. So in this module you could generate random numbers using different functions. For example, you have sample. Let's see, you have ran dot Sample, which generates a random sample of generates a random sample of three elements. So we have the parameter like a list. For example, we have Here you go five and then we have three. Oops. I mean, music on brand sample. I forgot something. Parentheses. And there you go. Took a random see? Because, randomly, we also have rand random, which uniformly generates around a number from an interval. So random. I don't I don't think we need this. Here you go. Just get some it crevices in there. All right. So generates a random number from 0 to 1. So it's a 10. Um, but yeah. So generous amount of zero. So if you want to live 10 for example, you do pregnancies up to 10. Is that the one? Basically start from 0 to 1. Let's try 100. So, as you can see, just returns zero from interval 01 Now you have an interval officer variation of this. So random. So you do rand into so it makes a random, you know, from interval 5 200 for example. And this would this does gets a random number from the interval. So one more mountain we have is this ISS module s y s. Well, it's important that so, import sis, I don't think we need toe make an alias for that. So now let's do something of this. So what this does This module gives us information on constants and functions that are related to the python interpreter. So, for example, we have you can get information on the max depth of Rikers Asian. So let's see that. So we have print says dot Get Rikers in limit. Go and you have 1000 so you can have record in up to 1000 times. You also have print version says version where we can see a long list. This. Oh, right. There we go. And it tells us the version off our python. What? Python interpreter. Using minus 3.51 We also have path, which shows us where all of the modules are. So this module desist module allows us to pass arguments for the council when executing the script, which will, um which you can see in the falling. Just let me get this file. Tom Prime test. You can see how it's used here in a module I made before, so you have it here being used. So it takes one argument from the consul First argument. When you press enter and that's and it does, it takes one argument from the council. When you run this module in the council, and that's pretty much it for this chapter. We hope to see you next time. 50. 49 Introduction to oop: all right, so in this chapter, we're going to be talking about something that's sort of advanced in programming. It's called object oriented programming, or 00 P for short. So in this tutorial, we're just gonna basically talk about the basic concepts and principles of Opie and what it is used, what college use and why. And so will just basically talk about the whole idea behind Opie. So the whole idea behind it is basically to create a class that contains descriptions, definitions at all possible actions that can be performed on data. So these define actions are basically called methods or functions. I'll be using methods more often than functions, because in O p, we try to like we like to use methods more. And so keep in mind that once you write a class and define all of its methods, you can only use define methods when working with data so you can't have basically anything random and that everything's pre defined. So when talking about Opie, it is important to mention these four basic principles. So we have the following we have hiding, so we're gonna have hiding information. We're going to have encapsulation insulation And then we're also gonna have inheritance and last but not least, poly morph ism. So what hiding info is so basically? What this means is that a user does not need to know how to class implemented it. They just need to know what the class can do. And so or what that is, basically, is what methods are defined in the class and what its purposes. So there is no need to show show in from implementation of class instances. And it's good to know that an instance of a class is a variable that is of the classes type . And so we have encapsulation, which basically means that all variables, basically instances and methods are logically grouped together so you won't have anything random you'll see later on. That will basically make with cars, for example, vehicle cars, a vehicle or truck is a vehicle it's on. And then we'll also talk about inheritance and polymorphisms at a later time because they're more kind of complicated. So it's basically impossible to explain all these things at once, so we'll turn. We'll learn about these things and examples. So will be the silly example focused tutorial kind of chapter. So keep in mind that some of you will find this topic kind of difficult. But that's OK because it's all programmers should base its recommended for everyone, all programmers to explore this topic in detail and also the discussed in section is there for you if you have any questions, so that's basically it for this introduction. So just tune in next time and will wolves beyond our way with object oriented programming. 51. 50 Class definition and object instantiation: All right, so let's dive into object oriented programming. So to start off, we're going to find one of classes. So a class is a collection of attributes that defined for any object as I wrote up here. And so these they have at each class has attributes, which include data members, which are those clad the class and instance, variables and methods so to define, to actually define I, uh, class this in Texas, written as follows. So you have class, and then you also have the name. As you can see, it's everything's highlighting a sublime text. So and then after that, we have something called the Doc String, which is basically a short description of the class itself. So it just is just running descript desk like that. And there you go, and then you have that you have the body. So we're gonna actually illustrate how how these this all works with actually an example itself. So we're going to simulate complex numbers with the class, so we're gonna divine a class called complex, and then we're gonna have our docks during this class simulates complex numbers. Here you go. And then we're gonna have our constructor. So our constructor methods. So it's written in the falling way. So we have death to underscores i n i t two of more underscores. And then we're gonna have three attributes self riel and imagine so we have our riel and imaginary parts and what this method does, it creates new instances. So keep in mind that class methods are the created in the same way as regular ones. However, the only difference is that we have this self argument here which is always placed first in our argument list. So after this, we're gonna add a colon, and then we're gonna define during to write the following. So self dot Rio equals riel, and we're now itself. Imagine equals imaginary. So you match so thes represent are really imaginary price, respectively. So these attributes are instance variables, instant variables defined by self dot whatever the name is. So this is an instant burial itself. So we can conclude that this riel and self diarrheal are not the same thing, and the same thing goes for the imaginary part as well. What this says is actually is this is the instance variable and this is the constructor argument So now that we've we've done this week, we want to Let's say we want to create an instance of our class. So we we have are variable and we said equal to the type the class itself. So as you can see it, auto corrected it on auto corrected auto filled to our classes name and we define our our arguments. So we wanna have imaginary part and the real part equal to one So and then when we want to print this hour, access these values we to, for example, you want to print We have si dot riel common see docked the match. So we're accessing these values directly. And Talon, I made a mistake somewhere. Here we go. Just let me check Complex line 13 So what is it? What is going on here? Oh, right. I forgot something up here did entity to do. Why is it giving me an error attribute? Air object has no idea out. That's of course I did. Um I have ah minus here instead. Ok, there we go. Sorry about that. So So, upon defining a constructor, we passed arguments like we just did. And this includes so itself. we use self. We're actually using self here. So when we when we want to pass values and arguments were basically passing itself and the other arguments themselves. So we're actually passing three here. So what we're gonna do now is let's say we have, I assume we want knew in that instant. Instead, she ate a complex number where we only care about the rial, part riel component of that number. So let's say we have to, As you can see, it got air. So what we like to do good practices for the interpreters sake we use, try and catch statements. So we're going to try two. And then we're gonna say except exception he as e e colon and they're going to say print R E. And as you can see, Allah see complex hope. I forgot. Here we go. I should I should have put this inside. The exceptions of cans Cut that. There we go. And as you can see, it's missing a match. So what this did? It only passed to arguments and said the expected three, as we said before. So what we need to do in order to fix this error? We have to define our default values of our constructor arguments. So here we have zero, and we're also gonna have the imaginary part zero. As you can see, it's gonna work now. So the real part is to and the imaginary part is zero. OK, moving on. So what we did here is basically just print everything out. Everything is all good. So now, in our next example, let's say we want to pass sequences to her class itself. So we're going to do that in the following way. So it's a race this so C equals complex, and then we're gonna say are two attributes our fault as falls to three and 123 like this. So these are attributes, and then when we print them out, everything is fine and dandy. But, um, what, you're what we're gonna do later on? We want to, let's say, because if this is the case, if everything's fine and dandy when we had sequences that we could put anything here. So what's to say is you stopping you? What's to stop the user from in putting characters, which is basically know what this glass does? It's just it's a simulation of complex numbers and you can have other things other than floated integers as our past arguments. So what we're gonna do inside our constructor method, we're going to define some restrictions to our constructor attributes arguments? Scuse me. So we're gonna say if if, if the real component is not a integer or float then or if here s is here or if we only if or if that if the imaginary part is not is not the same same case if it's not in integer or float. So it's not a float or integer its not a type inch or float that we're going to say we're gonna raise the exception. We're gonna say, Hey, this is, um not a arcs were going to say Art is not Let's say our eggs are not numbers, so we're going to say, Okay, so you have two input numbers, so we're gonna build this. As you can see, we got the exception. Our guys are not numbers, and so keep that. Keep this in mind that try were gonna actually bad try back here. So this is good. It's good practice tohave try and accept statements because, um, it's generally good practice. And it's for the safety interpreter. So except exception, as he and they were in, say, print E oops. And we have, uh So here we get indentation, right? Oh, right. It see even defines the indentation errors. So there we go. And it got rid of all that error that lots of garbage text we didn't want. So now just has our eggs are not numbers, so I know when we fix this, it's pretty much so. Let's say this is too. And this is three for okay. For And then there you go. And that pretty much pretty much it for this tutorial we have to see next time. 52. 51 Class methods part 1: So now let's talk about class methods. Methods are special functions inside the body of a class, as you can see here as I wrote up here. So each method has the self argument as the first parameter, and we're gonna let's So let's see how this Syntex is written. So we have deaf deaf, and there were going to say, Get Prio self as our argument and they're gonna say Return self dot Really? We also do the same thing for the imaginary part, so we're gonna get maj so and they're going to say return turn self dodge. Imagine. All right, So what these are are they are inspectors or they're also as they're also called getters. So we can we can actually use thes methods by doing the following. So we we initialize Dorrance class instance. So it's a complex with the with the attributes arguments 2.5 and 5.2, and then we're gonna print and we're gonna use the actual methods. We just we just typed out. So really, and then we have c get a match, as you can see it auto it Auto fills for us right here. So we print it checks out. So we could also have two other methods we're gonna define right now. So So now we had getters, or inspectors, as we call them, were also not gonna have mutate er's course or centers. What? The's dude, They're used to change the value to find in method. So set to really in this case, we're doing the rial and imagine a parts. So when have self and Val arguments and these arguments? So we have the cell phone before and we had the new value. So we're gonna say we're gonna set itself. So we have self Dutch rial equals. How so? We did this for the realigned, the real part, and they were gonna do the same thing for the imaginary part. So self, perhaps not set. Really Imagine so. I am all over the place today. So said so self. There we go. Sorry about that. So we have vowed. Okay, we have valve and we have self. It's like that. There we go. So colon and all right, so we did the same thing. So itself. Imagine this time. Imagine equals about All right, So now we have our getters and centers or inspect inspectors and mutate er's. So let's define let's do this same code we did here but in a different way this time. So we're gonna erase this so see equals complex. So we're going to say just without any values past So we have si dot set real. So we're using this to change the value. Remember, we defined before that a zero initially. So we're changing the value. No. 21 And we have set you met all we could do Well set real. You could do either way whatever sets it to. And then when we print So we're gonna print this now print and then we're gonna say si dot get riel so get is used to return the value, as you can see in this code that's defined up here. So we get riel and we get he match. Oops, I forgot the parentheses. Like like in all methods, you should define the parentheses. You should not forget the parentheses themselves, and there we go. So some might argue that these methods aren't really needed. But later on, we'll see that this is in the case, and it because in object oriented programming, it's we should take care to control access to data. So the users shouldn't really be messing with whatever is in the class, because we'll see later on that we don't make thes values. We make these attributes private, so cultural. I'll explain that more in detail in the next tutorial, so be sure to tune in next time. 53. 52 Class methods part 2: so So basically, I stopped last time at the question. So what's stopping us from basically access seeing value in the class directly and like setting indirectly instead of using going over getters and centres well in object oriented programming, often times. Actually, it's actually practice of options object oriented programming to define, ah, variables that are used in the class as private. Because the user to you, the people of person who uses a class, shouldn't know what's going on inside the class, and they should be just working with methods and not the variables themselves. So now we're going to find all of the wherever you see riel and image the imaginary parts as private, which is done with the two underscores in front of the name. So we're just going to define were guys just going to add those two underscores in front of re every every time we see real in a match. So we're defining each sent each wherever you ever see it as private. So these value variables are private. Now let me just check. Here we go. All right, so I think believe everything is good here. Let me just do one last check. So self riel private returns off Rheal Self in Madge. So vehicles vow. All right, Everything is good to go. So an object or any programming, everything is private. So and then we're gonna add two more things to this. We're gonna add awesome, like restrictions. So we don't want the case where the user imports something that isn't it of the type int or float. So we're going to say in our set on our centers were going to say not in and or float furnace a raise the exception, And it's gonna say riel heart must be a number, and then we're also going to do the same thing for the imaginary part. Okay, so you just go. I never just seem to change this to who match. All right, so here we have these air sections. Now, we're gonna check for this. So let's erase this was due. I'm going to do trying and accept. So let's write this out. So we're gonna say si dot set for Rio and here we go. We're using a sequence this time, and then we're gonna say, except whoops, I am, except exception. And then we're gonna see as e and then here we go Print. Okay. As you can see, this actually worked. So and it's also like So this is how we should be doing things, not just going to programming so defined that your variables is private and have we have to be sure to have restrictions on what can be input. So and we're also going to the same thing. For as you can see, we cant access private values because when you make a private that can't be X outside and they're treated as not exist non existent. So see, basically doesn't have this because it's private. And that's pretty much for that example. So let's move on to the next example to help illustrate how to properly use API mechanisms . So we're gonna introduce some other methods into our examples. So let's delete this. We have all this from before, and now we're gonna use import imported module. We're gonna use the math. So here we go. Let's make some more, um, let's make some more methods. So what these methods are going to do there basically to into defined polar form of giving complex numbers. So let's define some Excuse me so we have get riel set real, and that we're gonna have after set before sets the center's gonna have define. We're gonna say they're gonna be called Get free. So we have get fee and then we're gonna also have define We're also gonna have, um, open. I should have said before that to be more organized, so we're gonna have deaf module so recently called defined. We're gonna call it get module ists. Have the argument self. All right, let's type itself. So what these do get module is is going to return. So we're gonna do math for doing module. We're using modules here. A square root so square root we're accessing self get to riel times, so dot get riel. And then we're do plus self dot kit. Imagine times we're in times self doctor. Get Imagine. So this is the This is gonna solve the module. It's of this part. So here we go. That's that Pretty long. But this is just an example. So, as you can see, I basically I'm basically making methods that are will be used to simulate the complex number. So, in whatever you're doing with the class, you have methods that have attributes and meth, and you have methods that reflect the actual real life applications of your object or your clad of the class itself. So now we're gonna do feet and in return, we have return math dot a 10 off two of self dot get image, Colin. And then we're gonna have sore eating, Tanja. Two of the falling so self get rial. And there we go. So it's actually clean this up a little, make it more readable. So it's also a good practice to make things more readable. Have have, like, a space between each fund, each method or function, whatever you call it. And there we go. All right. And so now it should work. So let's do the following woods. We're gonna define complex. Here we go. Complex. So minus three. Four, there's are instance of the class print. And then there were two c get See. We have all kinds of functions down, so we get module iss and then we also have see that Get fee. Don't forget your parentheses, and there we go. Those are answers. So we define the polar form of the given complex numbers. It should be noted here that we can call a method from another method. That is what we did in methods, get modules and get fee. We called getters real and imaginary of the Rio imaginary components. So we used other methods inside one method so we can use them within each other. So knowing this, we can have the following constructor. So instead of having this from before, we have the following. So we have you can. He raised this and we could say self, We can say so for adopt upset Riel Rio. And we have self docked said Imagine. And then we have you met and there we go. So basically, we went from what we did, doing it directly like this. Let me just see race all this instead of having it looked like this and directly doing it, we can do the following. We basically use the method to set these values in the initialization of an instance, and that's pretty much it for the example. We hope to see you next time 54. 53 Operator overloading: so as we seen before is possible to add two sequences or two strings is also possible to multiply a string by some integer. So if we want our class to use operators such as thes and on other special operators, then we you have to use operator overloading. For example, it would be useful if we defined an operator for adding two complex numbers like while using our this our class right here. This would also allow us to control instance variables without writing getters and centers . So let's dive right into our example. So I'm in right now for I'm gonna use operator overloading for addition or the plus symbol plus operator. So in order for me to add two complex numbers, So in order to do that, I'm gonna define a couple methods right here, and I'll explain what they are in the second. So we're gonna have death to underscores string, to underscores, or now itself. And then we're gonna have yeah, just self self attributes. So what this is going to do, it's going to do display a string of my result will explain more in details just in the sec . Just ride it out return string, we're gonna return a string of So we're gonna convert are get rial part of the number to a strain and that were contaminated. So plus with a plus to make the complex number form properly. We don't need spaces in there. You can eat it. Not we're gonna continue. Excuse me. We're going to contaminate it now with the imaginary part converted to a string. So we have yet in Madge, and then we're gonna we're gonna add now with an eye at the end. Well, I all right, that's that part. And now we're gonna Here's are overloading. Here's that part where that operator overloading comes in. So we're gonna make a method at for addition. So it's gonna have self and other. It's going to add two complex numbers together. So what we wanna have we're gonna return a complex number which is consist of self. The real parts connect consists of get the one get real, plus the other get riel, the other real number part plus other real part. And then we're gonna add the imaginary parts together. Let me just check himself, get you maj to us other. Yet you match just check that Trump's There's this attack, Sarah. See? I just like the check. 1 37 up there. I forgot the colon. Everything checks out. All right, So now with these, we can had them. We can add the's to these two complex numbers I made right here. Here. So we're gonna print, and we're gonna print a plus B, and that checks out. All right, here's the result. So in this example, we overloaded with the plus operator. That is, we define the addition of two complex numbers using this method right here. We should also mention the term method overriding in our example. That's this method right here for this string. You might say the operator overloading works on the overriding principles which is closely related to the concepts of inheritance. Because operating overriding excuse me means changing the implementation of a method which is given by one of the methods ancestors. So we basically used the values, get riel and getting match to display a string of our result and through overriding a class can copy some other class and modify it if required. So this method copy that used these as needed and has required and unpaid string. We'll also we'll talk about this a bit more when we get to the inheritance topic. But so in our example. But for now, in our example, we used overriding to print out the complex numbers in this but in the complex number in a specified format, without calling getters and centers. As you can see, we just returned a string. Now let's get back to the main topic. So other than the addition Operator, which is a binary operator, we also we go can also overload a wide variety of both Unitarian binary operators. And unlike binary operators, unitary operators are performed on one operandi only. So in our next version of our complex class, well defined some other operators. So let's see what we can do. We're going to make one's for multiplication and division, so we're gonna override here. Rio overload. Excuse me. Deaf. We're gonna do want make a method for multiplication and we're gonna have self attributes and self and other has our arguments. So now in these, in these two following methods we're going to define, we're gonna check if the other this value right here is an actual is a normal number or if it's a complex number. So if the type of other is in into or float, meaning if it's afloat or into. If it's a floating point over our integer, we're going to say Return. We're gonna return a complex number where the rial part is multiplied by this number there . And the imaginary part is also divided by this number. Other so from yet. Maj. There you go times Father. So But what? In the other case, we this is under the this other case assumed that the number will be complex. So we're going to return a complex number, which consists of Let's see, here we go self dot Get riel times other Other day I get real, my bad other get riel and the RAV minus the self taught Imagine times other dot get Imagine that's for the real part. And for the imaginary part, we're gonna have self stopped. Get in, Madge. Times other dot Get imagine. Plus so dot to get riel times other dot get Really everything checks out with that. So now we can actually do multiplication. So let's do that right now. So we're gonna print a new news New complex number. It's gonna be a times be lips a Times B and there's our answer for that. We can also do. We don't have to have another complex number. We can also just news number like two, and it works. So that's multiplication. And now let's move on to our division overloading operator. So let me just see escape that. Let's see right here. So this might is this one's a little more complicated, but you have bear with me. So in older persons of versions of Python division, overloading with division is done like this with just give, However, I'm running three python 3.5, so we have to use. I have to use true def. So be sure to be sure. Toe used true, defined not just Div one working in Python version three in Python version three. All right, so let's get this underway so self and other. So this one we're also checking for. We're checking if it's an actual if it's a regular number, or if it's if this other argument is a riel, a regular number or a complex number, so we're gonna do type if type other of other is an integer or float, we are going to just do the falling. We're going to return a complex number that is the following, so self so Yet riel is divided by five typecasting float. Other in cases in danger because when doing division, remember, you have to use you should use floating float because there might be a decibel number. It might be a decimal number and not an integer. And the imaginary part. It's going to be self duck getting mAj. Divided by float Same thing as before. Flute of typecasting. Other other type casted to float. All right, so it's just just that Yep, everything checks out. All right. Now let's go on to the next part. So we're gonna have the else statement now. And this is where we assume that it's a complex numbers being other it This argument is a complex number. So here we go. So a we're gonna have We're going to set a couple variables set equal to some parts of the complex numbers to make their things more simple for us. So a prenup A a, B, C and D, respectively, equal to the following. So self get riel calm myself dot getting Maj come. Oops. Come on. Other dot Could get riel comma, other dot kitsch. Imagine, Since we're dealing with division of complex numbers, we have to set a nominator. So nominator is going to be equal to the following. We're gonna see time, See, plus de times D. And now, with with everything set up, weaken return following surgery return a complex number, which is the following. So it we have a times C eight times. See capitals eight times c plus. Let's see, be times d and then outside that were divided by nominator. That's our real part. And then common. The imaginary part is going to be the falling It's going to be B times C minus eight times d space that out there we go and divided by nominator plus check in Mount Syntax. Just checking my steaks right here. So I forgot a parentheses. No, something's missing. Let me just check Complex. I mean, I need another one. No. So I opened one up here. Here we go. Just Always remembered. Always check your parentheses. Yeah, There we go. So now that all checks out. And now let's see how this division works. So let's do a divided by B. Now spacing was weird. A baby and that worked out. And now let's do instead of using a complex number, let's do, for example, be divided by two in that checks out. So now we're to find two more operators in operator overloading, and so that in this with this we conclude this tutorial. 55. 54 Class inheritance part 1: At the very beginning of this chapter, we learned that there are four main principles in 00 P. And this, too, in this tutorial will learn about that third principle we talked about, which was inheritance. Inheritance allows us to define classes which inherit most of the properties of our existing classes and which can be used in all aspects in which the existing classes can be used. So that might sound a little confusing. But basically to buy that into a real life example. Have the class. We're going to find a class called vehicle, and then we're gonna have a later on against you class called Khar. So logically a car is a vehicle and a car has all the attributes of vehicle has so inherits the attributes of a vehicle. What, you'll see you as as I type one that I type out this example. And the fourth example, the fourth Excuse me. The fourth concept is close related to inheritance, which is polymorphism, and but polymorphism is is the ability of an object to adapt to the type of data it is processing. So you'll see that later on it will be more clear in the example. So let me just jump right it. Let's just dive right in it right here. So we're gonna have We're gonna find our vehicle class. So we're gonna have the in constructor method. Here we go, Self. So here goes. So then we have a couple attributes here manufacturer. So you'll see in the car class, you'll have these similar attributes, but you'll have other ones added on because because what this is gonna turn out to be the the vehicle class is actually a base class, which is which is also is or it's also called abstract class. In all based class methods are virtual and can be overridden in in the inheritor class. And we'll demonstrate overriding with the method vehicle type, which will see just in a sec. You'll see that in a little bit. So let me just type of cell. So we have. Then we have self dot Uh, wait, Nichols wage. Now we have. Lastly, we've got manufacturer ukuleles manufacturer. We're also gonna have our getters for the vehicle class, so get which so return. So basically define your constructor method, then you define the getters. And if you have any centers you to find those as well. But they should. Um it depends on what your classes being used for. All right, So we have self not wait. We have different Define get to Manu. Get manufacture. Were Yeah, with the app. Attribute self on return and ask. You see self. Don't try menu. There we go. And now we're gonna have this vehicle type, which is going to be overridden by our car class. So studio vehicle type self. And there one is They just passed. All right, so moving on now, we're gonna So this is our base class or abstract class, and it's gonna you'll let me just write out the car class, which is going to inherit attributes off the vehicle of us because a car is a vehicle. So here we go, the parentheses, you see, vehicle being that's the inherited class, some deaf, And it we're having our constructor method again for about this Hypercar hopes. So. So then so some live Texas on a complete feature, which is really handy for thing. Situations like this kind of saves time and typing all this out. So but now we're gonna have are, um, seats. Well, have a seat attributes and as you that's not in vehicle, but its in car. So inherited classes inherit from an absolute class can basically add their own, have their own on attributes. But you can't really have vice versa because there wouldn't be inheritance in alright himself. Spin self that weight couples wage so dot Now we have a seats, not self seats seats, and they're gonna have self What's our last one manufacturer? Right manufacturer he calls the manufacturer, so All right, let me just clear that off. All right, so now we have our constructor method. Now we're gonna define some getters. So he have If you notice here, I'm not naming Get seeds because this might reflect the actual in actual real application of this class is method in real life. Yeah, I kind of those kind of redundant but whatever. So So, Yeah, I just named that number of seats instead of get seats because it might reflect a real life application so deaf and we have vehicle tight. Now what you'll see is gonna be overridden, which is going now going. It is now going to be car the turn return. Now it's gonna say car, and now we're going to the same. We're gonna apply the same sort of situation or just gonna copy this and change a few things. So because truck is pretty similar, But instead of seats were gonna have, uh, attribute called capacity. So instead of seats capacity, here we go kind of taking a shortcut instead of typing out loud. But it saves time. So let's have a number of seats were going to say transport Capaci, and we're gonna say return capacity. There we go. And the type now is truck. So this example demonstrates inheritance, as you can see on when I keep repeating myself. But it kind of helps me memorize it that the we have inherited attributes. Cities are also found in the base class, the vehicle class. And now we're gonna go ahead and demonstrate polymorphism. So we're gonna to find demonstrate this through mechanisms of ritual methods in which we will use fictive values of attributes for testing purposes. All right, so let's do that a car. So we have a car we have instance of the class car, and so we're now it's gonna have attribute ABC 1000. It's gonna be a BMW, and it's gonna have seek See its four that we're gonna have one on a truck now. Classes of a truck. It's gonna have be, uh c b c d to And they have Excuse me one day, tribute 1000 it's gonna have is gonna be a man. It's going to be And the capacity and the capacity 10,000. Next, we're gonna see cuz they're just random examples. You don't know the real life examples, but in a real live application, they should actually reflect rial life things objects. Alright, If the f 3 1200 and afford it's gonna have four seats d it's gonna have it's gonna truck truck E f g four gonna have 11,000 for the wheat. Could be a Mercedes and then have 30,000 capacity. All right, so now let's test these the implemented classes. So we're gonna print and there were not a dot as it's gonna have auto fill now with get weight. That means everything checks out is everything is all good in a same thing goes for B and we're gonna get the manufacturer of B. Here we go. They're gonna have we're gonna have the man you now we're gonna have What do we have next? OK, we have so for C. We're gonna get the number of seats and for ah for D. We're going to get the transport capacity. There we go. So there that's started. Return a test. This out and truck is not defined home on a sec. Oh, silly me. I forgot the change. It's Ah, class Name truck. Oops, There we go. So that pretty much checks out. And now we're going to see the polit on Miller A polymorphism, which is gonna look like this in a print. You know, we're in a for loop now, so four v and sequence A, B, C and D and we're gonna print out. But following we're gonna print out every for every for a, B, C and D. We're gonna print out the many if we're gonna get the manufacturer and we're also going to get the vehicle type and that works out. And this let this last line is from before So would see race that I go. And there there's our answer. So and at this point, we have demonstrated most the concepts of object oriented oo p. I have joined a p 00 p object oriented programming in python 56. 55 Class inheritance part 2: Now we're gonna talk about some class specific. He's in Python Python. There was ah, sort of abstract abstraction called Property, which, which looks like this. We're gonna type it out like so we're gonna We have our complex class from our previous tutorial, and we're gonna have something called property right here. So Rio, the rial parts on equal property property Hand's gonna get riel and is going toe have set riel. And then we're also gonna have one for the imaginary part called Sana's property. We're gonna have getting Maj. I'm gonna have set a match. All right, so we also have another thing in here. The complex class is gonna inherit the object class, which is the class more class object. The glass object is base is the base class of all objects and use thus far and allows us to modify and the property, which is that so object? It is also possible to use the property as a decorator, which is a kind of more correct way of doing things because it sticks with the python philosophy, which is, um, the python velocity of there should be only one, and probably only one obvious way to do something which is not the case with our previous code from here, because we can instead of direct access to answer various, we could only use gathered and centers in that contact. Sorry. In previous, in previous our previous examples, we could instead of having direct access to verily use, we have to instant variable and variables that is, we can only access the from garden centres. But here this is a sort of called the What we're dealing with here is sort of it's called a new style class. And this was introduced Inversion Python 2.2 and classes prior to that were called old style classes. And it should be noted that Old South classes are removed in version three. So our new style class complex looks like the falling. This is a new style. So let me try to build this, huh? Next incursion, Not you. So apparently, in this version, it's not really working. So perhaps there was some kind of area. What so? But that's pretty much it for this. So new style classes have falling property and object inheritance 57. 56 Extra notes in python: So in our previous tutorials, we learned the main principles of object oriented programming in Python. And this tutorial will go over some other important concepts. Now, if we want our class instances to have a comment, some common information about something, for example, a number of currently. Instead, she ated objects in the running program. We can achieve this through a shared variable. This is almost equivalent to a static variable and C plus plus for those who are familiar for, I mean for those for familiar for the problem in language. Anyway, in python, using the shared variable communities use as follows. So what's can't escape that? All right, so we're gonna make a class called student. Oops, A student. All right, It's gonna be called student. Actually, let's not use this class student. It's going to inherit object object Plus and then we're going to say the following. So quote, quote, inch quote, quote and the number of students attributes this is our share. Illegal zero. They were define our constructor method for here we go self so self name and index and they won't have self that name. He calls the name Self dark in New York City schools Knicks. And then we're gonna have our shared variable right here. So student dot number of students plus equals one. So every time we instead, she ate a new student. We will add number students. This will increase by one. So let's to s one equals student. We're gonna call him Python High Cost Python ski Icahn ski and he's gonna have index 12345 and we'll have another student vehicle. So student equals Greedo. Vote Van Rose. Um, it didn't really have 35 67 So now we can access the share variable in the following way. So we're gonna have a print, and then we're going to say so we have print and we're gonna say student dot number of students. I want to say s one number of students as to dot number of students. And as you can see in all cases, in all instances, it's too. So another important concept in a low P is a destructor. De structures are great of great importance when comes to memory amendment memory management. An example of this is when we use the operator, the falling operator. It's called D L as you can see his highlighted in pink delete. For example, if you want to delete one of the students and print out the number of students, we will see the result. It is incorrect. So we're going to do this. So we have our initialized students sentences and we're gonna say delete. I'm gonna say delete s one. That's one that we're in a print now. The number of students number of students. As you can see, it's still too. But we deleted, one showed should be one. So the purpose of the deconstruct er is to release the resource is and ensure the adequate functioning of the program. The destructor for our class should be dick from a deck Ament. That should Decker meant the number of students when a student is deleted. So we have to add another method in this case, we're gonna add, So we're going to define a new method is gonna make for D l. And we're gonna say self, and that's going to be students dot number of students minus equals on. So every time you use the destructor is going to determine this value. So now when we actually do this it's going to be one, and the structures are mostly used for memory management. However, in Python we don't really have to worry about this because there is a Mexican mechanism called the garbage collector, which is used from engine memory. That's pretty much it. 58. 57 Visualization, Object, Libaries, Patterns, Other Topics : in this chapter, we'll talk and learn about visualization and python. Through our examples, we'll see how we can use data visualization. Since there are lots of libraries that were that we use for visualization, we will not be able to cover them all. But we'll cover the basic and most used ones. So the most the basic one library for data visualization, visualization that we use and python is Matt plot lib. And next to it, we have other ones like this B book A Seaborn Pie, Golfo, Liam and Pandas. I hope I pronounce this correctly. So in the next few tutorials, we learned how to use some of these libraries. But first, since we're on a 64 bit Windows machine, we're gonna have Teoh do a couple of things. So in order to install the map plot lived, life does map plot led module. We're gonna have to first. So we're gonna head on over. Actually, First, Teoh, we're gonna head on over to Google open our Web browser, and we're gonna find Matt plot lib, and it's gonna be the first link already clicked on in here. So we're gonna head on over to Matt plot live installation instructions. And there's a couple things we're gonna have to install. Basic. In my testing, I had to install the following. Um, excuse me. Um, since we're have a standard version standard installation of python, we're gonna have to install some other modules we're gonna have to install. So this, if you can see here, hold on a sec. Enough install set up tools. Numb P python date Util, P Y tzu pipes, pipe arcing Eichler and Matt Plot lib. We're also gonna need visual C plus plus three distributable for visual studio 2015 to be installed to. So first off, we're going to stall these other modules, and I'm gonna show you how to do that right now without having tax research for them on on the Internet, because you might get confused because aren't exactly installation files like like e x c execute herbal files to just open, unpack and open. Well, there might be, but this way I'm doing is because basically cuts out the job of actually searching on Internet for them. So we're gonna open our command prompt, and we're gonna keep this open for later. So let's minus this gonna keep this open for later. And now we're gonna find all this is how idea you don't do this way. This is just how I find it easier for me. So we're gonna find the python, the python. Um, full directory folder where? And it words located. So we're gonna open python 3.5 far location. We're head over to the scripts folder or going open it and see where it says Pip. That's an application used for installing modules in Python. So we're gonna copy this directory, and we're gonna paste it into our, um there lot, right click kind of automatically paste. So we're into another slash, and they're gonna do pip dot e x e. So Pip has a couple has his own command. So we're gonna do help. Um, it's not help. Whatever. So we have a couple of commands and, um, Pip, do you have but for the one we're gonna use is actually install actually forgot the syntax for help. But we'll just do this. We'll just keep it simple. So when Pip, you have the command install. And after that, the parameter you have two input is the module. You want to install. So first we're gonna try installing Matt. Plot lived and oops. Why is it not doing out? Oops. I forgot something. Hold on a sec. Mm. Five. Maybe. Well, on should be working. Oh, there's a space. That's why, uh So it's gonna run the install, Matt, pot lib here. You see, As you can see, it keeps going. So well, that's downloading. Um, I'm just gonna explain. So we're gonna have to do the same thing with set up tools. Numpty, python, python, date you till so on. And then the sublime text will be able to import any of these modules because it will be installed in the system. And I'll show you how to confirm that they're installed in a second. Just let this download. So basically, on windows on Windows machine, you won't work without the's other modules. For some reason, I don't know, in a lot of other python versions is automatically everything's a lot of things are automatically built in In version 2.7, you'll have might have some less. You last less problems, but it's going to see it's actually it does everything by itself. It actually retrieves the module before you. As you can see here, we achieved this file and it's got on packet and this tall everything for us. So this is kind of easy. Simple tool Teoh, install modules and python. You also have a bunch of other commands and pip like you can see what you've downloaded. You can search on. You can search what modules are available. Well, maybe I'll show you how to do that, but it's not really needed for this. Some tutorial. So we're waiting for it to install. It might. So maybe we should have done the other ones first, because this one's rather large. But, um, let me just so we just keep on waiting, basically, until it's all good, everything is done. So there we go. Oh, and here is our, um, error. So you might come across his air for Matt. Plot lived for some reason. It does this with Matt Plot lib and not any other. The modules that we need for this some these tutorial, these tutorials that are coming up for some reason, it gave us era coat. I tried figure it out, but, um, I couldn't really get it to work, but the solution I found is we have to install the wheel files. We'll get to that in a sec, but were first, we're gonna install all the other. We're gonna stall all the other modules ahead of time. So let's install set up tools. And if it says if it's not available, you have to, um, I believe it looks like this instead, with the underscores set up tools. There you go hopes when we just see what it's called Han set up. Is it like this? Maybe with Dash? Yep. There you like, Could not find requirements. Set of tools. Um, let me just check again what it's called. So if you're not sure what it's called, you can you could sort of just look what the packages called. So let's see. So this is how you basically do in selling packages. You just have to find the sort of here easy set up. It's called, uh, you go easy. So hopes it's a capital, so we're going to start a couple modules and if it if it checks out, says collecting. And it says XXX successfully installed. So now we're going Teoh. Let's see. Oh, for I for I kind of skipped this. So if you already have something unsolved, it'll sort of say, already satisfied. So we're gonna keep going ups. We're gonna keep going and doing We're gonna do these packages. I might have installed some redundant packages, but it's OK because you never know when you might need them. So we're gonna do numpty. It usually is. This the latest version see, collecting number usually gives you the latest version. Some of them are relatively small. Some of them are a little bigger than others. Really depends. And this is just a pro waiting process, really. Just install each one one by one, and you basically just wait. So that's installed. And we're gonna do the same thing for the fallen were going to say for python date you till So we're gonna do python date you till you Teoh. There we go. We're also going to do the same for P Y t Z and ready to the same for pie parsing. So you just do the same pie parsing How's it is their underscore? No, that's good. So you just do that. Hi. Parsing. Then we have cycler. All right, so basically gives you If you want to update Python, that gives you the tips on how to do it. And we're gonna do Matt plot live one more time. See, Matt clocked lib. And if you already have a download, it'll just use a cached copy of it. So, um yeah, so you don't have it wont download again. It will just use the cash copy of what you dabble in before and then you It'll try to distort again, but it's probably going to give the error again. So we're going to fix that in a second. We're just gonna wait for it. And Well, in the meantime, let's download visual redistributive ALS for visual studio. You just click on the link, and it just redirects you really often times like the download both. But in this case, I found it. It works just with a 64 bit. So we're gonna do that. So we're just gonna wrote save the file and wait for it two down mood that, um so we're just waiting. All right, so this is basically just a waiting game. It's not really anything fun, But Tom, it's essential to actually getting the surrounding windows on the Swint Windows machine. So you just install that to you? Close it. And of course, you have to restart sublime text. So we're gonna we're gonna start close. That, um minus this. For now. Minimize it. Um, maybe we'll need this for later. Let's see when. Sublime text. Well, that's still going of So what That plot black pot live is going to do is this. Libraries allows two D in limited three D plotting. It can also be used for simple animations. Now, the installation, like I said, is relatively simple, like with the things we just did. Like, almost all new interpreter versions have already happened, but we had to do this way in on windows. Um, you can also find this life you could find this live very on. It has its own website if you in case you didn't see from before. So we have Matt plot lib dot organize its own website and everything you could look at like installation tips and everything like that. I should have said that before, but anyway, so we'll be focusing on this library because lots of other visualization libraries are dependent on this one. So, like I said, It's pretty much one of the basic, most basic and most used ones that we have. And you can do things like Instagram's pie charts and other kinds off data visualization. So this is done yet this is taking a really long time, so we're just gonna have to wait. But, um see? So if you were gonna basically be importing these modules, this is taking a really long time. Can we cancel? Okay. I canceled it because they're ago. So we're gonna have to install something is called wheel to fix. This is this is going to stop what this does. Installs the wheel version. The files. I can't I don't really have time. I don't Really. So they I don't really have time to explain wheel, but, um, it's going to sell the wheel version off. It filed a of the whatever we install now. So forget do Matt plot lib. It might do the cash. Copy that. In that case, I'm gonna have to erase the cash, so we're going to have to install We're gonna have to clear the cache. Let me just see if this works. Matt, plot lib dot W h l No, it doesn't work. Oops. I forgot the install on. Yes. So, um, you could find the names manually, but usually, So let me just see how is helping command in this? Yeah, here we go. So we're gonna have to find a command that, um see if you see Well, Bill builds from your build wheels from your requirements. So let's see, We're gonna have to clear the cache somehow. So here we go. So we're gonna do no cash and, er, and that's not working for some reason. Oh, we need two lines. Okay, Now, let's try the wheel. Let's see through this. So what we're going to do is installed amat plot lib, Matt, clot live. And it's still not doing it. So cancel. But anyway, so in the next tutorial do this because we're running out of time. It's been kind of a long drag down anyway. So what? I like to do it Just use, like something like, see, clean or just clear the cache, and then do it again. And it does. It does it for me. So we'll see you next time. Okay. So just Segway off from the last video. I kind of made it. I made a mistake with the sea cleaner. So you don't have to really clean the cash anymore. You just have to install the new version off Pip, which is done by just doing the falling. Let me just go up here. This was I was testing some things. So you write in your Pippig E X e installed two dashes upgrade pip and it should install the new version. And then once you do that, it will finally install the wheel file. Now, in the new version of Pip, when you install Matt plot lib, it'll do everything for you. So this was in the older version of Pip. Which version was it to be exactly? Can't remember home. Let me just go back. It was version 7.12 0.1 point two and now it's version 8.1 point two. So now in this version, it will automatically do everything. Four years. You can see here so you can kind of just disregard the steps from before. So anyway, so now that we have everything installed, we can close everything up. Close all these taps. I think I use I also you stack overflow guilty. Guilty as charged by the Let's just get on with the programming program here. All right, so let's delete this. So we're going to just close that. What? We're start sublime text just in case. So elements of, like, text again. All right, so here we go. So, first off, we're going to begin by creating history. Graham, as our first example, hissed. A gram of feed, in case you don't know is a graphical representation of numerical data distribution. And we create will create a history. Graham, using Matt played live various follows. So let's import, Matt plot lip dot p I plot, and we're gonna use Alias as p. L T. Important this library and giving it an alias is basically this for the purposes basically , for user usage and p y put the P I plot module is a set of functions used for plotting. So and plt this What we're gonna do right now is creative a new figure. Object now to start off so well, say fig equals p l t dot p y plot as weight. No hopes I'm reading rock on as figure. Pl why Or peel? Why? Why did I write this So we're gonna do is supposed to be plt my bad. So p l t guilty dot figure, and it's gonna mean quotes hist o gram. All right. And now it's necessary to create one or more subplots by calling the ad subplot methods. So we're gonna do a x X fig ducked add subplot, and they won't have our arguments. 11 and 31111 And now we're gonna create the actual history. Um, so a axe dot hissed and in quotes. So one creating hissed a gram. The first parameter is a list of numbers that are within a certain range. And the second parameter is the number of bins to be created. So to owning one of 2112 Ah, 23. Let's see what else 23 35 45 60 33 22 56 34 28 40. And for you one. And then after this series, we're gonna have been this argument Pins equals 7 77 All right, so now we're gonna be setting the title than the labels on description and actually enabling to be able to show to figure so, plt dot title and it's gonna be It's gonna say distribution. Then we're gonna have peel t dot x Label is going to be a lumps of coal in range. There were no appeal t dot y label. That's a slash why label while able amount should be capitalized amount Epsom earned amount and that we're gonna say plt dot show It's its own function and that shows the figure. So note that there are another two parameters that could be specified on creating a history . Graham, those parameters are called normed and face color. So these two face color allows you to set the color of the hissed. A gram normed has two values will be doing that. So we're gonna right? I'm here, so we're gonna have face color. It's gonna change the color of this diagram, and we're gonna say are for a red and then we have normed. It could be either true or false. Now, what Norm does by default is set to false, however, have to set to true then the values in the history more normalized, that is all data is in the range between zero and one. So we're going to say for this example. True. And if you'd like to explore the visual ation history, miss more in depth. You can check out the plot Lie library, which helps it's called plot plot Plot Lee or plot Lie. Whatever plot lie to check helped create different help. You create different types of history, grams. So let's build this. We'll see if it actually works, it might take a little bit up. There we go. There's Artista Graham, see as you could see his red and it's normalized right here. And if we change us the green, for example, say G, that works. We're going to say false be. And here we go. As you can see, it's not normalized and it's green. All right, moving on. So our next example is the box plot diagram so can erase all this if you build every If you keep going with the code you'll be building, Um, well, when you build that each time you close the next window, you'll see in a second. Actually, so our next example is a box plot diagram is used in statistics for the graphical representation of numerical data. If you're not familiar with this diagram, please feel free to look it up on the net. For now, all you need to know is to create this diagram is that it consists of the following sections minimum first quarter median third quarter in maxim elements of the given data list and you will will be defining. You'll be seeing you see how this looks. So don't worry if you're kind of confused, so fig two equals plt dot plt plt figure I am parentheses. The type of figure is gonna be box plot. So capital be lower case p that creates the figure objects X ax. One different variables now. So we're safe. Fig two big to auto current hole fills. Add sub blocked at some plot and they're gonna have 111 and they won't have acts one. So you're raising, creating figure, adding some plot and then plotting and out. So now we have box plot instead of hissed. So box blot. Nope, no dashes or anything. And we're gonna have only one perimeter, which is just the Siri's. So we're enough. 21 tulips. That's a period not 2112 18 23 35 45 60 30 Actually, are we using the same you have arrested needs the same parameter is why not just copy paste . I'm kind of just doing this robotically, so they're save us some time and then we do plot show plt dot shell. There we go. And once we if you since we have two figures want you close the 1st 1 the 2nd 1 will come up. And there you go. So moving on, what's that? Was our box plot and now our next example? Well, actually, I should say it's possible chase orientation of the diagram as well as plot as as well as plotting all the values from a data set in our next example, we're showing you how Teoh comparison values by creating diagrams. So now we're going to use a bar sort of a bar graph figure bar graph what we call so fig three equals peel tea, doctor figure and the parentheses bar. And then we're gonna have a X two equals fig three. Don't add some plant ones X to adopt set X label. So we're sitting labels now X going to the same thing for the UAE label acts to said Why label as, um why in acts two lips, not three docked to set title. So we're setting the tail. Everything set lower case letters titled and it's going to be eaten bars and then we're gonna actually set the bars now. So a X two Dutch bar. So we have several. We're gonna have several Siri's so you're gonna have four arguments now. So the only difference here in regard to the other examples is that we're plotting each value separately in the first list. Values are on the X axis. In the second list, the values are on the Y axis. And in the third list, the values are the width of the bar graphs. And the fourth parameter is the list of colors. So we have our 1st 1 first list to three, and we're gonna have 5 10 15 5 And then we're gonna have the woods, um, 0.511 point three and one, and then we're gonna have our color argument. Kohler equals in square brackets B and then read our all right. And then to show this, we do plt dot show dairy. Go. That's our 1st 1 That's our 2nd 1 And what was? I forgot the parentheses So the 1st 1 A 1st 1 2nd 1 And there's our 3rd 1 As you can see, we have a red and blue ones. All right, moving on. Now we are going to do a line graph, so let's do that. So fig four fake four equals fealty dot figure figure. And this time is gonna be line capital L. And they say ax three now equals fig four dot at subplot. We're doing the same thing here, so we defined what kind of figure it is. Then we had the subplot, and then here we're gonna have the Range X and y Axis is axes, axes, AEA, axes. And then we're gonna say set ex limb two, we're gonna say our coordinates, so it's gonna be minus two and 10 and that for the why one were so so going to say, X hopes I don't need That's not right. It should be adopt X three dot and then accessories acts three dots. Sit said Excellent. We're going to set. Why limb now to So we're just making basically making a line graph. It's pretty, adding the limits and everything. It's pretty simple stuff, but if you want to learn more about the directory of That's right. So if you actually want toe foreign what all the light would all the details on which all the commands you have? You should prefer to the documentation of this library. So acts three. They're going to set. Why label X label first and say ex? The one said the Why label acts three set. Why leave? Will said want until why? And then we're gonna say the title said Title and this could have call it lines kind of my lines. All right. And then we're in a plot it out. So in plot, this time we're gonna have, um, the following. So we defined line site within the fine line saying that's in two D space and the first list specifies all. I just said this already. So it should be noted that in the examples in this example, we define lines that go through two points. So for endpoints, we will have end minus one lines on the graph. In case we passed only one list as a parameter two x three plot, then that is is considered. Then that is considered as if x the X axis excuse me, has values from zero to number, some zero to the number of plots that are given in the list. So here we have and number of points, then we're gonna have n minus one number lines. So what's so you're gonna see here that, um that Ah, the plot is gonna look different. It's not going to be empty this time. It's actually gonna have some parameters and have a list of 1 to 478 and then we'll have another argument. It's going to be 5234 three, and it's gonna be colder. Red are all right. So what's and then we're gonna have hopes. I made a mistake. I was confusing it with show. So plot is gonna have its own. Um, it's Ah, it's never mind. Just forget what I said about plot. I meant to say show, but show is not gonna change it. Also, we're just going to say plt show and that's it. We go next. There's a 2nd 1 There's our bars and there's our line graph. So our next story girl wants to be comparing values. We will be put our values in a dictionary for ease ease of use. So first, we're gonna have set a dictionary, data an organ, open our dictionary, curly braces and want to say player. And we're not of falling. So all the falling are players we have. It's your single quotes, actually, Wade. Oh, basketball players. James, LeBron James. Kobe wants to be Bryant, but whatever. And Curry. All right. And then we have the following Were enough the term first with the following. So we have corresponding values. 10 10 8 12 And then So we should. It's a good practice to the following. Just going to space it out to make it look a little better like that. Space is air kind of ignored. So next we're gonna say second now, second and the foot. The following scores Go soared. 12 8 13 8 All right, so moving on, we should out spaces. Do it. All right, screw the spaces. All right. So moving. Next we have the fall, so I wouldn't have third this kind of a boring process, but it's essential to this example. So homes third. So we're gonna have 15 15 12 age eight. All right, Next. Then we have the final on fourth fourth can't spell today. All right, so 18 20 15 and eight. All right. And then after that, we're gonna create the figure. Now it's gonna be called stacked bore. So fig five equals, uh, plt dot figure figure and is going to be called. This was going to call now Stacked bar. What's your single quotes? Just to make it nice. All right. And then we're gonna add to subplot like always sue x four, is it? Yeah. Acts for fig five dot Add subplot. 11113 ones. For now, we have a parameter called bar with which a variable that holds the width of the the width of the bar bar with equals 0.5. And now we're gonna define the positions of the left boundaries at the bars. So we're saved bars. He calls I plus one for I in range of the length of date. Uh, so wherever the data is in the dictionary, where first, the values of first first, right? You know, and then the middle bar of that on the X axis is used for dash plotting. So we're going to say ticks. EU calls I plus in parentheses. and far underscore with divided by two for high in horse bars. And then we create the first layer of bars. This is kind of a long process, but you'll see what it looks like at the end bar. So we're gonna have bars. Is the bar positions we're gonna have with equals bar with? That's the bar. Wait. I forgot one. I forgot up parameters. So data and we're gonna have first in quotes first. So this is this is ah, creating the first layer with the scores of the first. So we're setting bar positions. We are setting the bar height in the bar, wits in the bar label on the first layer. So we're gonna have no label well able first quarter quarter and they won't have the color . This is the hex value. So hashtag a for 5439 is it just example color and hex value. Excuse me, and that we're creating the second layer, so it's gonna look at the following, so x four dot bar It's gonna be bars. And the data now is going to be second data is now second second with with you calls of our wits, anyone have a thing called bottom of prime medical bottom. Now it's going to have data of the first quarter. First I forgot the Colt commas here. That's not good, Comma. Come on, Carmine. Comma, comma. This is a long drink on process. I apologize. But So, for example, if the first is 12 in the second is to three than the first bar on the second layer will go from 1 to 3 in the second bar to the second layer will go from 2 to 5. So this might sound confusing, but just, um Well, uh, lets us write this out first of second quarter quarter, and then the color, uh, f f 2600 and close on. Let me just check. I don't need this common here. There is ever done. It hopes that's good. There we go. And now we're gonna create the third layer bars. All right, so let's do this. All right, let's see a X four bar bars. Let's see. So bars data in the third quarter. Partner third data and the third we'll see state in the third with equals bar with common. Don't get your comments here. Common the bar with the bottom equals, This is kind of complicated now, so we make a four loop here, so I plus J for I j just starting points of the second layer bars. And the bar is this is a starting point in the second layer bars? No. So in no, in zip data first, uh, date, Uh, second, right? Yes, that's good. And then all this close in square brackets. Check. So All right, Next. So next we have the label once again. So as you can see, there's a pattern we had to live with. The bottom label on color label. Um, it's called, I believe Bill vehicles. I didn't turn in great or whatever. Label is now the third quarter. And then finally, the color once again equals Oh, I forgot the clothes. That Why is there a Oh, whoops. That's why. Do you, uh uh, just check these parentheses is going to make a problem for me later. There we go in extra. All right. There we go. That's fixed. All right, color. We're going to say F 9 to 00 All right, so now we create the fourth layer. This is painful, you know, But um, we'll see what it's data visualization is. There's a lot of parameters to go through, especially when you're doing comparisons, because the other do one for every single, every single set of data. So data now for the fourth and final air fourth can't type today. Fourth, Ah, wits again. So there's a pattern you had due to sign Which data set of data you're using from the dictionary. And you do set the bar with bar bar positions, the bar high in the bar with and then the bottom is going to be bottom equals. Now we're in the house three variable, sort of I plus J plus K. So we should keep that open in the four loop now. So for wait for I J. K. So now we have some of all the previous high it's and adding the fourth layer. So this is what happens in this for a loop. So I plus J plus K so that some for all the values in the following and zip of so we're gonna have in zip and parentheses data. So for the first for their all the other first. And they weren't having Teoh data in second. So the sum of all the values from the previous ones. Second second. Okay, data from the third. And don't forget your commas at the end right there and then last but not least, the label again. Fourth, fourth, quarter, quarter, quarter and then color finally color are So now we're gonna set the labels of the player names on place ticks in the middle. So this is done in the falling weight. We're going to do peel t dot ex ticks. It's its own function. It's called Ticks Data Player. So all of from all the players, and then we're gonna set the axis labels. That's why he's doing this escape. Alright, X four axe for dot set X label as total total. And they want to set. That is the why label set boy label as player, and they want to make a graph legend now. So there are a lot of parameters you have to consider when making a graph. So you have the legend. You have that labels. You have the actual bars. Yeah, the actual image, actual model figure my bad figure. Upper. Right. Then you have the X about X axis ballon trees and also appeal t dot Exe limb. And then we're going to say it is minimum of ticks minus the bar width, and the other parameter is going to be Max of the limit is going to be Max ticks plus bar widths. All right. And then with that done, we're gonna finally hit Show the graph after So long call, right? There's a syntax error first. Of course there is. Okay, so 37 1st 1 is now it's in tax. Let me just check O Connor, of course. And in another incident, Xterra. So the same thing. Oh, forgot the Commons and every single one c Don't forget your commas. There's another syntax error. So line 56 c. Basically, this is a real programming. You're just finding mistakes to go through. And basically I forgot a lot of commas. So 63. I also forgot the comma after it before the color. And another common ever. Let me just say 68 bottom that you go wide 75. Let me just see Line 75. It should be minus. And finally, after our whole or hole or hard work. We have a name error peel are 71 and it's we plucked. Finally, it builds everything from top to bottom and there are fine hole. There's are four layers we made with the labels Fourth quarter, third quarter, second quarter, first quarter, with our colors and our ticks in our player names, and everything seems to be in order. So next time this has been going on quite a long time now. So next time we're going to do two more examples for you to the scatter graph and pie chart . I apologize for beasts taking so long we hope to see you next time. Okay, so now we're gonna just We're gonna continue with visualization. Visit was a visual ization of data and python. So now we're just going to two more examples. Just this tutorial. The 1st 1 is a scatter graph. So we're gonna do the same thing as we did before we're going. Teoh fig said our figure name Figure six this time plt dot figure, defining the figure object as scatter. And then we're gonna have acts. Five equals now, fig six dot at subplot like we did before. So we're defining the figure, initializing the figure, adding a subplot some plucked with three ones. And then this time we're gonna have the function called scatter. The first parameter is the values on the X axis. So our first parameter is minus one zero 235 in their second parameter is the all the values on the Y axis. So we're gonna have to 13 to 0 a 0.5 my men on 04 and that's their er and that would appeal . T does show. And there we go. There's our scatter graph, though. So if we modify our scatter graph by adding two more parameters on one is list and the other is color, then we get ah, bubble graph. So we're gonna do the following. So we're gonna have a list here. So he Rio 1 20 203 100 1 53 30 And they're one of the colors of each bubble Read. You can do it with letters are for red G for green, and you go to use the Hexi decimal values unquote single quotes. Hashtag bc D f zero This is that hex value. You don't have to do it like this. This is this more technical on more specific way of doing things. BB 5500 So to recap, values on the X axis is the first argument. The second argument parameter for argument What every calm second parameter is so valued on the y axis. The third parameter is the bubble withs, and the fourth parameter is the bubble colors. And then we're going to show this. As you can see, we got bubbles. Now, now we can play with this. Let's take this 1020. She gets bigger Bill C 2000 4503 100 so you can play around to get bigger bubbles. All right, let's put that back to normal. All right, So our last example is a pie chart, so figure h is going to be equal to P L t. This time it's a pie chart. So the same thing is before just now it's saying pie. And now we have parameter we're gonna have a parameter we're gonna have a variable called Sizes and set the various various sizes of the portions of the pie chart. So 55 50 44 36 and