Showing posts with label Functions in Python. Show all posts
Showing posts with label Functions in Python. Show all posts

Functions in Python

A function is a block of statements 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 functions and we can have a user-defined function also in it. Functions in Python, we have three parts:


1) Function Declaration
2) Definition
3) Calling

Functions in Python

A 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 in 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 calls 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 lambdas are a one-line version of a function, they are not equivalent to inline statements in C or C++, whose purpose is bypassing function stack allocation during invocation for performance reasons.


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 elements in the list or number of characters 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

Deep Learning with Python “Data Science Training in Pune”

  Deep learning is also known as deep structured learning. It is part of a broader family of machine learning methods based on learning data...