Introduction to Python
Component of Python
A function is group related statement that performs the specific task.Python provide built-in function like print() etc. you create own function that is called user defined function.
We can pass data ,known as parameters into a function.
Function defined in the Python using def keyword.
Syntax of Python :
To call a function we use the function name and followed by parenthesis()
Once we have create a function and we can call it from another function . To call a function we simply type the function name with appropriate parameters.
Information can be passed to a function known as a parameters.parameters specified after the function name,and inside the parentheses.you can add the more parameter as we want,just separate them with comma.
print(fname+ "Hello" )
So just by calling the function we get our desired output
If we are call function without any parameter thats is uses the default values .
def myFun(x, y=15):
print("x: ", x)
print("y: ", y)
here we just assign the value to 'x' but in the output we get the default value of 'y' too.
We can send the all data type parameter to a function such as a (String,Number,list,Dictionary etc..) it will be created same data type in a function.
for x in food:
fruits = ["Banana", "Mango", "Apple"]
here we just get the list in sequence just bvy the calling the function.
The return statement with no argument is the same as return none.To let function return we can use return statement.
return 9 + y
So here in return we are getting 9 added to the values we assigned at the time of calling function.
Recursion is process to defining something in terms of itself.
if x == 1:
return (x * calc_factorial(x-1))
print("The factorial of", num, "is", calc_factorial(num))
So here we get the factorial value of 5.
python training insitute| Best IT Training classes in Gurgaon | python training