This content originally appeared on DEV Community and was authored by Keshav Jindal
1.Introduction
A function is a set of specified code in which we given some input and the machine do some computation and gives us the output. Function helps in writing the same code again and again and we can get numerous out once a function is defined. The data is passed in parameters.
Syntax
Function is defined with the keyword ’def’ Followed by a variable name and ended with a colon’:’.
Calling of a function
In above example we called a function by its variable name and assigned a value to a.
In above example we added to value entered by user as many times the user want and we did not have to write the same code again and again because of function.
Types of functions
There are two types of functions:
1.Built-in functions
2.User defined functions
Common examples of built-in functions
1.print( ) function.
2.type( ) function.
3.input( ) function, etc.
User defined function
Functions which are defined by ourselves to perform some specified task are called user defined functions. They make code easy to understand by the user.
This content originally appeared on DEV Community and was authored by Keshav Jindal
Keshav Jindal | Sciencx (2022-06-30T07:09:37+00:00) Functions in Python with examples.. Retrieved from https://www.scien.cx/2022/06/30/functions-in-python-with-examples/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.