Introduction
Setup
Operators
variable
String
Number
Dtype & Comment
Lists
Tuples
Sets
Dictionaries
if else statement
For Loop
While Loop
iterator & iterable
Pre-Built functions
Function
Decorators
generators
Types of errors
Exceptions Handling
OOP
Regular expression
Create module
OS module
Date module
Random module
Math
Statistics module
Exercise 1
Exercise 2
Exercise 3
Learn Data Structure & Algorithm
Learn Numpy
Learn Pandas
Learn Matplotlib
Learn Seaborn
Learn Statistics
Learn Math
Learn MATLAB
Learn Machine learning
Learn Github
Learn OpenCV
Learn Deep Learning
Learn MySQL
Learn MongoDB
Learn Web scraping
Learn Excel
Learn Power BI
Learn Tableau
Learn Docker
Learn Hadoop
Python provides a lot of functions to make our work easy. Among these functions some functions are very powerful and can give you effective result and make you work very easy. Let's discuss some python functions which you must know.
Zip function is used to concatenate two lists, sets, etc. It will concat according to the index number.
Example: Suppose you have two lists. Now you want to join those lists and make one list. You want to
join those list in such a way that first list first index value will be present at first then second list
first index value. Then first list second index value then second list second index value. To do this you will
use zip function.
Lambda is a Python built-in function. We can write a big function or code just in one line using lambda
function. It makes the code shorter. You can use condition or run for loop and also declare variables inside
lambda function.
Example:
Suppose you want to do sum of 5 with the user input value using a function. To do this you have to use at
least 3 lines of codes. But you can do this in one line using lambda function.
First, write lambda then parameters and expression
Syntax:
lambda parameter:expression
In the example, we have a variable X. Now we want to sum of 5 and 10. To do this with the lambda function we have to write lambda X variable then the formula X+10 and in the end give access to the variable to the lambda function. lambda function will take the value from the end where we gave access to the variable. Then the value will pass through the parameter and then the formula and then we got the result 15.
Example:2
This function is used in a for loop to track or get the position of items.
Example: Suppose you have a list and we know that the each value of a list has index number. Now using
a for loop you want to get each element of the list and also get the index number of that particular element
of the list. To do this you will use enumerate function.
In the example we have a list. Now we wanted to print all the element of that list one by one and with each element of the list we also want the index number of that element. To do this we used enumerate function.
This function works with iterable means list, tuple, etc. This function takes two parameters, the first parameter is function and the second parameter is iterable means list, tuple, etc. Map function also returns the output as iterable means list, tuple, etc.
Example:1Look in the example 1 we have list which contain numbers. Now we want to create a list where the elements will be the square of each number of the first list. To do this we used map function.
Example:2Look in the example 2 we have list which contain numbers as string. Now we want to make all then numbers string as integer number. To do this we used map function. After applying map function we got a new list which contains all integer form of the first list number string.
Example:3
The filter function is used to filter iterable means list, tuple, etc. If we give a condition and those
elements which can full fill the condition will stay and others will be removed. This function works only with
iterable means list, tuple, etc. This function takes two parameters, the first parameter is function and the
second parameter is iterable means list, tuple, etc. Map function also returns the output as iterable means
list, tuple, etc.
Example: Suppose you have a list. In that list you have numbers from one to ten. Now you want to create
a list from the existing list and want those elements of the existing list which are even numbers. To do this
you will use filter function.
In the example 1 we created a list using the existing list value and in the new list we have all those values which are even numbers of the first or existing list.
Example:2In the example 2 we created a list using the existing list value and in the new list we have all those values which are odd numbers of the first or existing list.