-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.py
More file actions
executable file
·52 lines (37 loc) · 1.1 KB
/
functions.py
File metadata and controls
executable file
·52 lines (37 loc) · 1.1 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/python
############################################
# #
# Program: functions.py #
# Author: Asanka Sayakkara #
# Description: #
# This script demonstrates the usage #
# of functions in Python. #
# #
############################################
# A function which accepts parameters by value
def multi_para_function(a, b):
a = 100
b = 200
#print("a=%d b=%d" % (a, b))
first=10
second=20
multi_para_function(first, second)
print("After the multi para function, first=%d second=%d" % (first, second))
# A function which accepts parameters by reference
def para_list_function(params):
params[0] = params[0] + 100
params[1] = params[1] + 200
params=[10, 20]
para_list_function(params)
print("After the para list function %s" % params)
def str_para_function(string):
print("string=%s" % string)
myStr="Hello!"
str_para_function(myStr)
print("-------------------------------")
print("Default Values")
def funcWithDefaults(para1, para2=30):
ans = para1 + para2
return ans
print("answer= %d" % funcWithDefaults(1, 2))
print("answer= %d" % funcWithDefaults(1))