Python Class 12 | Introduction to Function in Python - Function tutorial in Python in hindi
Function is a subprogram or smaller unit of a program which accept arguments and returns the result to the main function.
A function is mainly used for reuse. It can be reuse in a program as many times as you want.
Definition of a function is done using keyword def.
A function makes a program easy to compile ,debug and run.
This topic is first chapter of class 12 computer science c.s. syllabus.
Function is a subprogram that works on some arguments (datas) passed in function and returns a value to main part.
A large program is broken down into smaller units known as functions.
Q) Why function is required?
Ans- The most important reason to use function is to make program handling easier as only a small part of the program needs to be deal at a time which is very easy to compile, debug and run.
In this chapter we are going to learn
How function works.
How we can create our own functions.
How can we use the same function which we have created.
Consider f(x)= 2x2 is a function in math so we can represent the same function in python as well.
Here function name f, has x its arguments i.e. Value given to it and 2x2 is its functionality and for different value of x function f(x) will return different results.
In Same way Python or any programming language supports functions which,
can have arguments (values given to it), if required.
can perform certain functionality (some set of statements).
can return a result based on arguments passed.
So the last mathematical function can be written in python like this
def func(x):
r=2 * x ** 2
return r
Where,
def is a keyword used to define a function.
func is name of function which is an identifier so it can be any name except keywords.
variable inside the parentheses are the arguments or parameters (value given to function).
colon (:) at the end of def line indicates a function block starts in program so indentation is required.
Statements inside function block are called body of the function and it specifies what our function is going to do.
return is a keyword which returns the computed result to main part.
Q) What is main part then, and where does function returns its value?
def func(x):
r=2 * x ** 2
return r
a=int(input(“Enter a number:”))
result=func(a) these two lines can be written in single line as
print(result) print(func(a))
#FunctioninPython #Functions #Pythonclass12
Видео Python Class 12 | Introduction to Function in Python - Function tutorial in Python in hindi автора Кодовое Время
Видео Python Class 12 | Introduction to Function in Python - Function tutorial in Python in hindi автора Кодовое Время
Информация
2 декабря 2023 г. 11:40:46
00:13:12
Похожие видео