Path: blob/master/Python Basics/Day 4 Functions and Classes.ipynb
3074 views
Kernel: Python 3 (ipykernel)
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
Return() is not mandatory in Python
To let a function return a value, use the return statement:
In [ ]:
In [ ]:
Different variable class can be passed within a function
In [ ]:
In [ ]:
In [ ]:
Practice Questions on Functions
Q Write a Python function to sum all the numbers in a list.
In [ ]:
Q Write a Python funtion to check whether a given number is the given range
In [ ]:
In [ ]:
In [ ]:
lambda - one line function which can take any number of argumnets
Lamba Function
The lambda keyword is used to create anonymous functions
This function can have any number of arguments but only one expression, which is evaluated and returned.
One is free to use lambda functions wherever function objects are required.
You need to keep in your knowledge that lambda functions are syntactically restricted to a single expression.
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
Write a Python program to sort a list of tuples using Lambda
In [ ]:
The power of lambda is better shown when you use them as an anonymous function inside another function.
In [ ]:
In [ ]:
In [ ]:
Date Time Module
In [ ]:
In [ ]:
In [ ]:
In [3]:
Out[3]:
Hi
Welcome
In [ ]:
In [ ]:
In [ ]:
In [ ]:
Classes in Python &OO programming
In [5]:
Out[5]:
__main__.Program1
In [6]:
Out[6]:
NAME is RAM and age is 29
In [7]:
Out[7]:
A 9
B 32
In [ ]:
In [ ]:
- self is used to represent the instance of the class. With this keyword, you can access the attributes and methods class in python. it helps to bind attributes with the given arguments.
- In Python we have methods that make the intance to be passed automatically, but not received automatically.
In [11]:
Out[11]:
<function X.student at 0x000001EB420864C0>
<bound method X.student of <__main__.X object at 0x000001EB418EB220>>
This is Science Class
Class name calci , compute sum, sub, divsion using a fucntion called finalo/p.
In [12]:
Out[12]:
23.5,1.064
In [ ]:
In [ ]: