每當我試着從我輸入我的名單追加數字,它去外面的支架,而不是兩個支架Python的 - 我如何追加號碼列表內,
裏面一個是有沒有辦法只有一對括號而不是兩個?
而且我想1-3之間添加隨機數,我得到的,
[[2, 1, 3]]
你怎麼能在十分之一創建隨機數的小數位
我的代碼,
import random
array = []
nums = random.sample(range(1, 4), 3)
array.append(nums)
print(array)
for x in range(2):
nums = int(input("what are your numbers "))
array.append(nums)
print(array)
我收到,
[[2, 1, 3]]
what are your numbers 3
[[2, 1, 3], 3]
what are your numbers 2
[[2, 1, 3], 3, 2]
Process finished with exit code 0
你的意思是'array = random.sample(range(1,4),3)'? – Shane
使用'array.extend' – ruaridhw
以前沒有人提到'extend',我對此印象非常深刻。謝謝@ruaridhw –