Kernel: Python 3
In [1]:
Out[1]:
Enter your Emp ID1234
In [4]:
Out[4]:
SAI 34
In [18]:
Out[18]:
input 1= 2
input 2= 34
Enter your choice*
prod= 68
Return() is not mandatory in Python
To let a function return a value, use the return statement:
In [10]:
Out[10]:
1.1428571428571428
Different variable class can be passed within a function
In [ ]:
In [14]:
Out[14]:
The oldest employee is: er3
The oldest employee is: B
The oldest employee is: man
In [ ]:
In [19]:
Out[19]:
kiwi
apple
pie
abc
lambda - one line function which can take any number of argumnets:
In [20]:
Out[20]:
24.0
In [22]:
Out[22]:
729
In [27]:
Out[27]:
[2, 4, 4, 6, 8, 44, 20]
In [29]:
Write a Python script to display the various Date Time formats.
a) Current date and time
b) Current year
c) Month of year
d) Week number of the year
e) Weekday of the week
f) Day of year
g) Day of the month
h) Day of week
In [31]:
Out[31]:
Current date and time: 2021-02-01 16:53:32.344239
In [30]:
Out[30]:
Hi
Welcome
Python code to check time of execution of a program
In [ ]:
- 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 [ ]:
- Q Write a Python function that accepts a string and calculate the number of upper case letters and lower case letters
In [ ]:
Lamba Function
ambda 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 [ ]:
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 [ ]:
Classes in Python &OO programming
In [ ]:
In [ ]:
In [ ]:
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 [ ]:
Class name calci , compute sum, sub, divsion using a fucntion called finalo/p.
In [ ]:
In [ ]:
In [ ]:
In [ ]: