0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

要素の削除・挿入 Python3編

Last updated at Posted at 2023-12-11

忘れてしまったので調べて書いた。
要素削除にはpop()か、delをつかう。
違いは、popは()内に(●−1)番目を書き、
delは、配列[●−1]とかく

N,M = map(int,input().split())
A = list(map(int,input().split()))
A.pop(M-1) # この行は del A[M-1] でもOK
print(*A,sep="\n")

次は挿入

要素挿入にはinsert()
下記のように使う。

N,M,K = map(int,input().split())
A = list(map(int,input().split()))
A.insert(M-1,K)
print(*A,sep="\n")
0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?