Functions in Python with examples.

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 defin…


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’:’.
Image description
Image description

Calling of a function
Image description
In above example we called a function by its variable name and assigned a value to a.
Image description
Image description
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.

Image description
Types of functions
There are two types of functions:
1.Built-in functions
2.User defined functions
Image description

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


Print Share Comment Cite Upload Translate Updates
APA

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/

MLA
" » Functions in Python with examples.." Keshav Jindal | Sciencx - Thursday June 30, 2022, https://www.scien.cx/2022/06/30/functions-in-python-with-examples/
HARVARD
Keshav Jindal | Sciencx Thursday June 30, 2022 » Functions in Python with examples.., viewed ,<https://www.scien.cx/2022/06/30/functions-in-python-with-examples/>
VANCOUVER
Keshav Jindal | Sciencx - » Functions in Python with examples.. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/06/30/functions-in-python-with-examples/
CHICAGO
" » Functions in Python with examples.." Keshav Jindal | Sciencx - Accessed . https://www.scien.cx/2022/06/30/functions-in-python-with-examples/
IEEE
" » Functions in Python with examples.." Keshav Jindal | Sciencx [Online]. Available: https://www.scien.cx/2022/06/30/functions-in-python-with-examples/. [Accessed: ]
rf:citation
» Functions in Python with examples. | Keshav Jindal | Sciencx | 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.

You must be logged in to translate posts. Please log in or register.