Python 7.3 : The return
We are going to advance our learning and here we are going to see the keyword return which is a very important notion for the functions as well as the parameters, so what is the use of the word return, return is used to leave the function, to send a value which is not obligatory I am going to begin by putting, at this level comma the age is age and at this level I'm going to put age equal to 25 I restart my code you see it shows us that we have no name and the age is 25 this code we can write it differently by putting return at this level and removing the else why do I do that? I do this so that if we check the first if, if it's yes, we exit the function directly thanks to the word return and the rest of the code will not be executed unless the name is not an empty string. So if the name is not an empty string, it will enter the second if and it will execute this code to make a new function to check if the user is major or minor, I'm going to write that here a def major and takes in parameter the age and here I'm going to do if age superior to 18 return True we could write this code differently by doing if superior to 18 return, we're going to put superior or equal to 18 return true else return false so that means if the age is superior or equal to 18, return true else you return false but we prefer to put return false, so if it's not true we already know it's false I want to do a print at this level to call the age function so print colon is major comma I call the major function I'll enter 16 as a parameter and we can do it another way by creating an age variable at this level and just putting the age in the major parameter I'll run my code you'll see we say: you don't have a name the age is worth I'm going to comment on this and I'm going to run my code you'll see that it puts is major if I add the person and I relaunch it puts me the person is major false and if I put for example 18 at this level the person is major true so the code works normally here I will comment this and I will make another print double coast the person with comma years age and here I will put age equal to zero and at this level I will make a check if the function major parenthesis age colon print it is major else colon and here inside I am going to come to verify by making if age equal to zero colon return this way of writing is not good because in a function you can't return the values and at one point nothing which means that instead of putting nothing I'm going to put a return False which is better than putting an if that returns an element and an if that returns nothing it is not advised it should be noted that the word return is applied only in the functions if I make a check here I put for example one if the age is equal to zero return it writes me that in red because it is not advised the word return is applicable only in the functions on the other hand there is another word which makes it possible to say that the code was well carried out it's exist, exist zero means that the code has been taken into account and there is no error now in the ... if you want to return an error, you can put another number than zero If I run my code you will see that it displays the beginning of the program and then it puts Exist of code, that means that there was no error the code was taken into account now I will change this value and I will put 16 I restart, the person is 16 years old it is minor end of the program code works normally and that there is no problem nor error, we see you soon for a next video concerning the refactoring of the code.