Python 7.1 : Create a function
We are going to create a new project to do the expertise of the functions so new project, I am going to name function dash expert for expertise and after create close, I'm going to delete this here we're going to create a function that allows to display the information so I'm going to make def information for the name information dash Display colon parenthesis and inside I'm going to do a print I'm going to put titi I'm going to do another print I'm going to put mimi this is the code that must be inside the function and this code is not executable because at this level we have just finished the function so this is the definition and now if I delete the space that there is between the prints these 2 prints comes back to be defined in the main program and I'm going to comment this to be able to execute it I launch you see that it displays Tweety and Mimi on the other hand if I want, execute my function I delete this and I make Tabulation at this level to put that inside to execute my function I must call by putting the name of the function information display like this Put a small comment at the top and the call of the function and I exercise you see that there is Titi and Mimi that did not change Now we said that this function allowed to display the information of the persons so here I am going to put the person, is Titi that I am going to type in hard comma his age is 25 years I type in hard also and here I am going to say the name has characters here it is good and if I put for example here I make a print to delimit the program I put beginning of the program I'm going to copy and I want to put after the call of the function, here at the bottom I put rather end if I exercise you will see that we have beginning of the program, we have the person is Titi, his age and 25 years the name with 4 characters end of the program well if I copy this control v that I restart you see that we have the person is Titi his age is 25 years and the name with 4 characters twice simply because we had to call the function twice and now if I have 2 persons that I want to display the information At this level I am going to put information display titi hyphen 25 to say 25 years, and that I copy this control c control v and instead of Tweety I'll put Mimi here instead I'll rename mimi and I'm going to change the age when I call I want to call this function and I'm going to call I relaunch see how well I know the person and Tweety his age is 25 The name has four characters and the person is mimi his age is 35, the name has 4 characters if we do this the program works normally but we won't be taking advantage of the functions so to make the code more dynamic we ... We will see the parameters in the next video.