python-自訂函式裡的for迴圈存成變數
def area(width, height):
return width * height
def print_welcome(name):
print("Welcome", name)
global test
test = []
sequences = [0, 1, 2, 3, 4, 5]
for i in sequences:
print(i)
test.append(i)
print (test)
global test1
test1 = ''.join(str(e) for e in test)
#list1 = ['1', '2', '3']
#str1 = ''.join(list1)
print_welcome("Runoob")
w = 4
h = 5
print("width =", w, " height =", h, " area =", area(w, h))
print (test1)
output如下:
D:\>python test.py
Welcome Runoob
0
1
2
3
4
5
[0, 1, 2, 3, 4, 5]
width = 4 height = 5 area = 20
012345
留言
張貼留言