<jupyter_start><jupyter_text>tuple型オブジェクトの生成<jupyter_code>t = ()
type(t), t
t = (1,)
type(t), t
t = (1, 2)
type(t), t
t = (1, 2,)
type(t), t
t = 1, 2
type(t), t
t = ("M", 40)
t<jupyter_output><empty_output><jupyter_text>アンパック<jupyter_code>t = (0, 1)
a, b = t
print(f"a = {a}")
print(f"b = {b}")
l = [0, 1]
a, b = l
print(f"a = {a}")
print(f"b = {b}")<jupyter_output>a = 0
b = 1<jupyter_text>tuple のシークエンス型としての利用  [ ] による要素へのアクセス<jupyter_code>t = (1, 3, 2)
t
len(t)
t[0]
t[-1]
t[1:]<jupyter_output><empty_output><jupyter_text>for による要素へのアクセス<jupyter_code>for e in t:
    print(e)<jupyter_output>1
3
2<jupyter_text>tuple のイミュータブル性の確認<jupyter_code>t = (1, 3, 2)
t[0] = 4
print(id(t), t)
t += (4,)
print(id(t), t)<jupyter_output>140679108866208 (1, 3, 2)
140678163622320 (1, 3, 2, 4)
{'fraction_non_alphanumeric': 0.21694480102695765, 'fraction_numerical': 0.08600770218228498, 'mean_word_length': 5.842105263157895, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '220451', 'license': 'BSD-2-Clause', 'n_tokens_mistral': 510, 'n_tokens_neox': 469, 'n_words': 85, 'path': 'notebooks/tuple.ipynb', 'repo_name': 'sosuke-k/python-basics', 'size': '779'}