In this instructional video, Akansha Yadav explains the concept of functions in Python as reusable blocks of code that perform specific tasks. She describes why functions are useful for modularizing and repeating code, then walks through the exact syntax for defining a function using the `def` keyword, naming the function, adding parentheses, a colon, and an indented body. She demonstrates adding a parameter (`name`), using `print` inside the function, and calling the function with an argument to produce output like "Hello, Python". The tutorial emphasizes the role of parameters, the importance of proper syntax, and shows a concrete example of a greeting function.
Chapters
Ladies and gentlemen, in this video we are gonna see what functions are in programming. So in Python, functions is a reusable thing. It means it is a reusable block of a code. Suppose you have 10 lines of a code and you wanted to repeat it, you wanted to reuse it multiple times in your program. So what you can do is you can keep it as a function. So function is a reusable block of code that performs a specific task. It allows you to basically organize your code into manageable and modular pieces. So let us see that how to define. So for defining it, it's very simple. What you will do is you will write a keyword called def, following up with the— what the name you wanted to give it. Suppose I'm saying greet. Greeting. So greeting is the word that I am giving to my function, and after function it is compulsory to use the brackets. So the very important thing in the notation of the function is that the round bracket which I have used just now. So you will use round brackets, and after round brackets you will write colons. Following up by— when you will press Enter, you will be in the next line, and here you can write what you wanted to do. Suppose I wanted name, so what I will do is I will say print. This is how we define a function. Now I have defined one line of a code and I have given it a name. So one, uh, one, if I wanted to reuse it, what I will say, I will say greeting Python. So it's printing Python for me because the task of that function was to just print the name. So that is what the function is. Here we have just created a function with the name greeting and we have added name, name as a parameter. So whatever you're writing within the round brackets, it is a parameter. So it's a parameter, name is the parameter over here. And when I am calling this function, when the function prints the greeting to that function, suppose I want any message also, so you can write saying hello comma name. So it says, hello Python. Like this it works. So this is what the Python function is.