As a programmer, you you'll spend 60% of your time coding and 40% of your time fixing bugs.
So it's very important to understand what errors are and how to fix them.
So let's revise.
Errors.
We have two types of errors, actually.
We have syntax errors and we have exceptions.
So syntax errors are errors which happen before the interpreter.
Compiles the codes.
So first the interpreter just checks the syntax, right?
It looks if you have the brackets correctly, the commas, the dots.
For example, this line here.
This starts with a square bracket, but it ends with a parentheses.
The correct code would be to have a closing parentheses here.
But that is not the case.
And that's why this code will return of this.
The results.
So this is a syntax error.
An error which happens before the code is compiled and executed for the processor.
So this year tells you with this arrow where the error is, so closing parentheses does not match.
Opening parenthesis.
Right.
That's quite clear.
But error messages are not always clear.
Let's look at this one here.
Right.
So we have this opening bracket.
We have this closing bracket.
That's fine.
But instead of the periods between the variable and the methods, we have a comma here.
So this should be a period.
In that case, we get a syntax error, of course, because the syntax is not correct, but the error
is not so clear.
The message it says that we forgot some parentheses around the comprehension target.
So the interpreter looks at these two and it thinks that perhaps you meant to have them inside parentheses
like that.
So it's not so clear for the interpreter to understand what you're actually doing.
So in that case, you should look carefully at the codes and try to use your experience to understand
where the syntax error actually is.
So in that case, this comma should be replaced with.
A period.
So these two were examples of syntax errors.
Then we have exceptions.
This code here is syntactically correct.
So all the symbols and the rules of the language syntax are respected.
But the problem here is that we have this variable which doesn't exist.
So the variable name itself is fine.
It's syntactically correct, but it has not been declared in the script.
That's why we get this name error.
So we have syntax errors and we have nightmares.
And then we have attribute errors, which is produced by this code, for example.
This is an attribute error because this method here has been mistyped.
There is not such a method for strings.
The correct method would be strip.
So in that case you get this attribute error.
So an attribute a method is actually an attribute.
So.
Here we are trying to access that strip attributes out of the string object.
That's why we get this error.
STR object has no attribute strip.
So such errors are caught when the interpreter is trying to compile the codes to make sense of the codes.
Here is another example.
So we asked the user to enter a number such as the year of birth, and then we have this variable currency
here.
Then we want to calculate the age of the person using the current year minus the year of birth for that
person.
And we print out age, but the user didn't enter the actual year, but they entered something like this,
right?
In that case, this produces a value error.
It says that this thing cannot be.
Convert it into an integer.
So the INT method expects something like a string which contains a number inside.
For example this here, but this is not really a number.
It contains some dots and things like that.
And that brings us to the.
Topic of handling exceptions.
Okay, so these are exceptions, value error, attribute error.
These are known as exceptions and try accepts helps us to predict an error.
So we get that code and we transform it into this code.
So we tried to get the input from the user.
We tried to convert it into an INT, and then we tried to calculate the age and then we print out the
age.
So if the user will enter the ear correctly, for example, 3001.
This code will be executed.
So in other words, where there are no errors, this code will be executed.
But if this code produces an error, then Python will execute this code.
Now it's better that instead of doing except here you should mention the actual error that you accept.
Which you expect.
So in this case, we expect a value error when the user doesn't enter a correct format, Right.
Like this one.
So it's it's better to specify the error specifically in here.
Now, this line here, it's better to keep it outside of this tri, except because.
You don't really expect an error in this declaration.
So mostly you want to put these dynamic codes inside the try block So whenever possible, try to put
other codes outside of the tri block.
If you can.
Otherwise it's fine.
If this was also inside this block.
Somewhere in here.
Right.
That would also be fine.
It's important to know that tri accepts does not catch syntax errors because try accepts only catches
exceptions which are codes when the interpreter is trying to compile the code.
So this code here, for example, has this age variable which is missing a parentheses.
So in that case, if you run this code you'll get a syntax error.
So the try block the try clause will not be able to catch that syntax error, which is a good thing.
So first of all, you always want to have your code syntactically correct.
Then you catch all the exceptions.
And then you might have the question, oh, when to use, accept and when to use even live else.
Well, here is an example of when you use a fails or if it fails.
So the try accepts block always catches errors.
It doesn't catch logical errors or logical cases.
For example, if you you want to tell the user that, oh, you're the age we calculate it for you is
too big, then you would want to find that out with an if condition here.
Because the interpreter doesn't know what a normal age is.
It doesn't know that humans cannot be 150.
So you have to use if else blocks for that.
Right.
Next topic comments and doc strings.
So this year is a docstring doc strings are used to document what a function does, so you place them
inside the function definition and you use these triple quotes here and there.
So this function is then called in here and then for commenting single lines of code or blocks of code
which are not functions, then you use comments.
So this comment here is telling something is trying to tell us something about the next line which is
placed underneath.
So this one.
But try to not overuse comments, for example.
I think this comment here would be unnecessary because it's clear to the programmer that you're actually
calling the function here so you can omit this comment.
So you only want to comment complex code which you think that it will be harder to understand if you
come back two weeks after or something like that.
Modules.
Modules are Python files which can be imported into another Python file.
So basically when you import my file, my file is a file named my file dot py.
And so when you import that python file, you are making available all the functions and the variables
that that script has inside.
So in here, let's say this my file that SPI script had this area function defined.
So let's suppose that this area function was defined in my file, that's P In that case, we can access
that by referring to my file dot area and then we call that area function and get the output in a variable.
Standard libraries are also.
Python files.
They can be one single dot P file or multiple files.
For example, glop is a standard library request is a standard library.
So these are libraries which you don't have to install.
These are included with Python.
So you just import them and then of course, you use them similarly as we did with this.
So my file area.
Glop that glop.
So glop is a function in the glop library area is a function in the my file module.
So this is a local module and this would be a standard library or a standard module.
You can see depending of whether this is a single file or multiple files.
So that particular function globe would return this list.
Now, sometimes you don't really know if that is a method or a function.
So if Globe is a library or a module, then this is probably a function.
But if this was a class, then this would have to be called a method.
Now it's really it doesn't matter much what you call this, a method or a function.
But if you really want to find out in part charm, you can right click and then you can go to the go
to menu and then go to implementations.
And there you will see what this really is.
If it's inside the glob that P file or if it's inside a class.
Right.
So here I've also tried to use the get function of the requests library so that it's used to get the
contents of a website and then print it out.
So the content is HTML, as you can see here.
It also contains other information which is inside the HTML, for example, this text here.
And so one third party libraries are libraries which have not been included with the Python interpreter.
So you have to install them with PIP installed followed by the library name.
Their behavior is, of course, the same as the standard library.
So you use them using the same syntax, Of course.
Web apps.
Web apps needs a third party library, also known as a framework, a web framework such as Tremlett.
So we did use Tremlett in the course, and we'll use it again to create more complex web apps.
So I'm not going to go deeper into explaining Web apps because we're going to work over and over again
with them throughout the course.
We also covered p one simple Google a library to create desktop apps.
We're going to have more Google apps in the course.
So I'm not going to explain those here as well.
So you have a chance to practice and practice these over and over again throughout the course, either
by instructor led projects or by your own projects, which I'll give you.
I'll hand you out the exercises, the requirements, and you'll be able to work on your own.
So thanks for following this series of reviews.
And let's move on to the real parts of the course building applications.
So it's going to be fun, I promise.
And I'll see you in the next video.