Python Online Training In Andhra Pradesh and Telangana
Opening Hours :7AM to 9PM
In this article, you'll learn about functions, what a function is, the syntax, components, and types of functions. Also, you'll learn to create a function in Python.
What is a function in Python?
In Python, a function is a group of related statements that performs a specific task.
Functions help break our program into smaller and modular chunks. As our program grows larger and larger, functions make it more organized and manageable.
Furthermore, it avoids repetition and makes the code reusable.
Above shown is a function definition that consists of the following components.
Keyword def that marks the start of the function header.
A function name to uniquely identify the function. Function naming follows the same rules of writing identifiers in Python.
Parameters (arguments) through which we pass values to a function. They are optional.
A colon (:) to mark the end of the function header.
Optional documentation string (docstring) to describe what the function does.
One or more valid python statements that make up the function body. Statements must have the same indentation level (usually 4 spaces).
An optional return statement to return a value from the function.
In Python language these Functions are classisfied into following types
If any Functions signature does not contain parameters is known as Noparametarized Functions Syntax:
If any Functions signature contains List of parameters is known as parametarized Functions Syntax:
Based on the return type these Functions are classified into following types
1.No return type with no Parametarized Function
2.No return type with Parametarized Function
3.return type with no Parametarized Function
4.return type with Parametarized Function