Practical7 Python Programming 1tsdkaMEsU
Practical7 Python Programming 1tsdkaMEsU
PRACTICAL 7
Part A (To be referred by students)
Built-in Functions
8. Write map function to return a list of numbers which are square of first 10 Fibonacci
numbers.
9. Write a lambda function for adding 26 to its argument, also create a lambda function
that multiplies argument x with argument y and print the result.
10. A twitter database is given in which we have username and tweets.
users = [ {"username": 'seema', "tweets": ["i love chocolate", "i am a student"]},
{"username": 'arush', "tweets": []}, {"username": 'kumal', "tweets": ["India",
"Python"]}, {"username": 'sam', "tweets": []}, {"username": 'lokesh', "tweets":
["i am good"]}, ]
i) Filter out Users which don’t have any tweets/Inactive Users
ii) Filter inactive users with just username in uppercase.
iii) Return a new list with the string “your name is” + name, but only if length of
name is bigger than 4 using map , filter and Lambda
1|Page
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering/ School of Technology
Management & Engineering
Course: Python Programming
PROGRAMME: B.(Tech.)/MBA(Tech.)
First Year AY 2023-2024 Semester: II
names=['Rohan','Rhea','bob','to']
Output:['your name is Rohan', 'your name is Rhea']
Theory:
• Functions are sub program & in Python, interpreter creates an object of function
internally.
• Functions are used to perform a specific task
• If there are several tasks, one can write multiple functions
• When we define function inside a class, it is called as method.
• ‘def’ keyword is used to define functions
• Syntax of function definition:
def functionname(parameter list):
#function body
• A functions can not executes its own, it needs to call/invocation when required.
• Function is called using its name and passing values if any.
• Syntax:
functionname(value/values)
Example:-
• It is also possible to return values back to the calling place from function.
• Return is used to send value back to calling place.
• Advantages of Functions:-
• Reusability
2|Page
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering/ School of Technology
Management & Engineering
Course: Python Programming
PROGRAMME: B.(Tech.)/MBA(Tech.)
First Year AY 2023-2024 Semester: II
• Returning None
def fun():
print(1)
a=fun()
print(a)
Pass by Objects
• There are various function calling mechanisms like
• Call/pass by Value
• Call/pass by Address
• Call/pass by Reference
• But, Python programming supports call/pass by object.
• Because, everything is considered as object in Pyhon.
3|Page
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering/ School of Technology
Management & Engineering
Course: Python Programming
PROGRAMME: B.(Tech.)/MBA(Tech.)
First Year AY 2023-2024 Semester: II
Arguments:-
• Formal Arguments/Parameters
• Actual Arguments/Parameters
• Following Types of Arguments are supported by Functions in Python.
• Positional Arguments
• Keyword/named Arguments
• Default Arguments
• Variable Length Arguments
Recursion:-
• A Function having call to itself.
• Example:
def fun():
fun()
fun()
Built-in Functions:-
5|Page
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering/ School of Technology
Management & Engineering
Course: Python Programming
PROGRAMME: B.(Tech.)/MBA(Tech.)
First Year AY 2023-2024 Semester: II
6|Page
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering/ School of Technology
Management & Engineering
Course: Python Programming
PROGRAMME: B.(Tech.)/MBA(Tech.)
First Year AY 2023-2024 Semester: II
PRACTICAL 7
Part B (to be completed by students)
7|Page