-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmyfunction.py
More file actions
35 lines (26 loc) · 753 Bytes
/
myfunction.py
File metadata and controls
35 lines (26 loc) · 753 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#Example
#Creating a function
def my_function():
print("Hello from a function")
#Calling a Function
my_function()
#How to send parameters
def greetings(name):
print("Good Morning, "+name)
#Calling a greetings function
greetings("Vinay")
#Returning function
def addition(num1,num2):
return num1+num2;
#Calling addition function
#print("Addition =>"+addition(10,20)) #Will give error
result = addition(10,20)
print("Addition of 10 and 20 is {}".format(result))
#Default Parameter Value
#The following example shows how to use a default parameter value.
#If we call the function without parameter, it uses the default value:
def substraction(num1=0,num2=0):
print(num1-num2)
substraction(30,20)
substraction();
substraction(50,50)