Python Basic Tutorials

Python is a high level general purpose programming language which has a clear/easy learning curve. Python programming language is massively used in various domains like Artificial Intelligence, Data Science, Web Development, Utilities Tools and Scripts and many more

Python is a Programming language, and the default Python we use is written in C programming language which is also referred to as CPython (Python implementation in C). There are various implementation of Python Programming language i.e Jython(in JAVA), Skulpt(in JS) e.t.c

To make everything easy: We refer CPython as Python

Python Anonymous Function

What is an anonymous function?-lambda() function.

Anonymous functions are those functions that are defined without defining their name. Normally functions are defined using the 'def' keyword but the anonymous one is defined using the 'lambda' keyword. That is why anonymous functions are also called lambda functions.

The anonymous approach of creating a function is useful when we try to pass a function as an argument to another function

Lambda functions can take any number of arguments but can take only one expression.

Its syntax is: lambda arguments : expressions Example1

>>>square = lambda x: x**2
>>>print(square(4))
   16
Example2(normal function vs lambda function)

#normal function.
def multiply(x,y):
    return x*y
print(cube(5,4))
#lambda function
print((lambda x,y: x*y)(5,6)) 
Output

20
30  
Passing a function as an argument to another function
     
n=25
def cube(f,num):
    return f(num)

func=lambda x: x**3
print(cube(func,n))
Output
15625