forked from xiyouMc/PythonGuide
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunction.py
More file actions
49 lines (39 loc) · 721 Bytes
/
Function.py
File metadata and controls
49 lines (39 loc) · 721 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
def my_abs(x):
if x>0:
return x
else:
return -x;
print my_abs(-10)
def power(x,n=2,a=1):
s = 1
while n >0:
n = n-1
s = s*x
return s
print power(2)
print power(2,a=2)
def add_end(L=None):
if L is None:
L = []
L.append('end')
print L
add_end()
#a^2 + b^2 + c^3
def calc(numbers):
sum = 0
for n in numbers:
sum = sum + n*n;
print sum
calc([1,3,5,7])
#*->can be Change
def calc(*numbers):
sum = 0
for n in numbers:
sum = sum + n*n;
print sum
calc(1,3,5,7)
# **
def calc(name,age,**kw):
print('name:',name,'age:',age,'other:',kw)
extra={'city':'Beijing','job':'Engineer'}
calc('Mark',23,**extra)