Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
y = [[0,0,0], [0,0,0]] p = [1,2,3,4,5,6] y[0] = p[0,2] y[1] = p[3,4]
エラーを返します に値を代入したいのですがp、yその方法は?
p
y
答えはy = [[1,2,3],[4,5,6]]
y = [[1,2,3],[4,5,6]]
どうもありがとうございました!
y = [] p = [1,2,3,4,5,6] y.append(p[:3]) y.append(p[3:]) print y --output:-- [[1, 2, 3], [4, 5, 6]]
スライスの最初の位置に値を指定しない場合、python は 0 を使用し、スライスの 2 番目の位置に値を指定しない場合、python はリストの残りを取得します。