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 1 year has passed since last update.

リスト

Posted at

List型

py.qiita.py
#  List型 データ構造
#  Listとは、複数の要素が入れられる変数?
l = [1, 2, 3, 4, 5]
print(l, 'クラスは、', type(l))

#  文字列も入れることが可能
l2 = ['nike', 'newbalance', 'adidas']
print(l2)

#  Bool値も入れることが可能
l3 = [True, 1, 'newbalance']
print(l3)

値の取り出し

py.qiitq.py
#  値の取りだし
print(l[0])
print(l2[0])
print(l3[2])

#  range関数を用いない方法
for i in l:
    print(i)
    
print('**************************************')

# range関数を用いた方法
for i in range(len(l)):
    print(l[i])

リストの中身とインデックス番号の両方を取り出す方法

py.qiita.py
#  リストの中身とインデックス番号を取り出したい時
#  enumerate関数を用いる
#  インデックス番号、中身の順に出てくる
#  l2 = ['nike', 'newbalance', 'adidas']
for i, j in enumerate(l2):
    print(i, j)
    
print('*****************************')
    
#  enumerateを使わない方法
#  こちらはあまり使わないらしい
for i in range(len(l2)):
    print(i, l2[i])

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?