X Tutup
Skip to content

5.3. タプルとシーケンスにおけるコードの脱落 #1015

@te-horie

Description

@te-horie

概要

チュートリアルの 5.3. タプルとシーケンス 中にあるコード例に脱落があり、実際の実行結果と合っていません。

問題のある箇所 (URLで指定すること)

チュートリアル 5.3. タプルとシーケンス
https://docs.python.org/ja/3/tutorial/datastructures.html#tuples-and-sequences

コードでは https://github.com/python/python-docs-ja/blob/3.14/tutorial/datastructures.po#L817-L818 です。

問題の詳細

第4段落の『問題は 0 個または 1 個の項目からなるタプルの構築です。』に箇所にあるコード例が

>>> empty = ()
>>> singleton = 'hello',    # <-- 末尾のカンマに注意
0
>>> len(singleton)
1
>>> singleton
('hello',)

となっていますが、singleton = 'hello', の後ろの len(empty) が抜けています。
原文 (https://docs.python.org/3/tutorial/datastructures.html#tuples-and-sequences) には len(empty) があるので、単純な脱落と思います。

修正案

上記の通り len(empty) を追加すれば良いと思います 🙂

 >>> empty = ()
 >>> singleton = 'hello',    # <-- 末尾のカンマに注意
+>>> len(empty)
 0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      X Tutup