Visit BlogAdda.com to discover Indian blogs Visit blogadda.com to discover Indian blogs Functions in Python | Training Institute in Pune

Friday 20 July 2018

Functions in Python


A function id a block of statement in which instruction is given to perform a particular task. It provides code reusability. They provide better modularity of the program. Python has a number of built in function and we can have user defined function also in it. Functions in Python, we have three parts:

1) Function Declaration
2) Definition
3) Calling

Functions in Python

Function declaration is done first before giving the code to be performed. There is some rule for function definition

1) There is a keyword def followed by the function name and ()
2) The argument and parameter are given in ()
3) Colon: will be used for indentation
4) The first statement of the function is an optional statement which the documentation string or the docstring
5) The return statement exit the function and the return without argument will be similar to return none

Function definition in Python Programming will be code which we have to run to get the required output. Function calling can be done in two ways

1) Call by value
2) Call by reference

TYPES OF FUNCTION with Few Functions Example:

1) Function with no argument and no return value
2) Function with no argument and with return value
3) Function with argument and no return value
4) Function with argument and with return value

Function Argument:

1) Keyworded
2) Default
3) Variable length argument
4) Required Argument

The Anonymous Functions:

These functions are called anonymous because they are not declared in the standard manner by using the def keyword. You can use the lambda keyword to create small anonymous functions. For more details visit Python Training Institutes in Pune.

Lambda forms can take any number of arguments but return just one value in the form of an expression. They cannot contain commands or multiple expressions.

An anonymous function cannot be a direct call to print because lambda requires an expression. Lambda functions have their own local namespace and cannot access variables other than those in their parameter list and those in the global namespace.

Although it appears that lambda's are a one-line version of a function, they are not equivalent to inline statements in C or C++, whose purpose is by passing function stack allocation during invocation for performance reasons.

Read Paras Arora's answer to Why should I learn Python instead of Java? on Quora
Built-In Function in Python:

1) Print()-to print any value or anything on the screen
2) Abs()-Return the absolute value of a numeric value
3) Round()-Return the rounded value of a numeric value
4) Max()-return the largest item
5) Sorted()-it will sort in ascending order
6) Len()-give the number of element in the list or number of character of the string
7) Type()-give the type of variable
8) Zip()-create the tuples of variable
9) Chr()-return the string representing the character whose Unicode point is the integer given in ()
10) Filter()-Give an iterator for the element of inerrable for which the function give true

10 comments:

suman said...

best information for us.thank you.
Python 3 tutorial Python

Rahul thakkar said...

Good Post! Python was mainly developed for emphasis on code readability, and its syntax allows programmers to express concepts in fewer lines of code.

Mohan Sharma said...

Great Read! Python Training will help you master the concepts and gain in-depth experience in writing Python code and packages

Babit said...

Thank you for sharing the article. The data that you provided in the blog is informative and effective. Python Training Institutes in Pune

Anonymous said...

Your article is too good and informative. I am searching for Python and I get exact article i am thankful to you for sharing this educational article.

Python training in pune

Jitendra said...

Software defined networking is the in-demand skills for network engineers. Anyone can start getting skills through SD-WAN training course with experts.

Anonymous said...

Great post on function of python, keep posting more valuable information Python Course in Pune
Best python training institute in Pune

Bhumi Jakhar said...
This comment has been removed by the author.
shantanu said...

Great post, thanks for sharing valuable information, keep us posted more. Python Course in Pune

Python Classes in Pune<

iteducationcentre said...
This comment has been removed by the author.