こちらは「tuple」(Python組み込み型)のサンプルコードについての記事となっております。
目次
基本情報 … Basic Information
Pythonの「tuple」とは、値をカンマで区切って丸括弧で括った不変(immutable)のシーケンス(順序付きの要素集合)オブジェクトです。具体的には、以下のような機能を持っています。
- シーケンス型の一つで、要素はインデックスでアクセス可能です。
 - 値を変更できないため、変更不可能なリストとして使われることが多いです。
 - 要素が1つしかない場合は、要素の後ろにカンマをつけて定義する必要があります。
 - 複数の異なる型を含むことができます。
 - 他のデータ型との相互変換が可能です。
 - パッキングとアンパッキングができます。パッキングとは、複数の値を1つの変数にまとめることで、アンパッキングとは、タプルから複数の変数に値を代入することです。
 
チートシート … Cheat Sheet
| Create an Empty Tuple | a=() | () | |
| Create an Empty Tuple | a=tuple() | () | |
| Create a Number Tuple | a=(1,2,3) | (1,2,3) | |
| Create a String Tuple | a=(“one”,”two”,”three”) | (“one”,”two”,”three”) | |
| Delete a Tuple | del a | ||
| Get a Length of the Tuple | a=len(input_tuple) | A. (1,2,3)  B. (“one”,”two”,”three”)  | A. 3  B. 3  | 
| Get a Type of the Tuple | a=type(input_tuple) | A. (1,2,3)  B. (“one”,”two”,”three”)  | A. <class ‘tuple’>  B. <class ‘tuple’>  | 
| Get a Element of the Tuple with ID | a=input_tuple[target_id] | A. (1,2,3),1  B. (“one”,”two”,”three”), 1  | A. 2  B. “two”  | 
| Count a Value in the Tuple | a=input_tuple.count(target_val) | A. (1,2,3,3,3), 3  B. (1,2,3,3,3), 999 C. (“one”,”two”,”three”,”three”,”three”), “three” D. (“one”,”two”,”three”,”three”,”three”), “Three”  | A. 3  B. 0 C. 3 D. 0  | 
| Get 1st ID of Tuple with Value  Search 1st ID of Tuple with Value  | a = input_tuple.index(target_val)  * ValueError  | A. (1,2,3,1,1), 1  B. (1,2,3,1,1), 999  | A. 0  B. ValueError  | 
サンプルコード … Sample Code
001 タプルデータの生成, タプルデータの情報表示 … Create the Tuple Data, Get Information from the Tuple Data
・sam001 = (1,2,3,1,1)
| Length | len(sampleTuple) → int | len(sam001) | 5 | 
| Type | type(sampleTuple) → str | type(sam001) | <class ‘tuple’> | 
| Value by Id | sampleTuple[id] → int | sam001[0] | 1 | 
| Id by Value | sampleTuple.index(val) → int | sam001.index(1) | 0 | 
| Count by Value | sample.count(val) → int | sam001.count(1) | 3 | 
### Create Tuple
EMPTY_TUPLE = ()                    ### tuple()
INT_TUPLE   = (1,2,3)
STR_TUPLE   = ("one","two","three")
### print(EMPTY_TUPLE)  ### ()
### print(INT_TUPLE)    ### (1,2,3)
### print(STR_TUPLE)    ### ('one', 'two', 'three')
### Delete Tuple
### del tuple
INT_TUPLE   = (1,2,3)
del INT_TUPLE
### Read Length
### len(tuple)
INT_TUPLE   = (1,2,3)
### print(INT_TUPLE)                 ### (1,2,3)
### print(len(INT_TUPLE))            ### 3
### Read Type
### type(tuple)
INT_TUPLE   = (1,2,3)
### print(INT_TUPLE)                 ### (1,2,3)
### print(type(INT_TUPLE))           ### <class 'tuple'>
### Read Value at target_id
### tuple[target_id]
INT_TUPLE   = (1,2,3)
### print(INT_TUPLE)                 ### (1,2,3)
### print(INT_TUPLE[0])              ### 1
### Count target_val
### tuple.count(target_val)
INT_TUPLE   = (1,2,3,3,3)
### print(INT_TUPLE)                 ### (1, 2, 3, 3, 3)
### print(INT_TUPLE.count(3))        ### 3
### Get Index of 1st target_val
### tuple.index(target_val)
INT_TUPLE   = (1,2,3,1,1)
### print(INT_TUPLE)                 ### (1, 2, 3, 1, 1)
### print(INT_TUPLE.index(1))        ### 0このPythonプログラムはタプルに関するものです。 タプルとは、リストと同じようなもので、複数の値をまとめて格納することができますが、違いは一度作成されたタプルの値は変更できないことです。
このプログラムでは、タプルの作成方法、削除方法、長さの取得方法、型の取得方法、特定の値の取得方法、特定の値のカウント方法、特定の値のインデックスの取得方法などが説明されています。
タプルは、変更できない値を保持する必要がある場合に使用されます。リストのように、インデックスを使用してアクセスすることができますが、一度作成されたタプルの値は変更できないため、変更する必要がある場合は新しいタプルを作成する必要があります。
参考リンク … Reference Link

Built-in Types
The following sections describe the standard types that are built into the interpreter. The principal built-in types are...

Python Tuples - GeeksforGeeks
Tuples in Python are immutable, ordered collections that can hold elements of different data types and are created using...