python-for用法

 假設我們想要將for迴圈的資料存成變數,其實可以利用一個空list方式來存取


test = []

sequences = [0, 1, 2, 3, 4, 5]

for i in sequences:

    print(i)

    test.append(i)

print (test)

test1 = ''.join(str(e) for e in test)

#list1 = ['1', '2', '3']

#str1 = ''.join(list1)

print (test1)



output如下

D:\>python test.py

0

1

2

3

4

5

[0, 1, 2, 3, 4, 5]

012345

留言

這個網誌中的熱門文章

c語言-關於#define用法

CMD常用網管指令

PHP 與 JavaScript 之間傳值利用 json