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

留言

這個網誌中的熱門文章

c語言-關於#define用法

CMD常用網管指令

PHP 與 JavaScript 之間傳值利用 json