From Zero to Python: Essential Course for Absolute Beginners | Jorge Escobar | Skillshare

From Zero to Python: Essential Course for Absolute Beginners

Jorge Escobar, Technologist, entrepreneur and open source fanatic

From Zero to Python: Essential Course for Absolute Beginners

Jorge Escobar, Technologist, entrepreneur and open source fanatic

Play Speed
  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x
40 Lessons (2h 25m)
    • 1. Introduction

      1:00
    • 2. Roadmap and Requirements

      1:09
    • 3. Why Python?

      2:16
    • 4. Installing Python 3

      0:25
    • 5. Installing Python 3 on Mac with Homebrew

      1:04
    • 6. Installing Python 3 on Windows 10 with Chocolatey

      1:32
    • 7. The Cloud-based Python Development Environment

      1:17
    • 8. Python Versions

      1:06
    • 9. The Python Interactive Shell

      0:55
    • 10. Basic Arithmetic Operations

      3:49
    • 11. Variables

      5:35
    • 12. Variable Format

      0:47
    • 13. Types

      3:13
    • 14. Strings

      11:13
    • 15. Lists

      3:54
    • 16. Tuples

      1:23
    • 17. Dictionaries

      4:32
    • 18. Loops

      6:18
    • 19. Conditionals and Control Flow

      6:46
    • 20. Conditional Grouping

      7:12
    • 21. Date and Time

      4:57
    • 22. Functions

      6:58
    • 23. Arguments

      4:55
    • 24. Variable Scope

      4:59
    • 25. Classes

      2:53
    • 26. Instances

      1:46
    • 27. Instance Variables

      3:57
    • 28. Inheritance

      3:00
    • 29. Static and Class Methods

      2:29
    • 30. Modules and Packages

      3:41
    • 31. Running Modules

      2:10
    • 32. Packages

      2:58
    • 33. Packages in Windows and Mac

      1:50
    • 34. Packages in PythonAnywhere

      2:36
    • 35. Finalizing our Package

      1:41
    • 36. The Python Path

      8:35
    • 37. The PYTHONPATH Environment Variable

      4:38
    • 38. The Python Stack

      6:44
    • 39. Introduction to Unit Testing

      8:04
    • 40. Conclusion

      0:28
  • --
  • 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.

880

Students

--

Projects

About This Class

3597f86a

Are you looking to change your life and become a software developer but don’t know where to start? Are you discouraged by long, multi-hour Python courses that don’t really seem to teach you what you really need to know or watched dozens of Youtube tutorials only to be more confused than before?

My name is Jorge Escobar and I have worked in some of the top tech companies in the world, from Yahoo! to  MongoDB to PayPal, and now I’ve started my own educational project, FromZero, where I have helped thousands of students to kickstart their coding career.

Python is a beautiful and complex language. But the truth is you don’t need to learn all of it to start building applications. And this is what this course is about.

In about two hours I will teach you the essential parts of Python that you need to know to start using web frameworks, data science or artificial intelligence.

But don’t be fooled, we’re not cutting corners in this course. It is packed full of really complex stuff, but taught in a way that you will understand, even without having coded anything before. 

Best of all, you don’t even need to have a computer. You will have the option to use a cloud-based Python development environment, so that you can practice at work or in a cyber cafe where you can pick up where you left off.

This course is so good, I even recommend it to people that have been already coding in Python for a while, as it will clear a lot of those quirky things that you always wondered about.

So, you have officially run out of excuses. You don’t need to know anything to take this course, no math, no computer knowledge.

We will start by learning about variables, strings, lists, loops and conditionals, then move on to functions, object oriented programming with classes and objects, modules and packages and round it all up with an introduction to unit testing.

The course has easy to follow and digestible video lessons as well as links to the code as we develop it. You can also purchase an eBook with all the material.

The course can take anywhere from 3 to 7 days to complete based on how much material the student completes daily.

Additionally we’re constantly updating the course, adding contents thanks to the feedback of our students.

Join this course and start your path to becoming a professional Python developer!

Meet Your Teacher

Teacher Profile Image

Jorge Escobar

Technologist, entrepreneur and open source fanatic

Teacher

From Zero is an educational project created by Jorge Escobar, a technologist, entrepreneur and open source fanatic with more than 15 years of experience in the development of web applications in New York City.

Jorge has worked in well established companies like Yahoo!, Univision and MongoDB and has also been the technical founding member of various successful tech startups that have received multiple rounds of venture capital.

The biggest problem Jorge has experienced during his career is finding well rounded developers and he interviewed hundreds of them for positions in the teams he was leading. A constant pattern (no matter if candidates came from a good university or had a few years of experience) was the lack of practical, real world knowledge.

That's why Jorge... See full profile

Class Ratings

Expectations Met?
  • Exceeded!
    0%
  • Yes
    0%
  • Somewhat
    0%
  • Not really
    0%
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.

Your creative journey starts here.

  • Unlimited access to every class
  • Supportive online creative community
  • Learn offline with Skillshare’s app

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.

phone

Transcripts

1. Introduction: by phone is a beautiful and complex language that can be used for many applications from data warehousing, statistical analysis to social applications and even gaming. But the truth is, you don't need to learn all of the language to start building Web applications, and this is what discourses about. In the next 90 minutes, you will learn the essential parts off Typhon that you need to know to start building Web applications with popular frameworks like the angle or flask. We will start by learning about viable strings lists, loops and condition ALS, then move on to functions, object or enter programming with classes and objects, modules and packages, and round it all up with an introduction to unit testing. So let's begin our journey to learn python for Web development. 2. Roadmap and Requirements: you might be wondering, What do you need to know to learn Fife in with this course? The good news days? Not much. You definitely don't need a computer science degree or even be good in math. You will find that learning a computer language. It's more about solving apostles and breaking down problems into small, reputable pieces that creating a recipe to produce the same deserved every time. If you already know other programming languages, this course is a great way to introduce yourself toe python in a quick, efficient way. If you already know, Python discourse will go over so many off the fundamentals that you're most certainly going to learn new things about the iPhone or why some things work the way they do. I've been programming in Python for seven years, and I learned a few new things writing this course. You need a computer or cloud server to run the python code. Most people already have a desktop or laptop available. However, you can also use a cloud development environment, and we will check out one of the best ones in the industry. I'll give you instructions on how to set that up in the next lesson, 3. Why Python?: for me, the best language to learn right now, especially if it's your first language, is python. Why do I say that? Here are some of the reasons by phone is like an onion. The external layer is simple and approachable. You can learn the basic stuff really quickly, and best of all, be productive. But once you master that, you can peel that off and be presented with a new level of complexity and amazing modules to learn, which will take a couple of months to master. And then you can find more and more layers as to grow your skills. I've been using bison for seven years full time, and I still find something new and amazing about the language every week, even though it's a hard concept to grasp. For beginners, having a language studies object oriented is a huge benefit. Think of it as a way to better maintain your code base and make things better organized with objects, you have the ability to pass information around your application package in an organized and accessible form. We will have an introduction to object oriented concepts later in the course, but for now, just trust me. It's totally awesome. Bison has a great package manager called PIP, which allows you to install thousands off libraries that do almost anything you can imagine and that are constantly updated by their contributors. It's hard to find a platform or service that doesn't have an associate ID Peep library. This means that you don't have to reinvent the wheel every time you write a new application . These libraries help you focus on the creative side off your application. Probably as important for any language. Having a community that uses the language every day for thousands off different uses is a major reason to use it. Pythons community. It's passionate about the language and are open toe help newcomers, so you will have a supporting group toe help you when you're start. So in summary, python is a great language to learn, especially if you're a beginner. You will start writing your first application in no time, and bison will be there as you grow your development skills. 4. Installing Python 3: in the next couple of videos will learn how to properly install Typhoon Three on Windows and my computers, as well as the option to use a cloud based bite on development environment that will let you learn the course without having a computer skip to the video that's appropriate for you . 5. Installing Python 3 on Mac with Homebrew: my fairy package manager for the Mac is home, and that's what will use to install by phone three between stole homebrew. Just go to the humble website below now, Corbyn echoed on the homebrew home page. Now open a new terminal window. You can open the terminal by going to the spotlight. Search on typing terminal. Once the terminal window is open, based a homebrew code and press enter. Wait until all the files are installed to check that everything was properly installed to our brew doctor. Now we'll install Python three. Doing so bites on three. Just type the following brew. Install five from three. Wait until the script finishes to make sure Python three wasn't still properly type Python three Dash Capital V and that's it. Now we can begin our course. 6. Installing Python 3 on Windows 10 with Chocolatey: My favorite package manager for Windows is Sugar Lady, and that's what will use to install by phone. Three. Head over to the shock a lady install page and copy the code in there. Now open a power shell terminal. You can find it by pressing Windows Plus R and then typing power shell. However, you need to run as administrator. So right click on the window and on the menu. Select Run as administrator based, recording the power show window and press enter. Wait onto the program is installed. Close the power shell window and open it again as an administrator. Remember, every time you use Sugar Lady to install packages, you need to run power Shell as administrator. Technological lady was installed properly by typing Choco dusty. If you see a version number, you're ready to go now to install, bite on three just to Shoko. Install dash y python three. Close and reopen Power Shell as administrator to make sure that path settings for the python package are applied to make sure Python three was installed properly, type by phone dash over Case V and that's it. Now we can begin our course 7. The Cloud-based Python Development Environment: I'm constantly searching for the best python cloud development environment and I keep coming back toe Python anywhere. They are completely free, but they have really good plans. They have amazing customer service and they have my sequel and post great support built in in this lesson. We will look at how we create our python anywhere account to start the process. Please use the following referral link Toby fully open with this link, I get a small commission if you sign up for a paid plan and this helps me continue to bring you more good content. Thanks In advance, when you land on the page, you will see a welcome page Click on the green button to start the process here you will represented with the different plans. For the purpose of this course, the beginner account is more than enough. If you're thinking of hosting a personal site with your own domain or one better speed and performance, choose any off the pay plans. So go ahead and create the account. You will be asked for a user name, email and password. Make sure to confirm your email with the link they'll send you, and that's it. you will arrive to the dashboard. Don't worry about this yet. We'll start covering how to do all the stuff in the coming sections. 8. Python Versions: before we begin. I wanted to talk about the two major python versions by from two and Python three, As you can tell by from three is the latest version of the language. So why are we still talking about bison? To the true face? There was a lot of resistance from developers to upgrade to the latest version on a lot of open source libraries, which are maintained by regular developers and not buying. Companies were not being upgraded to the new bison version, so a lot of people just stuck with by phone to even though Python three have been out for years. Luckily, as of 2018 most of the important libraries are well supported in by from three. There's still a handful off library stocking python to, but none of them will use in this course by phone. Three is the future, and I want you to learn the future so we will be using Python three throughout the course, and with that, let's get started 9. The Python Interactive Shell: to have the first good taste off python. We don't need to go further than our terminal by phone allows you to interact with it, using what's called the rappel that stands for read evil print lope and essentially, it's an interactive shell that lets you write short commands and get the output immediate. To open the python ripple in Mac, open your terminal and type python three and in Windows opened the power shell and type Typhon. If you use by phone anywhere, just head over to your dad's sport and in the new console section, click on Python and then the 3.6 button. You will see a message with a python version and at the end, three corrects and a cursor. So let's start to write some commands in here. And for the first generation, we're going to do some basic calculations. 10. Basic Arithmetic Operations: Here we are, other Python Interactive show, and we now want to be able to use python as a calculator. How do we go about that? So let's just enter a simple mathematic expression, right? Two plus three and press enter, as you can see by some replied with the answer five. Try another one. Enter 10 minus three. As expected, we get seven. What a marble duplication. We don't use an X, but rather we need to enter an asterisk. So type three asterisk five Boom! We get 15. Finally, for division we used to slash So if we do 21 slash seven, we get three. Oh, wait, we got 3.0, and not just three. Why is that? This is what we call a type. So the numbers we entered where off type integer. But since a division is usually something with decimal points, python returned to us a number off type float. We'll be looking at other types in more detail later on. So what would happen if we try the following command? Three plus five times? Two. Post the video and guess the answer. If you say 13 you were correct. You might have had a good or bad flashback to your math teacher telling you about order of operations by the works the same way it does. Multiplication is and divisions first and then additions and subtractions. Their way to alter this behavior is to use parenthesis. So let's say for some reason, you wanted to do this some first. You need to put up our emphasis around the three plus five and then put the times to outside like this. Three plus five times two. So three plus five equals eight and then eight times two is 16. Okay, Now you try. If we have the following sequence eight times three minus two. How would you arrange it? So that the answer is eight. Pause the video and give it a try. Ready? Okay. So you should have put a parenthesis around the tu minus tree. So that was evaluated first, which gives one. And then the multiplication would happen later. Eight times parentis is three minus two a. So try some other things with a calculator on your own and get the hang of it. There are many other math operations available, for example, to get the power off a number you would use two asterisks, so two to the power of three is written as follows. Two. Star Star. Three. We can also get the reminder of a division also called Margallo by using the percentage sign. So, for example, the reminder off dividing 16 by three it's one. This is the result is five and we're left with one. So you would do something like this. 16 Model three. Don't worry about learning all the mass operators as you build your projects. You will be finding out what they are, and you will memorize the ones they use the most. For now, try doing some more math calculations on the shell and get acquainted with it. 11. Variables: when you are building your applications, often you will need to remember the result of an operation or just plain values. So consider this example again. Two plus three. When you press enter, you get a result. Five. In python, this is called an expression. An expression is a line of code that returns a value right after you hit the enter key. But what if you wanted to keep this value to be used somewhere else, like, for example, in a later operation? For that, we have these virtual boxes we call Viable valuables, allow you to execute the expression, but instead of giving the value right away, it will store it in a box that has a name. So let's try that, right. The following impress Enter age equals three times. Five. Wait. What happened to the result As to my guess, the value 15 was stored in the age fire, so the line age equals three times five is not called an expression anymore. It's called a statement. A statement is a line of code that doesn't return a value immediately, but instead it does some type of transformation that you can then use in your application So how do we get the result out off the expression? We can just go ahead and type the viable name in the shell like this. As you can see now, the word age is associated with the value. 15 Every time we type, age will get 15 until we modify it. So how do we modify it? We just assigned a new value to the viable, like this age equals 21. Now, if you type age, you'll see there. 15 has been replaced with 21. That is why they're called virals. Their values can change over time. So I created some viable is and see what happens. Just post a video and I'll be back to resume. Okay, now, for another cool by phone trick, let's say you have eight cartons that hold 12 X. We can represent that with the following expression. A garden equals 12. So now let's say we have a box that can hold 10 egg gardens and we want to know how many eggs we have in that box we could do. The following box equals 10 times egg carton. Now, if you print the box spiral, you can see how many ex we have in the box. Really cool, right? Bison interpreted the value of a carton first and then multiplied it by 10. So what happens if we change the value off a carton to 24? What do you think the value off box will be? Don't look. Pause the video and say out loud what you think will be the value off the box. Viable If you say 240 it would have made a lot of sex. However, that's not the right answer. You see the box viable holds what the value off it waas until we change it again. All the wise variables would be changing all the time without our consent. And that could lead to a lot of confusion to the users off our application. Have anything to do with valuables is to increase them or decrease them by a certain value . So let's say somebody took an egg from the egg carton, viable with a find earlier. Right now the value is 24 so we would do that by doing a carton equals a garden minus one. So we're telling Python to get the value off the egg carton, viable sub struck one from it and then save the result in the same viable mind blown right . Now, check the value off a carton to increase it by one, just to a garden equals a garden plus one, you can increase by any number you want. Of course, a carton equals a garden plus 12. Since this is a pretty common thing to do by phone offers, a short cut for this. So, instead of putting the viable again replaced the equal sign with plus equal, like so a carton close equals one. Likewise, we can substrate by one by doing a carton minus equal one. You can even do multiplication and division, although those are less common to use a carton, times equals two a carton Slash equals two creating a viable that stores the number of inches from a measurement and then another one that converts that two centimeters. How will you do that? 12. Variable Format: in the previous lesson, you saw that we named a viable egg on the score carton. So why didn't we name it EG uppercase carton or egg dash garden? It turns out these things are important. And if we didn't have some sort of contract between programmers on how to name virals and many other conventions are code will look really different from code base to code base. So the users of the python language all a deer toe a format called pet eight. You don't need to memorize the whole document. What? I want you to take a look because it should be your go to guide. When you don't know how to format something, the more things you look up, the more you'll know how to write them. 13. Types: remember how we talked about how some values we were getting back from my iPhone, where different types. So, for example, when we do three plus two, we get far. Five in this case is called an integer. It doesn't have a decimal point, but now if we do nine divided by three, we get 3.0, the 3.0 is called afloat because it has a decimal point. But now imagine were signed. These expressions still virals, so let's do a equals three plus two b equals nine divided by three. Just by looking at a or B, we can tell what viable type they are. So now let's check what type of viable is the ones we used earlier. So just right type. Part of this is a life only saying that a is a type off int or integer for now. Don't notice too much the world class in there. Think off a class as being the category type off the viable. Now let's do type part, and this is B by so now says B is a type off float i e. A number. That's not whole. There are a number off Typhon types but let's check the two other most use ones. The 1st 1 is called the bullion and essentially holds a true or false value. Just those two. So let's type a bullion result equals true notice that it's written true with a capital T and not true old lower cups. That name is a reserved value for python, so now we want to check the type we do type parentheses result so by phone correctly states that the viable result is a bull or bull in to change their value toe false we do. The following result equals false. Nor is this in text off false. The F is capitalized. I won't tell you how many times at the beginning you mistyped that as false or lower caps. But eventually we all learn the last type will introduce is called String, and we're going toe dive deep into it in the next lesson. But as an introduction, strings are a serious off characters, which can be any combination off letters, numbers or symbols. So let's try one type name equals quote John End quote. That's it. Now the viable name holds the value, Jon, If you type name, you get the string John and to check the typing python we would write Type Parent is his name, Bison says. It's a type off str or string. There's a lot of things we can do with strengths, so we'll check that out next. 14. Strings: in the previous lesson, we were introduced to the string type in python strings is one of the things you'll use a lot in your application development. So it's good to have a good understanding of the things you can do with that. The first thing to learn and it's a source off a lot of discussion in any part on development team is the question off single quotes versus double quotes. So, for example, you can do this name equals quote, John End quote or this name equals double quote John Double quote that by phone. Interpreter will be fine with both. So the principle I use is the following. Use single quotes. Unless you have a single boat industry, for example, let's say the string is John's horse. You would use sentence equals double quote John's horse and double quote if he used single quote. John's horse single coat that returns on air sentence equals single quote. John's horse single quote. The second thing to learn and this one is super important is that strings are also lists. What is a list? It's a sequence of values that have an order, and an index will see lists in the next lesson. But for now, visualized this. This is a string with award hello in it, but we can also get to specific characters off that string using an index. So try this in the terminal. Greeting equals Hello. So if we want to just extract the E in hello, we can do greeting bracket one. No, it is not for Mitt. We used a viable name. Then in brackets the character index, we want it. We can get slices off the string by adding a column and another end exposition. So, for example, to get e l l from the viable we do greeting bracket one colon four. Notice that we specified four in the second number, which corresponds to the old character. However, the slice doesn't include the last character. So the above expression reads. Get me the characters from Index one and below Index four. Did you see that? We also have negative numbers in that chart. That's because the list also has a negative index, which is handy. For example, if you want to get the last character off the string, and you can also do a slice as well Reading bracket minus four. Colon minus one. The above reads Get me the character from minus four to but not including minus one notice . The slice always goes left to right. Doing it backwards doesn't work. Greeting minus one colon minus four. The last nifty trick with slices is that you can leave the second number out, and that signifies until the end of the string. So, for example, if we want to get the slice from E until the end of the string, we do grading bracket one colon, and that also works with negative strings. Greeting bracket minus four colon. Okay, now you tried. How would you get the string? L l O both from the positive and the negative index. You can join two strings by using the plus operator. So let's say you have a greeting and a name. Viable greeting equals quote. Hello. Name equals quote. John. You can join the two by using greeting plus name. Okay, that was too literal. Let's insert something in between reading, plus quote, comma, quote plus name. Ah, that was more polite. Now let's say we want to have a string that reads How many eggs are left in a carton? So we have the eggs underscore. Left viable like so eggs left equals four. And now we write the string quote. There are unquote plus eggs on the score. Left plus quote Ex left in the carton. Whoa! What happened? Bison is telling us that we can't makes a string and that ain't or integer number. We must convert the number toe a string. To do that, we use the built in function called str Quote. There are unquote plus str x on the score left plus quote Ex left in the carton. What if we have a string that does have a value and we want to add it to a number? For example, it would define eggs Toby a string with the number five in it. And why an integer with the number five in it, X equals quote five end quote Y equals five and we want to add the two as numbers. We can convert the XTO a number using another built in function called i NT I anti parentheses X plus y. We can also convert it toe afloat by doing float. Parent is is X plus y. Now let's say we have to vie roubles. We need to output. Now we have a carton. Zero number carton on the score number equals 25 and we want to know the number of eggs left in that carton we could do. There are str eggs left plus X left in card number, plus str carton number. I mean, it works, but it's starting to get messy. And one of the principles that bison developers share is to write clean, readable code when you write good python code, it's referred to as being python. Bison allows us to do string interpolation, which is a fancy word to say, Replacement of values in a string For that by from 3.6 introduced the F function for strings so we can directly insert the variables industry by doing this. F quote. There are bracket X left in card number. Bracket card number isn't that much more readable? I think so, too. You can assign the F string toe a viable a swell I'll put equals F. Quote. There are Bracket X left in carton number bracket card number. There are a number of methods or functions that are integrated into strings, and you execute them by using a dot notation. For example, let's say we want to put all characters in all caps for a string, using the name viable before we can do name equals. Quote john name dot upper notice when he to use an open and close parenthesis at the end of the method. That's to signify we are not passing any parameters to the function or modifiers. We want the function toe execute immediately. Well, look at functions and parameters. Later in this section, we can convert all the characters to low caps by doing name dot lower. We can strip the space characters from the beginning and end of a string. Like this space is equal Quote space. This is a bunch off spaces. Space quote spaces dot strip. We can separate a string in tow. A list off strings using a specific character joined equals. Quote a slash b slash C joined dot split Martin. This is slash and we can't even join a list off strings with a separator between them. By doing separator equals slash separator thought joined a B. C. There are other methods available, but don't worry. You learn them as we go along. The last built in function for strings that I want to show you. And that's really useful for strings is Len, which tells us the length size of a strength greeting equals quote. Hello, John. Len off Creating the land function also works for lists. Well, you shouldn't be so price about that. Now, you try it. So you have a list of product numbers in a string like this. Stock equals quote 1 22 comma for 55 comma 677 Create an F string that outputs. There are three products in stock right now and come back for the solution. So I would do it like this. Products equals stock dot split coma. And here was a tricky part, Remember, I told you. Len also works for lists so you can do number of products equals Len off products. And now do F quote. There are bracket number of products, products in stock. Hope you had fun with that one. 15. Lists: in this lesson will check out three very important types in Python. Let's start with lists. We've seen a bit of this type in the previous lessons. It's essentially a collection off order items, so at least could be I DS equals 12345 As we saw in the string lesson, we can get an element off the list by passing it zero based index number. So to get to we do I ds off one. We can also get a slice with the index number and the upper bound but not included. Index number. So to get 234 we do I ds one Colon four. Now here's something interesting about lists. Remember when we had the following X equals three y equals X X equals six? And then why does the value of why was not updated when exchanged? The name for this behavior is called mutability. Numbers and strings are called immutable imp iPhone I e. They don't take. But when you assigned X to the new value off six internally python living changed a viable . He created a new version of it and left the previous version in a limbo state where it might be deleted at any point it's needed, but lists are mutable. I eat. They can change to check this out. Let's check that. At least we had before I DS. Now let's assign a new viable called numbs toe. ID's norms equals I DS and now change one value in I DS ideas off to equal six. Now look at numbs. The third element of numbs also changed. Keep this in mind when dealing with lists. We already know that to get the size off a list used the built in function. Len Len off ID's. We can check if there's a value in a list by using the built in function. In this function returns a bully it Let's right two in ID's 10 in ID's to add a new element at the end of a list, you'll do ideas thought append six. Notice. We have six twice, and the list is fine with that. If we wanted to replace that 1st 6 we just replaced the value on the end exposition like we saw before, I d Stuff two equals three. To get the position off a value within a list, we can do the following ideas dot index of four and can remove a value by doing I DS thought removed. Six. You can also remove an item with the Dell built in function, for example, to remove the value in the 4th 0 based index. We do del i ds off four. By the way, we can use tell to remove a viable as if it never existed. 16. Tuples: triples are like lists, but with one key difference. They are immutable, like strings and numbers. They are defined. Using parentis is instead of brackets. Cords equals 25 64 98. You can get the first value off the courts, topple with the Syria and exploitation cords off zero. But if you try to replace the value of the first value, you get an error. Courts off zero equals 18. You can also get an error if you try to upend a value course startup end 1 28 So when would you use a tupelo instead of a list? The main reason would be if you want to set a list of things that you want to make sure won't change later in the code, you are sort of protecting that the two poll is kept as you define it. Initially, things like code settings or options in a select field are good candidates to use Stupples . But don't worry if you don't get it now. Fully, once he used them, you'll see the difference more clearly 17. Dictionaries: are really useful. Data types are dictionaries. Dictionaries are also sequences, but they have a key and a value. Let's see what that looks like. Countries equals us. United States See a Canada MX Mexico. Now, instead of using the Ciro Index method to get a value we used to keep, for example, to get the value Canada we do countries off. See a. We can add key value pairs of the dictionary by creating a new element like this countries ve equals Venezuela countries Just like lists. We can get the size of the dictionary, len off countries, and we can delete an item using Dell del countries. See, a. We can also update an item easily. Countries off MX equals Mexico. And if you were wondering about it, yes, dictionaries are mutable. So assigning another viable toe the country's list. We'll change it if something changes in the dictionary. You can also check for the existence of a key in a dictionary v e in countries. But that doesn't work for values. Venezuela. In countries, however, dictionaries have two methods that return at least off their keys and values. Countries, darkies countries start values and interesting enough it has a method that returns a list with two pulls off the key value pairs countries dot items. This is really useful when we want to scan the dictionary. For some reason, we'll see more of these types of operations later on. A frequent issue you will have is to know if a dictionary has a specific key. Sometimes the dictionary is being returned by another function or library, or you're dealing with user input, and you don't know for sure the contents of the dictionary. If you try to access on any existent key, you will get an error on the program will crash. Let's see that in action countries off i t. There's no Italy in our country's capiche. So in order to safeguard the program and test gracefully if it has that key, we used the built in get method that the dictionary provides. So to test this without risking to crush the program, we do. Countries don't get i t. Nothing happened, and that's good. Now if I try to get a country that does exist, we get the value countries that get us. We can also assign a default value toe the get so that we can load a value we want. In the case, the key doesn't exist like this. Countries don't get I t comma. No country found. Now it's your turn. Try your hand with list two poles and dictionaries. Try to get specific elements, slices and adding and removing items. And here's a question for you, Theo Countries Dictionary above with what you've learned so far, How would you find out if a specific country is on the values of the dictionary? Think about it and write it down. I'll tell you the solution in a second. Ready so to get if, say, Venezuela is on the values off the dictionary. I would do the following Venezuela in countries dot values. Did you get the same result? Cool. Let's move on to the next lesson. 18. Loops: looping refers to executing an operation or group of operations repeatedly until a condition is met. There are many reasons why we would want to do a look, and they're usually related to lists and dictionaries, so now's a good time to review them. The first looping command is the built in function called four. So let's say you have the following list. Numbers equals 12345 We want to write a script to write all the values so that would look like this for number in numbers. Colon. That statement, above loops for every item in the numbers lists, assigns it toe a viable called number and executes the block below. Since the list has five items, whatever is below will be executed five times, and then it exits the look. Now press enter and notice that instead of the three arrows we have three dots by phone is expecting us to continue writing the code. And that's because when we use the colon at the end of a statement by phone, is expecting a block a block. Issa Siri's off statements that are associated with the line above. So how does Spieth on No, which commands belong to the statement, and where does it end? It's really simple by the spacing, So any comments we want to execute a number of times under that four statement need to have at least one space before it. The bison forming guide eight recommends four spaces, so that's what we'll use. I know it might sound confusing right now, but don't worry. It'll make sense soon, so let's continue the statement and therefore spaces and then right print number printing virals. Just using the viable name is a quick way to see the contents in the interactive terminal. But here we've started using the Print Command as that's what we would be using in a real Python script. We could have written just a viable name here, and he works, too, but he wouldn't work in a real script. Just remember to put print and whatever you want to print surrounded by parenthesis. Notice that when you press enter after the print statement, you get another three dots by phone is giving you the chance to continue writing more statements on that block to exit the block, just press enter now. Python knows we're done with the loop and executes it. Now let's try the loop with two commands. Do the following for number in numbers. Print Dash Print number. As you can see, older statements with a spacing in front get executed once in every look. You can also look for dictionaries using the four function, but the values are a bit different. So let's create a dictionary with three values. Numbers equals a one B two C three. Now we look using the four function for number in numbers. Print number. Okay, so we're getting the keys, but not the values. For that, we would use the values method for value in numbers. Start values bring five. We can also get both the key and the value at once using the items method. Since each loop will return a key value. Topple we can assign it to viable is dynamically by doing for key value in numbers. Thought items print key value. Notice how we can use a comma in the print statement toe print toe values that are off different types. Can you figure out what would happen if we had just done print key plus value? There's another loop function called while while executes the loop as long as a condition is met, we will see conditional in detail in the next lesson. But for now, I'll give you a quick advance. We can check if the value is less than another by using the left angle breath. So, for example, if we want to find out if three is less than five, we do three lower than five. So let's say we want to do the same print out off five numbers, but without creating a list we could do. The following equals zero. While I is less than five, I equals I plus one print I. As you can see, the loop, executed the statements until the value off I reached five. Or in other words, while the value off I was less than five, the moment the value off I was higher than five. The loop stops executing. There's a built in function that's useful to generate this sequential lists, and it's called range. So, for example, to generate a list off all the numbers from 0 to 99 you would too. Numbers equals range from 0 to 100. Let's check the last number of that range numbers off minus one. So now you try doing the following challenge. Generate a list using range called ID's that has the numbers from 0 to 20. Now do a four loop that prints all the numbers. Next, do the same, but only using a while loop and no range. 19. Conditionals and Control Flow: Sometimes we need to make decisions and add a fork in the road in our scripts, and that's what we get with conditional and control flow. There are a number of conditional operators that allow us to check for the relationship between two items. Let's go quickly over them. We already saw that if he used unequal operator on a viable, the expression on the right is assigned to the viral on the left. But we can check if two values are the same using the double equal operator. So, for example, let's say we have two viable and we want to test. If they're equal, we can do X equals five. Why equal six X equals equals why, As we can see, the result is a bullion value, and it's false, Of course, since five is not equal to six. The opposite of that is the not equal operator. So we can do X is not equal to why we already saw degraded than operator in our wild loop. But just to refresh your memory, we can do X is greater than why The opposite of that would be the less than operator X is lower than why we can also test if our values greater or equal to another, we can do it like this. X is greater than or equal to. Why on the opposite would be less or equal. Then X is lower or equal. Dan Y. Now take note of the format you can't. Two X equals less than why. Always remember to put the angle bracket before the equal sign. Conditional are not limited to numbers. We can also do comparisons between strings. For example, X equals John. Why equals Jane? X Equals equals why X is not equal to why, for two strings to be equal, they need to be exactly the same. So if we have X equals Joan, why equals lower case? John X equal equal? Why false? One handed trick use often is to use the lower method for strings to check if they're the same. So in the example above we could two x that lower equals equals. Why don't lower? This is true because we converted both strings to lower caps, so you can also do greater than or lower than with strings. In that case, the comparison will be based on the alphabetical order off the streaks So, for example, Alfa equals a omega equals Z. Alfa is lower than omega. This will come handy when we want to sort strings in alphabetical order. We can also group condition ALS just as we did arithmetic operations using the end and or logical operators we use. And when we want all conditions to be true, to return true and or when we want just one of the conditions to be true to return true again using divi roubles X equals five. Why equal six? We could test the following with Aunt X Equals equals five and why equals equals six. So because we're testing that both values are equal to their actual values, we get a true however, let's do one condition to be true and the other false and see what happens. X equals equals five and why equals equals five. We get a false which makes sense. Both expressions are not true since why is not equal to five. So the whole expression fails now if he used and or that would look like this X equals equals five or why equals equals five. Here we get true because we just needed one off them to be true. There's another logical operator called not which negates or switches the expression after it. So, for example, we can do X equals equals five or not. Why equals equals five. We could read this as if X is equal to five or why is not equal to five off course. The second part of the expression is true, since why is not equal to five. So we get true by phone has a built in constant called none, which is a special value. It detects if a viable has value or not, but it's not exactly zero. As zero is a value, it's more equitable with void. You can also assigned me to a viable toe the note that it doesn't have a value yet. For example, let's say we set a new viable Z to none. Z equals none. At this point, we're saying Z is not set yet. It can be a number or a string. We just don't know yet. We could test if a viable is none by doing Z equals equals none. However, Pep eight says the following comparisons to Singleton's like none should always be done with IHS or is not never the equality operators so always, always used the identity operators is and it's not to check. If a viable is none. Z is none. They're called identity operators because they are really checking. If the two values belonged to the same location in memory. Not if the values are the same. That's also why it's much faster To test. Z is none than C equals equals none. Geek alert. Here's a function to check the memory location off available. I d of Z now compare that to the i D off None. I d off none. See how the numbers match. That's why Z is none. Now if we said Z 20 it's no longer known Z equals zero z is none. 20. Conditional Grouping: just like mathematical operators. We can also group logical expressions with parentheses is so to continue with our virals X equals five Weichel six z equals zero. We can do the following expression. X equals equals five and part, and this is why equals equals six or Z is not. So Python here does. The calculation off the logical operators in the parent is is first. Why equals equals six or Z is none and then does the end operation with the first part of the statement. X equals equals five and true. Armed with the logical operators, we can now control the flow of our script based on the outcome off these comparisons, just like with the loops. By inventing or putting spaces in front of a group off lines we can enter or skip this groups or blocks, depending on the truth, iness off the statement. Let's do an example. Name equals John. If name equals equals John Print, it's John. As you can see, the block indented under the if statement got executed. If we had more than one line and it had the same indentation, it would have been executed as well. We can combine the if, with another conditional statement called else the block under the else will be executed. If the logical statement after the if is false so we can do the following if name equals equals James Print, it's James else print. Here's Johnny. Finally, we have 1/3 conditional that can further test another comparison. If the first if is false, it's called LF and it means else if in the previous example, it's dangerous to assume that if the name is not James than it has to be John, so we'll use on L. If instead, name equals one. If name equals equals James Print, it's James L. If name equals, equals John Print, here's Johnny Else print. I don't know him. Remember to put else at the end of the comparisons. Otherwise it will be executed before you test for any other conditions. Sometimes we want to stop the operation of a loop or to skip to the next generation, and there are two commands to do, so let's see each one in action. So let's build a numbers list with the numbers from 1 to 10. Numbers equals range off 1 to 11 for numbering numbers. Print number if number equals equals five. Break. So break just exits us from that lope. But let's do another use case with the same numbers list. Let's say we want to print on Lee the even numbers. Remember the module of function that gives us the reminder of our division. If we divide a number by two and get a modular off zero, that means it's uneven number. So with that, let's do for number in numbers. If number modular two equals equals zero, continue else. Bring number. Notice how with this Continue the loop. Just give the rest of the code and went back to the beginning with the next item way. Have the following sequential list of numbers. I want you to create the reversed version off that list in another list called reversed numbers. How would you do that? Using loops and lists? Pause here and continue when you have to. Solution. Okay, Ready to see how I did it? I created the empty reverse number list first, as you always want to initialize viable that you'll be adding things to then I made sure to initialize the numbers list. Numbers equals 12345 My idea is to do a loop that starts from the back off the list and moves toward the front of the list. So, for example, on the first generation off the loop, I would get the last number off the list and appended to the list and the second time around. Get the second to last and so on. Remember how there were negative indexes on lists? So, for example, the minus one index of numbers is the last number numbers off minus one five. The second to last number would be minus two. Numbers minus two is four. Do you start to see a pattern there? If we subtract a number toe that index, we get the previous number and so on. So let's define that viable as reverse index. Reverse index equals minus one. And once we get the index, we can upended toe the reverse numbers list. Let's call it looked number and then appended to reverse numbers. Look. Number equals numbers reversed on the score index. Look, number reverse numbers upend. Look, number reverse numbers. Then we can subtract one toe the reverse index, get the loop number and append that to reverse numbers. Reverse index minus equals one. Luke. Number equals numbers. Reverse on this core index. Reverse numbers dot upend look, number 54 So here's the whole code. - Did you do it in a different way? It's very possible if you got the same result. That's a good sign. 21. Date and Time: even though technically not a python type date objects are an important part of any application bison offers. A set of helpers are part of the language called standard libraries. You will be discovering many of them throughout the course, but we're going to check out. The daytime library by phone allows you to import this libraries by using the import function. So let's try importing the daytime library by doing from day time. Import daytime. You don't see anything happening, but internally, Python just loaded the daytime library into memory, sort of how neo loads his knowledge of kung fu. In a few seconds. In The Matrix, the import command looks a little weird with the daytime repeated twice. You're really importing the daytime library from the daytime module, which also has other libraries like Time and D. C. Info. Now let's try getting today's day. They time dot today. The date and time you get is the system's local time. In my case, it's Eastern standard time in the United States. As you can see, we get an object that has a bunch of values. You can probably figure it out, but they are the different components off today's date, so the first number is 2018 which is the card in here. The second value is the month. The third is today state and then we have the hour, minute, seconds and milliseconds. You can extract the different components by using some custom methods. Let's assign today's date toe a viable today equals daytime dot Today. Now we can get the year, month or day today, that year today that month. Today, that day we can also get the difference between two dates by doing a simple so obstruction . So let's say my birthday is may 25th. I can tell how many days onto my birthday from today by subtracting the oldest state from the most recent. So let's set a birthday barbell Birthday equals daytime 2018 5 25 Now we can subtract the birthday from today to underscore. Birthday equals birthday minus today that to underscore birthday object. It's not a daytime object, but a different type of object called time Delta. Check it by doing a type command on it. Type to underscore Breck take. We can get the number off days to my birthday by doing two birthday dot days. You can also get how many days you've been on this planet by setting the date you were born . What's on the scoreboard equals daytime 1969 5 25 h equals today minus was born age, dark days. That's a lot of days, but let's get the age in years. We can do age that days divided by 3 65 That would be a cool answer to How old are you? We can calculate any dates in the future or past from another date by using the time Delta object first import the time Delta Library from Daytime Import time Delta. So, for example, if we want to know the date one week from now, we can, too today plus time, Delta Days equal seven or to get the date a month ago. Today, minor Stein Delta Days equals 30. The last thing will check out is the UTC time method. As you might know, there's dozens of time zones are on the world and even here in the United States, keeping track off all the time. Songs in your application quickly becomes something off a headache. That's why in your application, whenever you want to store the date and time off. Any event like a user registration date or the date of the latest post started using UTC. That way you have a unified time for all users, and you can translate it later. Toe there, local time zones. That's the way professional developers do it together. UTC time right now. Just use daytime that UTC now. And that's all the daytime we have. See what I did there. 22. Functions: we've come a long way in this python IQ interrupter a trip. The time has come to exit the Python interactive shell and write ourselves our first file. For that, we will start using the terminal. A sign that you are on your way to becoming a professional developer is the lack of fear off opening the terminal and have a permanent Charcot for it. Pained in your launcher For windows, we will use power shell. And for Mac, We will use terminal on by phone anywhere. Will use the bash console on the dash board to open power shell on windows. Just go ahead and type power shell on the cortana. Search on Mac. Hit the spot like search. Aiken, untie terminal on python anywhere. Hit the bash button you will replaced in your home directory. We will create a folder for our python scripts. So go ahead and type. Make their by sun Underscore tests on the terminal. Empress, enter. You just created your first folder from the terminal. Big stuff coming. Now we need to change to that directory type CD by phone. Underscore tests in present. You are now in the python on the score tests folder. You can double check by looking at the command, prompt those characters at the beginning off each line and check that it says Python tests . Now we need to write our first bison script file. For that, we will need a coat editor that allows you to write in format Python scripts. If you're using python anywhere, you can skip this section as we will be using their own line code editor for the purpose of Discourse. I will just use Git Hops Adam Editor. So go to the atom editors home page, adam dot io and download the file for your operating system on my computers. The Adam editor will be downloaded on your downloads folder. Make sure to move it to your applications folder before running. It opened the Adam Application. You may get a couple of welcome tabs if you want to hide this every time you open Adam, just click on the check mark titled Show Welcome Guide. Now quit Adam with file Exit on Windows and Adam Quit on Mac. Now go back to your terminal and type Adam functions Speed. Why, this will open a new file called Functions B Y on the Python test directory in Our Autumn Editor. Notice how the file name ends with dot B y. That means it's a python file and allows Adam to know how to properly to code hints and coloring. If you're using macro windows, you can skip this section to access the court editor in Python anywhere head over to the files section. You can go to the files page anytime by using the hamburger icon on the top right and selecting files. Now on the directories. Select Python Underscore tests You're now inside the directory now on the file section. Enter functions dot B Y and hit new file. You will now be inside the functions dot B y file and can start coating, so we're going to write our first function. A Function is a collection of statements that are executed every time you call the function . So right the following code on the editor deaf my underscore function Print. Hello World Notice how, after pressing enter at the end of the first line, the editor automatically puts spaces for us to invent the print statement. From this point, I will be putting a link to the lessons code I write on this slider. Just go to your browser and type this Your oil. Now save the file. Using the key shark it Control s on windows or command s on Mac. You'll notice the little brutal circle next to the name goes away on bison anywhere. Hit the save green button on the naff bar or use control s. So how do you run this code? Since we'll be switching between the terminal and the court editor all the time. I suggest you put both windows one on top of the other on Windows and Mac on bites on anywhere. Open a new browser window and open python anywhere again. You don't need to hit the bass blue button again if you have an existing open console as this would create a new bash terminal. If you don't have any consoles open, then hit the bass. Barton. Now rearrange the two browser windows one on top of the other. Make sure you're on the python tests folder. If you don't see bison tests on the command, prompt change to that directory now in the terminal type by sun functions, stop ey on Windows Python three functions that B Y on Mac and Python anywhere and press enter. What happened? Nothing was printed on the terminal. What happened was that bison registered the function. But we're reading actually tell it to run the function. The way we do that is by calling the function so right this at the end off the file, save the file and run the script again. Bingo. Now we get Hello world. Now check out what happens if we add another line below the print statement. Let's say we add another print statement below the 1st 1 notice. We're keeping the same indentation like the first line. As long as the two lines have the same number off spaces, they are grouped under the function save and run again, you'll see the three dashes below. 23. Arguments: functions can accept incoming data through the use off their arguments. Arguments can be thought as viable is that are being set from the outside and passed to the function. Let's try that at a name argument toe my function inside the parentheses on the same viable toe. The first print statement. Finally, let's add the name John to the function. Call now, save it and executed we get Hello, John. Now, at a second call to the function with another name safe and run, you can see the power of this right. You can call this function with a new name on. The output is different. We can have more than one argument on the function. Let's try that quickly change the name, argument toe first name and add a second argument called Last name, separated by a comma. Next change The print statement to have the first name and last name arguments using the F method finally changed. The function called Toe have the first name and listening. Now we run the script we get Hello, John Jones. Most functions don't print things inside of them. Off course, some of them will, but functions are usually little black boxes that return the result off their computations . Let's adapt our function to return the full name with passed away. So instead of printing, let's assign a viable called full name, toe the combined first name and last name string and then return it to the collar. Then, on the function call, let's assign the result toe a viable called composed name and printed. If you run it, you'll get the exact same result. The last thing will learn about functions are the two different argument types, so the first name and last name arguments are also called positional parameters. They are positional because the function is expecting the first parameter. You pass Toby the first name, and the second has to be the last name you can call them my function function with last name and first name as a parameters. If you pass Jones comma John in my function, it will return the results backward. They are also required arguments if you try to call them mind function with only the first name. Look at what happens now. Run the script by some is telling us the function is expecting to arguments, not one. So let's say we know for sure will have to first name and last name data, but the inputs could have an optional address and or a phone number. We could do the following at the address and phone number arguments, but assigned both to none. Notice the Web eight format. Here you put the equal sign without spaces by pre assigning the value non toe. These arguments you are declaring them Toby keyword arguments, which have the following characteristics. They're optional. You can pass them on the function. Call or not, they are not positional. You can pass them in the order they are set in the function, or you can call them in a different order. If you pass their keyword names, let's put some conditional is on the function to check if the address and phone are passed and add them to the customer record. Finally, will change the combining return viable to customer data. Let's put four different calls to the function to see what happens. Notice how on the first goal with John Jones, we didn't pass the phone or address on the second Cole with Jane Jones. We don't pass the phone number on the third called with Julia Jones were passing both address and phone but using them positional e on the fourth call with Robert Jones. Notice how the phone and the addresses are in reverse order, but because we're passing the keywords before them, the function is able to figure things out. 24. Variable Scope: there's an important functionality that you should know of our bar Valls that we haven't talked about. And that's the concept off scoping so far when you have created viable, you just assume they're available everywhere. Turns out that valuables inside off a function or classes, which we'll see later on, are scoped toe that function or class on are not available outside of that code lock. Let's try this by adding a new print statement at the end off our function. P y. Now run the file and see what happens. Even though we're setting customer data in the my function function, we executed customer data is nowhere to be found. This makes a lot of sense because off a principle you should always be mindful off. And that's the principle off encapsulation. Your code should always have little black boxes that do things when called, but that don't modify any external virals but rather return values that are assigned outside. That means code that's more maintainable and better. Organized bison introduced recently away toe overwrite that you've seen the global and known local keywords. So, for example, if you wanted customer data Toby available anywhere from the outside of a function you can add on the first line off the function. The following statement. Global customer data now run the code, and you will see it works if you define a viable at the top. Most level of the code that viable is available inside the inner functions. For example, if we define another viable outside called No Address without adding the global keyword, we can access it from inside off the function so online. One to know address equals falls and in Line 21 insert print. No address, no address. Now run the script and you'll see no address printed out. Let's change no address inside of the function to see what happens outside at the following in line seven. Now caught lying 24 paste it in line 16 and 19. If we run the file now, we see that on the outside. No address was not changed. That's because even though no addresses available to be read within the function when you change it, it's actually creating a new no address local viable. So we declared no address Toby the global viable outside the function to let Typhon No, we want right access to the viable inside the function. Put this in line five Global. No address. Save and run the script. You'll see no address changes. Accordingly. I won't cover none local here, but it's essentially similar to global, but it just exposes the viable toe, the outer function. But not globally, however, and this is what I highly recommend. Don't use global or non local period. It's just bad practice. Toby. Allowing external virals inside of functions on viable set in functions. Toby. Available outside, there might be one or two which cases where I could see this being valuable, but I'm talking Ciro 20.5%. Just please don't use this unused parameters and returns instead. That is all we have for functions. Now it's your turn. Try to great a function that accepts two numbers as positional arguments and return to some of the two and an optional third number argument that, if passed, makes the function return the average of the three numbers. Once you've tried it, let's check the solution. Here we have the function with the three arguments number one, number two and number three, with number three being option. Then we check if number three is being passed. Calculate the average by summing the three numbers on divided by three and then returned the value. Otherwise just sum up the two first number. Hope you had fun with that one. 25. Classes: object oriented programming is a feature that is heavily used in professional programming. But it's the hardest to grasp by new developers. I found it easier to explain by doing instead of explaining, Let's create a new file in your Python Tests folder just to file new file on Adam and then saved a file with file safe file and call it classes. Stop ey on python anywhere. Go back to the Python Tests folder by clicking on the python, tests link on the top left nuff bar and then enter classes. Don't be Y on the dialogue and finally press new fire, so we'll start by defining a class. What's a class? So think of a class as a blueprint to create objects from, and it helps to understand if we think about physical things. So let's create a class called Animal Notice How we make the name Start with a capital letter. Pep eight d takes that class names should normally use the cap wards convention. In effect, every ward is capitalized and joined without spaces, so a class for animal kingdoms would be called Animal Kingdom Also noticed. The class name is always the singular name off the objects it represents because the class is just one. So as with functions, we follow the class with a list off statements indented. So let's bring something glass. Animal print. I'm an animal. At this point. We have an animal class that prints that it's been annual. Remember how I told you classes are the blueprints for objects? How do we create an object we create the first copy of the animal class doing the following dog equals animal. Notice how we put that statement outside off the animal class, save the file and run it by doing python glasses. DePuy Remember on Mac and Python anywhere running with by phone, three classes that B y. We see a line that prints out I'm an animal. So what happened here, Waas that we created a new object called Dog from the animal class. Right now that object doesn't do much. It just brings out a statement 26. Instances: the dog object is an instance of the animal class. What else can we do with our animal class? One thing we could do is give it legs so we can create a class viable called legs and assign it a number. So let's at that. So now any animal we create from the animal class will have a viable called legs set as four. How do we access this class? Viable? We can just print it like this. Print F. I have dark dot legs. Lex saved a file and run it. You will see that the dog says it has four legs, but let's say we're going to make another instance off the animal class. But this time it's a spider. And as we know, a spider has eight legs so we can do the following. Spider equals animal spider Dot Legs equals eight print. I have spider, the legs, legs. Save the file and run it. Now we have two instances of the animal class. One. He's a dog and another isa spider. But as you can see with a spider, we were able to change its legs. Property. The dog instance, isn't affected. It's a separate object from the spider, as it should be, but you can probably see it's not very smart to set the number off legs before we know what the animal instance will be. Legs should be an instance viable. Not a class viable like it is now. We'll see that next. 27. Instance Variables: to set the legs. Instance, viable? We need to do the following code. Self dot legs equals none. So what's this self business? This refers to the instance itself, i e. These viable will be associate ID just toe each instance and not too the whole class without the self. If we change the value, it will be set toe all instances like we had it before. However, that means that I would need to create the object first, then said the legs afterwards every time. Wouldn't it be nice if we could set this basic piece of information from the moment we create the object? Turns out you can. Classes have some internal functions that are low you to manage them better. They're also called magic methods. One of these magic methods is called in it. It is called every time you create a new instance of the class, you can also pass initialization viable on the method, which is perfect for what we need. Magic methods have a weird Syntex. You surround them with two underscores. So let's right the Enid method for our animal class death on this score. On this score in it on the score on the score. Self comma lex self that Lex equals legs, and now we can pass the legs as a parameter when we Instead, she ate each animal dog equals animal of four spider equals animal off. Eight. Now save the file and run it. We can also have custom methods that can do anything we want. These methods also have access to the objects self variables. So, for example, we could write a method that can start moving the animal. So let's at that death start on the score. Moving self self done moving equals true, but it makes sense to initialize. It is viable with a state off false, since the animal is probably not moving when it gets created self, that moving equals false, and it would make sense to have a method to stop the animal from moving deaf. Stop on this court. Moving self self moving equals false. Finally, we could have a method that tells us the moving status of the object. Death moving on this course tied herself. If self dot moving is true, return the animals moving. Els return. The animal is stopped. Now let's make our spider crawl spider thought start on the score. Moving pranked spider dot moving underscore status. Saved a file and run it. I don't know about you, but saying the animal is moving is a bit heartless. Let's add an optional name argument under in it and said it as an instance, viable then on moving status, we can call the animal by its name. Finally, let's call despite her by its name. Spider equals Animal eight. Comma Charlotte. So if the file and run it love to see Charlotte run. 28. Inheritance: Sometimes you want to leverage on existing class and somehow work on features. On top of that class. Developers are Lacey, and that's a good thing. We never, ever want to reinvent the wheel. If there's a library out there that does it well and does it cheap we use. So let's say that we have an amazing animal class that another developer wrote. It could be something like this. So just select all the contents off our classes, start B Y file and clear them and type this manually. Or you can copy and paste from this cold link. So now imagine, we want to create a new class called Dog, but we don't want to write from scratch all the functionalities that the animal class already offers. We can extend the animal class by putting it in parentheses after our new dog class. Like so class dog animal. This is called inheritance. The dog class inherits the animal class and all of its methods and properties. So what would the initial dark class look like here it ISS notice how by inheriting animal , we already have all its properties like legs and wings. But since all dogs have four legs and don't have wings. We can initialize all dogs toe have those properties. However, we can also add dog specific methods that are not in the animal class. For example, we know that when dogs are thirsty, they pant. So let's create that classmethod just for dogs. Now we can do the following operations. Final equals Doc Prince, vital dot Make sounds print fiddle is thirsty. Final update coordinates print vital That coordinates. Notice how Here we can call animal class methods and specific dog class methods. Now run the code and check out what happens. Now it's your turn. Create a bad class that extends theano Emel class and write the innit method as well as at least one custom method that only applies to bats. 29. Static and Class Methods: So far, the methods we've seen are called on an instance. What happens if we called? Dog is thirsty directly without generating any instance of the object. We get an error sometimes who want to expose a method that anyone can use without creating an instance of the class first. For example, let's say we want the dog instance to lease the dark breeds available we could to the following. Now we can get the Breeds without an instance by doing dog dark, get braids. That funny at sign on top of the Deaf Command is called a decorator and essentially tells any function underneath it that its behavior is goingto be overridden by another function. We'll see decorators in more detail when we start building our own applications, and we'll even build custom ones. Now. Remember when we had the legs class viable at the beginning off this lesson? It didn't start with Self because it was available toe all the instances off that class without being tied with an instance. Let's add one to the animal class Planet equals Earth. We're going to assume all animals created from this class are on earth, so we can now create a classmethod that's available to the class without having to do any instance off the class. Notice that we pass CLS as the methods first argument. That's like the self for instances, and in this case, it represents the class for both the static and class methods You can have arguments past. Just remember to put them after the CLS on class methods. So now you can do print animal dot get planet. Check out the complete file. 30. Modules and Packages: when we wrote our first Python file on the Functions lesson, we wrote our first module without knowing it. A Python module is a file containing fight on definitions and statements. The file name is the module name with the suffix dot b y a pendant. So why distinction? Why not call it just a python? Fire Models are special in the sense that we can import them from other places, not just run them, as we've done so far. To test that, make sure you're on our Python test directory. Let's rename the classes big y to animal P y by doing the following command. M V classes. Don't be why animal P y module file names are almost always reflective off the main class it contains. Also, remember that classes are almost always a singular and not a plural e. So it's the animal class, not the animals. Class animals are the instances of the animal class. Next, open the file on Adam or python anywhere and remove all the statements after Line 32. Make sure you have only the two classes on the file. Also, make sure to save the file now called Interactive Shell, by typing python on Windows Power Sale or Python three on Mac or Python anywhere and write the following command under prompt import animal. Nothing seems to happen, but now you can create an instance off Fido right from the shell without writing anything on the shell. We have all the animal class functionality. Notice how we did animal that dog toe, build an instance. The animal with Lower Case A refers to the module name I e. Animal dot b y. It's not the animal class, so when we say animal dot Dog, it means the dog class in the animal module, there's another way we can do this, but you need to exit and open the interactive shell again. So do exit part in theses and then run the interactive shell again. When we exit the shell, all the imports and viable are destroyed. So now do the following import form. This is much nicer. We now. Instead, she ate with blue toe equals dog notice. We don't have to manually import the animal class by phone is intelligent enough to figure that out because dog is extending the animal class. There's a cool standard function called there that you will use often with dear. You can get all the viable methods and modules available for a specific module. For example, let's say you wanted to see what's available for the Pluta instance. You can do dear off Fluto for a moment. Ignore the ones with the double underscores. Remember, we said these were the magic methods and they were part off old classes. But notice after those, we have both the animal and dog parameters and methods. 31. Running Modules: When you import the module from the terminal, you're expected to interact with it, using the statements necessary. But sometimes you want to run the module as a script and have it do something automatically or even pass parameters to it. There's a handy magic method available on the module, called name that has no value if it was executed from the interactive shell, but it will have the string main if it was executed from the terminal. Let's see that in action. Let's add an if command at the inn over class and test if name has the main string and execute the statements with it earlier. Automatically exit the interactive shell. If you're still there, saved a file and now do the following command from the terminal. As you can see here, the module executed two commands on the eve. Kloss. Now open the shell and do the import as we did before from Animal Import Doc. Nothing. We don't get any print out off the East thirsty method with a cyst library. We can also read the input from the command line. Let's say we want to override the sound title makes from the terminal. We can do the following now save the file and Rhonda multiple as before. That's what was expected from the dock class. Now let's override the sound Fighter makes now Fido House, thanks to our new argument past. 32. Packages: As your application grows, you will want to further subdivide modules into their own directories and wrap everything up in one top level directory. We call this a package, so let's create an animal package. First, we will create the folder animal on the score App on your user home folder. Make sure you look out from the interactive shell by typing exit or control D, and that you are in your Python Tests directory by typing PWD. Now create the animal on the score, APP directory and now move the animal P y Inside the Animal APP directory. You have just used three file system commands. PWD allows you to check for your at in the file system. Make dear allows you to create a directory in the current directory. M v. The Move Command allows it to move files or directories. Why called the directory animal on the score app and not just animal. We will see this in a bit, but let's just say for now that bad things happen when you called a package or directory name the same as a module or P y file More on that later. In order for us to be able to import our package or module folders. We need to notify Python somehow that this directory is special. To do that, you want to create a fire called in it B. Y inside of the animal on the score up folder. Does that sound familiar? Yes, it's very much like our class, innit method. And indeed, Python will execute whatever coat is in this file. Prior to loading the package or module on Mac and Windows, opened the Adam Editor in your Python test directory By doing adam dot now, select the animal on the Score Pap folder and hit the A key on your keyboard. You should see a prompt to create a new file type on the score on this court in it on the score on the score dot b y and hit. Enter on by phone anywhere. Click on the python on the score test link your upper left navigator, select the animal app link on the directory section and then enter on the score on the score in it on this score on the score dot p y on. Then you file input when the file opens. Just click on the animal on the score app link again. Now we're going to create a sub module called Canine that will have the dog class in a module cold dog. Follow the instructions below for your specific platform. 33. Packages in Windows and Mac: If you're using python anywhere, skip to the next section. Click on the animal folder again on Adam and this time hit capital airy and type canine. Next, click on the canine folder and do a again to create the underscore on the score in it on the score on this court dot B Y here and then click canine again to create dog dot p y Inside it. You can go ahead and close the underscore the score in it on the score the score dot b y taps as we don't need to do anything on them. Selected a class on the animal dark p Y file. Cut it and paste it into the dog, not B Y file. Be careful to not copy the on the score in this court name on the score and the score equals equals main section. Leave that in animal dot p y. If you see bull circles on the tap, it means those files are not safe. So safe both with control s on windows or command s on Mac. Now we're going to move the underscoring the score name on the score on the score equals equals main section toe a file in the Python Tests folder. So go ahead and select that section. Click on Python tests, hit A and create a file called Ron dot b Y and save it there. However, since we're always going to run this file from the terminal, take out the IV on this corner. Score name on the score in the score equals equals main and moved the whole block to the left. You can do that by selecting the whole block and pressing shift tab. Save both Ron P. Y an animal P Y. 34. Packages in PythonAnywhere: seen spice on anywhere uses. Clinics were going to use a couple of file and directory management commands, so make sure to have both the file editor and the bash console open on adjacent Windows again. Make sure you're in the Bison Tests folder by checking that the Prompt says by phone underscore tests. If it doesn't say that you're in the wrong directory just to see the till day slash python on the score tests. First, let's create an anti wrong Don't be wife file on the Python Tests folder. So do touch Rhonda P. Y. Then let's create the canine folder by doing make Dear Animal on the score. App slash k nine. Next, we need to create another, underscoring the score in it on the score in the score dot p y empty file inside of the canine folder. So to touch Animal on the score app slash canine slash in it up. Ey, Finally, we'll create another empty file called Doc Doc P. Y. Inside of canine that will hold our dog class. So just to touch animal on this score, canine slash doc B y. That's it. Let's continue selected a class on the animal dot p y file. Cut it and save the file. Be careful to not copy the name equals main section Live that in animal p y. You'll see the text on save changes next to the file name. Make sure to save the file before the next step. Now open the doctor wife file and based the code we have in memory and save the file. We're going to move. The name equals main section from animal P y toe the run people I file in the Python Tests folder. So go ahead and select that section, cut it and saved a file. Then paste it in Ron P Y and save again. However, since we're always going to run this file from the terminal, take out the if name equals main and moved the whole block to the left. You can do that by selecting the whole block, impressing shift tab safe Rhonda P. Y again, we're ready for the next step 35. Finalizing our Package: we need a couple of imports here before we run this. So the file were running is run dot b y. But for it to get access to the dark class needed to extend, she ate clued Oh, we need to import it. So in Ron P y at the following statement at the very top from animal underscore app dot canine dog import Doc, What the statement is saying is from the animal on the score APP package, go to the canine module and import the dog class from the dog sub module. The dots show us the folder structure at a glance. We need one more change before we run this. Now open the canine doc P Y file and notice how we're referencing the animal class. However, Python won't know what that class is, since it's not in the fall anymore. So we need to import that as well. So insert this line at the top from animal on the score app dot animal import animal and now save the file. Okay, let's walk this dog again. Make sure you're on the Python Tests folder. You'll see why I keep mentioning this later in this lesson. Bison wrong dot p y house. Awesome. It works exactly as before. But now we have, ah, much better structure layout that allows us to keep growing the animal library. 36. The Python Path: when you start learning python, One of the main causes of frustration is issues with models not found. Whenever you get those issues, just come back and review this lesson. There is a logical explanation of why Python doesn't find the module you're trying to import When you run a Python script, that Scripts directory becomes a starting point off where other modules are located. In our example when we ran Brown P Y earlier are homeopath Plus, the Python test directory became the Reference Directory, for example, in My Mac, That Directory WAAS users slash instructor slash python tests Remember we had from Animal on the score app dot can nine dot dog import dog at the top of the wrong people I file by phone could find the docks of module easily because every doctor in that expression represents a directory relative to where the Run B Y script was. Run i e. Users, instructor by thumb tests, animal app, canine dog. So let's try this. Moved around P y script toe the Animal APP Directory. You'll be faced with this scenario moralist, often where one script is related to the class itself and you don't want to have it floating around on the court base. So do the following move rump ey, animal app And now let's try to run it from the Python Tests folder where we are bison three animal app slash rump ey by. So he's saying it doesn't know where to find the animal act macho. Why do you say that, Python? It's right there. The promise. Now you're running the script from here. Users instructor by some tests Animal app. K nine Doc B Y. But you're telling Python another story on that import. You're telling it to search the animal app package from within the folder. So how do we tell Python to run this as if the script was running from the root directory? There is a very special module that can help us with this called say's dark path. That helps us retrieving the active folder. And the good news is that we can change it on the fly. So let's edit the rump ey file and put this couple of statements at the top of Run P y. And now run to file. This is what it looks like on my Mac on by phone, anywhere you get this. However, on Windows, it looks like this spot. The difference between the Mac and the Windows output that's right on Windows, the full just are separated by back slashes, whereas in the Mac and by phone anywhere, which are Lennox operating systems, they're separated by forward slashes. This is going to be a key Distinction will address later in this lesson. As you can see, this is a python list off absolute directories or path. Absolute means that they described not only the fragment off a directory, but all directories starting from the root folder in our computer. Can you spot that are Python Tests? Directory is the 1st 1 in the list. Turns out we can upend another item on this list with the root folder. We want to tell Python this application should be run from, so let's edit rump ey. And at that first path, you get on the output but without the animal on the score app folder above the print six path statement. Notice your path will be different than mine on Mac do on windows. Do on python anywhere do save it and run the fall again. It worked. Now notice the barks at the end, but more importantly, also at the end of the Six Paths list, we have the folder we upended. So in order for us to properly set up the folder we append, we need to work with relative paths. The upend would then be described relative to the root off her application, not the route off the hard drive. That way, no matter where people installed the animal app, they can run the rump ey script without any problem. To do that, we're going to use a serious of utilities in separate lines, and then we'll combine into one line. First, we need to get the current location off the file were running by phone No STIs through a library called Always So at always toe the import. Next, we need to know the name off the module and the filing we're currently running. They are just going to score file on the score on the score. Magic method does that for us. So at this command, then to know the name of the containing folder off this file, we used the following command. Now let's add a print statement to see what that looks like on delete the Prince Statement online. Eight. Let's from the file. As you can see on this score, underscore file on the scoring. This core tells us the folder name and script main, while OS dot Path that their name tells us the name of the containing folder. Now we need to know their parents off that folder to navigate through folders in a relative way, he used the dot dot notation. For example. Let's say we're in the Bison Tests folder to go into the animal At Folder. We type on the terminal CD Animal App. We're now inside the Animal APP folder. You can verify that by typing PWD or Current Working Directory Command, which tells us where we are to go back to the parent folder Python tests we can use CD dot dot check the p W. D. Now we can do a similar thing in our script and type something like dot, dot plus script folder name. But since different operating systems might use the folder separators, definitely. We used another OS utility called Join, so type the following and run it perfect. We now know the relative path off our parent folder, but we want to express this in absolute terms. Now the truth is that some directories can potentially be pointers toe other directories. These are called siblings or symbolic links on, even though you think you're in folder there A. You're really in other dear a. But the same link acts as if it were really in dear a. So we could potentially be running the script from one of these simple ings and running toe errors. So for this last step, we have the following. Now, if you're on the script, you'll get perfect. The route path now looks exactly the same as the one we had car coded before. 37. The PYTHONPATH Environment Variable: Let's see what this looks like in Windows looks very different, right? But the same code does the same thing in both operating systems, and that is a good thing. But of course, we won't add all this code every time we need to get the route bath. So go ahead and write this snippet somewhere where you have it handy. You're going to use it often. So replace all those lines with this and save the file notice. We break the parentheses to improve readability. There's another way to the find the path that your computer looks for scripts and that is through an environment viable called Python path Environment. Variables are viable, is that are available on the operating system level, and programs and users can set them just as any other script viable. Let's see how we do it in our different environments on Mac or Python anywhere. Do the following Echo Python path. If there are paths their opinion. Python tests absolute folder path with a column before your path. Otherwise, just put yours. You going to be WD toe. Get the full path. Now we'll check if your path is stored in the environment. Variables list for Windows Power Shell. Do the following. If there are paths, their upend yours with the same my colon before your path. Otherwise, just put yours now check if your path is there with the bison path set, we can remove the cease path. A pen statement from the Round P Y file. Save it and run the script. It will run just fine. Please note that these environment variables will disappear. Once a closer terminal. There is a way to make them stick, but that one is a bit out of scope for this course. Make sure to undo this change for the next part of the lesson, and that the wrong P Y script has this. At the beginning, the last thing I'll discuss is the naming off the modules or packages. Remember how we called the animal package animal on the score app and not animal? That was because we have a module called Animal Doctor ey. If you call the package animal as well, Typhon would be confused on the import statements. If you meant the package or the module, let's try that Rename animal on the score. App to animal open the animal slash romp ey file and replaced Line seven with this and now open canine Dr B. Y and replace line one with this. Now try to run the script. See that? It says Animal is not a package. That's because it's confused with animal dot B y. So whenever you see this kind of errors off packages or modules not found, check that the names of the packages and the modules are different. Make sure to undo these changes before we start a new lesson. If you messed up and want to make sure you're in the right spot, feel free to download the code. That was a lot to take in. But don't worry. Modules and packages are really easy once you start using them on a daily basis. 38. The Python Stack: Sometimes things go bad with your script. You might have seen some of these errors, but up during the course. If you type something incorrectly, it's a bit daunting for the beginner. When a script throws an error in Python, it's just not one line, but what seems a novel on the screen? The key here is not to panic and come through all the errors until you find something related to your script. You see Python works like a pancake stack. Your script is at the very top pancake, and the python interpreter is at the bottom. In the middle, there's a bunch off libraries and packages, often called middleware, that allow your script to the things that you normally would need to right from scratch every time. For example, one of the Web frameworks you learn soon, like flask or dango or libraries, like the Amazing Requests Library that allow you to connect to other websites. So when an air happens in your script by phone might be somewhere in that big stack and finds an event it can recover from and then needs toe work its way to the top to tell you which command cost the issue. So let's produce an error in our dog class on purpose. Online. 10 of the Doctor ey script. Let's create a water level integer viable and try to return it with the pence strength as to remember, you can't come. Karen ate a string with a number you need to convert the number toe a string first or used the F module, Save the file. And now, at this line at the end of front P Y. Save that. And now let's run the script. Well, that's not too bad. Just a few lines. Yes, in this case, since our program is so simple. But wait until you're running a full fledged Web platform. The error output can be many pages long. That trace back is what I was telling you as the concept of working older way to the top. See that the first layer of the air says starting line 14 of grumpy. Why the method is called Well, we know that that is not what caused the air, but Typhon starts there because that's what broke the execution. Then it goes a level down and points at Line 11 of Dr Ey, where the error is indeed located. Finally, Python tells us that something in that line must be a string and not an integer. Sometimes the air that Python reports it's not the real error at all. It's up to you to really figure out what the error ISS. But by looking at where Python thinks the error is, you can at least start digging close to it, I told. That helps you Pinpointing. Where there's occur is the wonderful python, the border, or PDB as its library is cold. Sometimes it's helpful to freeze time right before the error occurs to see what's happening while everything work correctly and then sort of see the crash in slow motion. So at the following snippet online 10 off Doc B Y import PDB PTV said Trace. If you're using Adam, you can just type PDB and you'll see the snippet magically appear. Save it and run the script again. As you can see, the script froze, and it's now saying it's on the water level line of the Doctor ey file and on the East thirsty method of the class. Then there's a little arrow, and it says water level equals zero, not stick a man that will be run next but hasn't being executed yet. This is called the cursor. Finally, the PDB prompt is waiting for you to issue a command or explore the viable or libraries until that moment. So try bring the water level viable to see what you get. Like I said, it's the next thing Python will execute, but it hasn't executed it yet. However, you can explore one of the class properties already set, for example. So how do we move forward in the script? We issue the next command or just end now. Notice the cursor moved one lying down. Now you can see the water level value we can see. The next line that will be executed is the one that throws the error. So go ahead and hit N. Uh huh. There's that pesky air here. You can reproduce it by typing the statement and trying to fix it on the command line itself. So now we know that if we used the F for murder instead, the error won't be thrown. But pity B is still there, waiting. You can hit N to see what happens here. Pdv saying it's going to return back to the calling script. So hit and again you see that Python returns the air back to the color in line 14 off from P Y on the command. It's on. At this point, we know what to do so we can use the continue command or just see there you reach the end. So let's fix the error and saved the script. Changeling 12th 2 and go ahead and remove the PDB line, save it and run the script again. It should work now. There are other PDB commands you can explore, but to be honest, that flow is what I used 99% of the time. Try putting PDV statements in other parts of the package and get acquainted with it. 39. Introduction to Unit Testing: one of the most important and most misunderstood practices that every professional developer most have. He's a good understanding off unit testing. There are testing libraries you might use down the road that give you specific benefits. But the bison language ships with a built in testing module that is very good called unit test. So let's try writing a test. Tests of a package are normally placed in the root folder of that package. In our case, we're going to write a test for the animal APP package. So on the Animal APP folder, create a tests file now online. One right import unit Test unit tests are object oriented, so you need to define a class that will contain all the individual tests so online. Three. Will right class test by phone Math unit has start test case in this class will test some python mathematical functions just to get acquainted with the concept. Your class name should be as specific as possible and describe what's being tested in it. Inside of this will create our first actual test so online five right to following. So here assert equal is a method provided by unit tests and allows to test if the python expression on the left is equal to the one on the right, and that's basically what testing means. It's writing expressions that you know should be true but that are broken by mistakes injected while developing the application. There's one important rule you must always remember. Write it down all the methods on your test. Most begin with award test and then an underscore and then the name of the test. This is how, by some recognizes these are tests and not other methods. So let's end the test class in there at the following at the end of the fire, save and run the test by doing by from three animal AP tests B y. If you notice closely, there's a little dot in there that the notes a test was run, which, in our case, waas test tradition. Let's do another test, but make this one fail in purpose to see what that's like So online. Eight. At the following, we know this test will fell because five minus three is two, not one. So save the file and let's run the test again. Well, that was ugly, but as you can see, one test ran with the little dots, and the next one failed, they noted with a capital F. Then Python tells us why it failed. So it raised the existing test Python methods test and replaced with the following code notice. We're adding that directory snippet for the test to be able to get its bearings online for Why don't we just put the test file on the root directory you ask? One thing you learn as you continue writing tests is that each package should have its own isolated test. So it's better for you to get used to putting each test inside the package. It's testing. Also notice how we have the test legs test for one small thing. Onley. Good tests are like that. They focus on little areas and not necessarily test every generation off how it fails, but a key piece off the functionality. We'll talk much more about tests. Incoming courses run the test and you'll see everything looks good. Let's add another test this time will test the coordinates. I know what you're thinking. This looks repetitive. Do we need to create the same animal instance twice? Why not use the same animal instance, we created on the previous test. Well, one thing you need to know and always remember is that with Ex test, all the data is wiped clean by phone. Makes it like this so that each test is independent from another. This is very important. Don't forget it. Save the file and run the tests. There is a functionality that we can use to make the test less repetitive. There's two special methods on the test case module called set up and tear Down that are executed before each test and after each test. In those methods, you can set up things that you want to be available and or disposed after each test. So let's do a set up for the test animal case. Change the foul so it looks like this that looks, march less repetitive. Notice that the animal instance was bound to the test animal class using the self in front of it. Otherwise, the tests wouldn't have access to it. Let's finish this by creating another class for the dark module. Why another class? Well, it's model needs to be tested separately, and you might want to set up different things. Plus, it reads much better and makes test more maintainable. Now run the tests. With these tests in place, you're not guaranteed that any changes you or any other developers make your code will function as it should. Let's do a simulation of this. Let's say that one of the developers in your team unknowingly changed the number off legs in Line five off the dock class. If you're on the test now, you'll get a failed test. This just means you'll always have peace of mind and be able to sleep a night. The last thing I'll mention is that when you have a bunch of tests, files and modules, you might not want to run them individually but might want to run them all at once. Unit Test has a handy discover module that automatically scans all packages and finds files named tests dot p y and runs them. I usually just at this file called Test Stop ey on the root folder off the application, and now you just run by from three tests B Y on. All your tests will be executed. It's your turn right to additional tests for the dark class, one for the East thirsty method and another one for the get breeds static method 40. Conclusion: congratulations on finishing the courts. You now have a really good foundation to start learning one of the fights on Web frameworks like the angle or flask. If you want to get the free e book for this course, head over to learn python web dot com slash e book. Also, check out my other courses and connect with me on www dot from zero dot io. See you in the next course.