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?

More than 3 years have passed since last update.

[Python]リスト

Posted at

#リスト
リスト作り方
[要素1 , 要素2 , 要素3]
, で区切る。

リスト例
文字列のリスト
["sushi" , "ramen"]

数値のリスト
[100 , 200]

変数にリストを代入

fruits = ["apple" , "banana" , "strawberry"]

リストの出力、要素の取得
リストの出力

fruits = ["apple" , "banana" , "strawberry"]

print(fruits)

出力結果
["apple" , "banana" , "strawberry"]


リストの要素の取得
変数[インデックス番号]
変数はリストを代入したもの

fruits = ["apple" , "banana" , "strawberry"]

print("好きな果物は" + fruits[1] + "です")

出力結果
好きな食べ物はbananaです


**要素の上書き**
リスト[インデックス番号] = 値

fruits = ["apple" , "banana" , "strawberry"]

fruits[1] = "kiwi"

**要素の追加**
リスト.append(値)

fruits = ["apple" , "banana" , "strawberry"]

fruits.append("kiwi")
0
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
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?