3.6.4 +演算子と*演算子
w_str = "abc" + "def"
print(w_str)
->"abcdef"
w_str = "abc" * 3
print(w_str)
->"abcabcabc"
w_list = [12, 34, 56] + [78, 90]
print(w_list)
-> [12, 34, 56, 78, 90]
w_list = [12] * 5
print(w_list)
-> [12, 12, 12, 12, 12]
w_tuple = [12, 34, 56] + [78, 90]
print(w_tuple)
-> [12, 34, 56, 78, 90]
w_tuple = (12,) * 5
print(w_tuple)
-> (12, 12, 12, 12, 12)
※(12,) 要素最後にカンマ(,)を置くことでタプルであることを示します
+=演算子と *=演算子
w_list = [12, 34, 56]
print(w_list)
-> [12, 34, 56]
w_list += [78, 90]
print(w_list)
-> [12, 34, 56, 78, 90]
w_list = [12]
w_list *= 5
print(w_list)
-> [12, 12, 12, 12, 12]
3.6.5 indexメソッドとcountメソッド
indexメソッド シーケンス名.index(データ)
countメソッド シーケンス名.count(データ)
w_list = [11, 22, 33, 11, 11]
print(w_list.index(22))
->1
print(w_list.count(11))
->3
print(w_list.index(77))
->ValueError: 77 is not list