1
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?

pythonのリスト型の使い方(要素の連結、要素の取り出し:extend,スライス機能)

Last updated at Posted at 2024-03-18

リストの連結

>>> f_list = ['モモ', 'みかん', 'バナナ', 'イチジク', 'ブドウ']
>>> list_int = [-1, 1, 2, 4]
>>> f_list + list_int
['モモ', 'みかん', 'バナナ', 'イチジク', 'ブドウ', -1, 1, 2, 4]  

リストの連結。メソッド「extend」

>>> list_int.extend(f_list)
>>> print(list_int)
[-1, 1, 2, 4, 'モモ', 'みかん', 'バナナ', 'イチジク', 'ブドウ']

要素を取り出す。スライス機能

>>> list_f = [0,1,1,2,3,3,2,5,23,4,35]
>>> list_f[0:3]
[0, 1, 1]
>>> list_f[2:6]
[1, 2, 3, 3]
>>> list_f[:4]
[0, 1, 1, 2]
1
0
0

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
1
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?