ソースコード
#coding:utf-8
#tuple タプル
#tupleの定義
a = ("banana","apple","kiwi","strawberry","apple")
print(type(a),a)
x = (2,3,1,5)
print(type(x),x)
#join 2 tuples
y=a+x
print(type(y),y)
#Number of elements
print(f'yの要素数={len(y)}')
#The number of times an element appears
print(f'appleが{a.count("apple")}回現れた')
#Accessing tuple elements
print(a[:2],a[-1])
for x in a:
print(x)
#Tuples cannot be modified, so the following operations are not possible:
#a[1]="pear"
#print(a)
#Lists and Tuples: Updating a Tuple
b = list(a)
print(type(b),b)
b[1]="pear"
print(type(b),b)
a=tuple(b)
print(a)
#タプル要素の追加
tuple1 = ("トマト","白菜","人参","キャベツ")
list1 = list(tuple1)
list1.append("大根")
tuple1 = tuple(list1)
print(tuple1)
#
tuple2 =(11,34,56,23,89)
list2=list(tuple2)
list2.pop(3)
tuple2 = tuple(list2)
print (tuple2)