リストの取り出し
apple = ["Red","Delicious"] #リストの定義
print(apple[0]) #0番目の要素(Redを取り出す)
print(apple[0:2]) #0から2番目手前までの要素を取り出す(["Red","Delicious"]を取り出す。)
print(apple[0:1:2]) #0番目の要素を起点に2つおきに取り出す(["Red"]を取り出す。)
print(apple[-1:]) #-1番目の要素から最後まで取り出す(["Delicious"]を取り出す)
print(apple[:-1]) #最初から-1番目の要素まで取り出す(["Red"]を取り出す)
print(apple[0]) #0番目の要素(Redを取り出す)
print(apple[0:2]) #0から2番目手前までの要素を取り出す(["Red","Delicious"]を取り出す。)
print(apple[0:1:2]) #0番目の要素を起点に2つおきに取り出す(["Red"]を取り出す。)
print(apple[-1:]) #-1番目の要素から最後まで取り出す(["Delicious"]を取り出す)
print(apple[:-1]) #最初から-1番目の要素まで取り出す(["Red"]を取り出す)
要素の追加
apple.append("Fruits") #appleにFruitsの要素を追加する
→apple = ["Red","Delicious","Fruits"]となる
→apple = ["Red","Delicious","Fruits"]となる
※.appendは関数ではなくメソッド
要素の変更
apple[0] = "Blue" #appleの0番目の要素をBlueに変更する
→apple = ["Blue","Delicious","Fruits"]となる
→apple = ["Blue","Delicious","Fruits"]となる