Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Other

Functions

Rating
-
Sold
-
Pages
56
Uploaded on
03-08-2023
Written in
2023/2024

I have 100+ example in functions.

Institution
Course

Content preview

All Function Methods:
Example: 1
Python Function with No argument and No Return value Example
def Adding():
a = 20
b = 30
Sum = a + b
print("After Calling :", Sum)
Adding()
O/P: After Calling : 50


Example: 2
Function with No arguments and with a Return value Example
def Multiplication():
a = 10
b = 25
Multi = a * b
return Multi
print("After Calling the Multiplication : ", Multiplication())
O/P: After Calling the Multiplication : 250


Example: 3
Python Function with argument and No Return value
def Multiplications(a, b):
Multi = a * b
print("After Calling the Function:", Multi)
Multiplications(10, 20)
O/P: After Calling the Function: 200

,Multiplications(15, 18)
O/P: After Calling the Function: 270


Example: 4
Python Function with arguments and Return value Example
def Addition(a, b):
Sum = a + b
return Sum
# We are calling the Function Outside the Definition
print("After Calling the Function:", Addition(25, 45))
O/P: After Calling the Function: 70


Syntax:
Syntax of Function
def function_name(parameters):
"""docstring"""
statement(s)


Example: 5
def greet(name):
"""
This function greets to
the person passed in as
a parameter
"""
print("Hello, " + name + ". Good morning!")
greet('saiii')
O/P: Hello, saiii. Good morning!
greet('Love')

,O/P: Hello, Love. Good morning!


Example: 6
In python, the function definition should always be present before the function call. Otherwise,
we will get an error. For example?
# function call
greet('Paul') #Fisrt hey function ni call chesthey error vasthadi. first function rayali next function
call cheyali.
# function definition
def greet(name):
"""
This function greets to
the person passed in as
a parameter
"""
print("Hello, " + name + ". Good morning!")
#first function cheysinaduku error vachindi.
O/P: NameError: name 'greet' is not defined


Example: 7
Docstrings:
def greet(name):
"""
This function greets to
the person passed in as
a parameter
"""
print("Hello, " + name + ". Good morning!")
print(greet.__doc__)
O/P:

, This function greets to
the person passed in as
a parameter


Example: 8
The return statement
The return statement is used to exit a function and go back to the place from where it was called.


Syntax of return
return [expression_list]


This statement can contain an expression that gets evaluated and the value is returned. If there is
no expression in the statement or the return statement itself is not present inside a function, then
the function will return the None object.


def greet(name):
"""
This function greets to
the person passed in as
a parameter
"""
print("Hello, " + name + ". Good morning!")
print(greet("May"))
O/P:
Hello, May. Good morning!
None




Example: 9
Example of return

Written for

Institution
Course

Document information

Uploaded on
August 3, 2023
Number of pages
56
Written in
2023/2024
Type
OTHER
Person
Unknown

Subjects

$9.39
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
saimuralidhar

Get to know the seller

Seller avatar
saimuralidhar Andhrapradesh
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
2 year
Number of followers
0
Documents
2
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions