INTRODUCTION TO FUNCTIONS - PYTHON PROGRAMMING

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello friends welcome back to our channel so in the previous sessions we have seen the concept of lists and tuples and also we have seen the basic operations performed on tuples so in this session let us start the new concept that is Python I mean function in Python so the basic major usage of writing these functions is reusability in order to achieve the reusability so reusability means once we write any function that function can be called a number of times that means we can use that function in meaning of programs right so so in order to rewrite any logic we can write a single generalized function and we can make use that function number of times and also easy debugging that means the finding and rectifying the errors will be easy for the user if we write these functions so in the absence of functions if you're any program makes a more lines of code or more complex logic then it would be difficult to find the errors in case of logical error it is somewhat difficult to find the logical errors right so if that can be written in functions then automatically this debugging process will be easier for the user right so the major results to writing the functions is real ready for easy debug you know so similar to the variable in C language we have seen the function declaration next function call next function definition so these we have seen in C problem so here we can avoid this declaration because so first we have to start writing the functional definition and then we will write the actual program so here we are not writing the many main functions or I I am just mentioning as an actual program right instead of using the main function and I am using the actual program so first I have to write the function definition and then we have to write the actual program where this function call is included so that's why this function declaration is not needed in Python from them right so how this function definition can be done so here in the function definition let us see that so what are the parameters involved in the function definition function definition so first one is every function should start with the EF keyword so we are having the BEF keyboard so all the function functions should start start with DF keyboard and every function should have a name so how a name not equal to any keyword so the same rules we have applied in C language right so we have to give one name specific name to the function because this is a user-defined function so the user is writing the function so we should give some name and that should not be equal to any one of the keyword so we have discussed the keywords in the previous session so just go through the keywords session so this name should not match it any one of the keyword next one is parametres or we can call them as arguments so parameters or arguments are nothing but the inputs given to that particular user defined function so this is an optional this is an optional so every function may have the parameters or arguments or may not have the parameter so it can have zero or more parameters or arguments and this should be included in between parentheses right so first we have to write the definition made DF keyword then we have to write the name and then we have lines the parameters or arguments in between the parentheses right this one is an optional next fourth one every function name with or without arguments should end with call corner so because in our C language we are not using the curly braces so instead of representing the block of statements that can be done only by using the indentation so here to achieve the indentation we have to use this column right next every function will be having some return so that return can be any value return or an empty later so finally the control will return to is calling function so every function will return to its calling function that may be an empty return or any value in term so return right it can be MD or a value returned so in C language every function will return only sing event right it cannot wear that means a function cannot return the multiple values but here in Python programming so function can return multiple values to the calling function that is done only by using tuples in the form of tuples right so in case of returning the multiple values that will be done only by using tuples so here the multiple return can be accepted multi value return can be done using tuples right so these are the some important points while writing the function function definition right so first it should start with the DF keyword next it should have some name which is which does not match with any one of the keywords and then we have to write the parameters that means inputs to the function that may be an optional thing and these parameters or arguments must be included in between the parentheses and after the balances every function should end with on so this gives the indentation that means a block of which represents a block of statements next every function will return the controller to its parent function calling function so that means that can be an empty return otherwise you later here the multi-value return can be done that base one function can return multiple values and that can be done only by using tuples so if you understood this function definition right now let us Mordor function call function1 so as we discussed in the C programming we have to write this function call in the same function or some parent function that is called as coding function right so here also while reading the program we have to declare this function call and by the control execute this function to automatically the pattern moves so the function definition right C so here the function call also have function name here also the function named arguments or parameters okay the only thing is this function name and our parameters should be equal to the function definition right so this one's the same function name should be written in function definition and the same number of arguments or parameters should be returned in function definition right the number of arguments should be equal in both function call and function definition and the function name should also be equal in both function name a function definition right and this function this function call will be written and whenever the control comes introduce this function if the function temperature will be executed so let us see an example so that the tour will be clarified right and as I said before here there is no question of function declaration because the function definition always starts at the beginning so first we have to write the function definition then only we have write the actual program C function to add two numbers function to add two numbers so first we have to write a function definition right so function definition we have to write DF some and by the parameters some a comma we use the columns because this represents the indentation now here we can write sum is equal to a plus B and next we have to write a vector or directly we can write it as being redone right written right now by the actual program J is equal to I cast because the input function always take the string enter first number next please equal to so reading the two values improvements input enter second input now write a function call listen is equal to and of PA problem P so this is a function called DAC the function name in both the function definitions are equal the number of parameters in both the function deficient function call are equal so here we are passing two arguments here where are in the parliament now print the result break reason is equal to 5 yes so this will give our resin right first we will read to Albert so this I am calling as an actual program actual program this I am calling the user-defined function use a different function and the actual program right so we have to write a function come in actual program and the function definition and that bearing of the program right so there is no question of function declaration so hope you understand hope you understood this simple concept the intervention basic interaction of functions in Python so let us stop here in the next session let us see the difference between the variables that means in the concept of functions so we will use a two types of variables that is a local variables and a global variables so I will explain the two local variables and global variables in the next session with the example so if you really understood my sessions so like my sessions share my sessions with your friends and if you are having any doubts regarding these functions or sex or tuples order list so feel free to post your notes in the comment section so that I will definitely try to clarify all your doubts so thanks for watching so I don't forget to subscribe to our channel thank you very much
Info
Channel: Sundeep Saradhi Kanthety
Views: 86,924
Rating: 4.9174943 out of 5
Keywords: SUNDEEP, SARADHI, KANTHETY, PYTHON, PROGRAMMING, HIGH-LEVEL, LANGUAGE, PORTABLE, FEATURES, APPLICATIONS, INSTALLATION, INTERPRETER, PYTHON SHELL, PYTHON SCRIPT, INTRODUCTION, BEGINNERS, function call, function definition, arguments, indentation, call by value, call by reference, return, function name, def keyword, user defined, function introduction, Python Function, Python def, Functional Programming, Python for Beginners, Absolute Beginners, python tutorial, args
Id: XjfvaFnJ4zk
Channel Id: undefined
Length: 14min 44sec (884 seconds)
Published: Fri Sep 28 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.