DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Cover image for Functions in Python with examples.
Keshav Jindal
Keshav Jindal

Posted on

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 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.

Top comments (1)

Collapse
sandeeparora14 profile image
Sandeep

Good work

Head to your account's Settings to...

🌚 Enable dark mode
πŸ”  Change your default font
πŸ“š Adjust your experience level to see more relevant content