# SOME DESCRIPTIVE TITLE. # Copyright (C) 2001-2022, Python Software Foundation # This file is distributed under the same license as the Python package. # FIRST AUTHOR , YEAR. # # Translators: # Rafael Fontenelle , 2022 # #, fuzzy msgid "" msgstr "" "Project-Id-Version: Python 3.10\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2022-12-30 14:59+0000\n" "PO-Revision-Date: 2022-11-05 17:23+0000\n" "Last-Translator: Rafael Fontenelle , 2022\n" "Language-Team: Japanese (https://www.transifex.com/python-doc/teams/5390/" "ja/)\n" "Language: ja\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=1; plural=0;\n" #: ../../reference/expressions.rst:6 msgid "Expressions" msgstr "式 (expression)" #: ../../reference/expressions.rst:10 msgid "" "This chapter explains the meaning of the elements of expressions in Python." msgstr "この章では、Python の式における個々の要素の意味について解説します。" #: ../../reference/expressions.rst:12 msgid "" "**Syntax Notes:** In this and the following chapters, extended BNF notation " "will be used to describe syntax, not lexical analysis. When (one " "alternative of) a syntax rule has the form" msgstr "" "**表記法に関する注意:** この章と以降の章での拡張BNF (extended BNF) 表記は、字" "句解析規則ではなく、構文規則を記述するために用いられています。ある構文規則 " "(のある表現方法) が、以下の形式" #: ../../reference/expressions.rst:19 msgid "" "and no semantics are given, the semantics of this form of ``name`` are the " "same as for ``othername``." msgstr "" "で記述されていて、この構文特有の意味付け (semantics) が記述されていない場" "合、 ``name`` の形式をとる構文の意味付けは ``othername`` の意味付けと同じにな" "ります。" #: ../../reference/expressions.rst:26 msgid "Arithmetic conversions" msgstr "算術変換 (arithmetic conversion)" #: ../../reference/expressions.rst:30 msgid "" "When a description of an arithmetic operator below uses the phrase \"the " "numeric arguments are converted to a common type\", this means that the " "operator implementation for built-in types works as follows:" msgstr "" "以下の算術演算子の記述で、「数値引数は共通の型に変換されます」と書かれている" "とき、組み込み型に対する演算子の実装は以下の通りに動作します:" #: ../../reference/expressions.rst:34 msgid "" "If either argument is a complex number, the other is converted to complex;" msgstr "片方の引数が複素数型であれば、他方は複素数型に変換されます;" #: ../../reference/expressions.rst:36 msgid "" "otherwise, if either argument is a floating point number, the other is " "converted to floating point;" msgstr "" "それ以外の場合で、片方の引数が浮動小数点数であれば、他方は浮動小数点型に変換" "されます;" #: ../../reference/expressions.rst:39 msgid "otherwise, both must be integers and no conversion is necessary." msgstr "" "それ以外場合は、両方の引数は整数でなければならず、変換の必要はありません。" #: ../../reference/expressions.rst:41 msgid "" "Some additional rules apply for certain operators (e.g., a string as a left " "argument to the '%' operator). Extensions must define their own conversion " "behavior." msgstr "" "特定の演算子 ('%' 演算子の左引数としての文字列) には、さらに別の規則が適用さ" "れます。拡張は、それ自身の型変換のふるまいを定義していなければなりません。" #: ../../reference/expressions.rst:49 msgid "Atoms" msgstr "アトム、原子的要素 (atom)" #: ../../reference/expressions.rst:53 msgid "" "Atoms are the most basic elements of expressions. The simplest atoms are " "identifiers or literals. Forms enclosed in parentheses, brackets or braces " "are also categorized syntactically as atoms. The syntax for atoms is:" msgstr "" "atom は、式の一番基本的な要素です。もっとも単純な atom は、識別子またはリテラ" "ルです。丸括弧、角括弧、または波括弧で囲われた形式 (form) もまた、構文上アト" "ムに分類されます。atom の構文は以下のようになります:" #: ../../reference/expressions.rst:66 msgid "Identifiers (Names)" msgstr "識別子 (identifier、または名前 (name))" #: ../../reference/expressions.rst:70 msgid "" "An identifier occurring as an atom is a name. See section :ref:" "`identifiers` for lexical definition and section :ref:`naming` for " "documentation of naming and binding." msgstr "" "アトムの形になっている識別子 (identifier) は名前 (name) です。字句定義につい" "ては :ref:`identifiers` 節を、名前付けや束縛については :ref:`naming` 節を参照" "してください。" #: ../../reference/expressions.rst:76 msgid "" "When the name is bound to an object, evaluation of the atom yields that " "object. When a name is not bound, an attempt to evaluate it raises a :exc:" "`NameError` exception." msgstr "" "名前があるオブジェクトに束縛されている場合、名前 atom を評価するとそのオブ" "ジェクトになります。名前が束縛されていない場合、 atom を評価しようとすると :" "exc:`NameError` 例外を送出します。" #: ../../reference/expressions.rst:86 msgid "" "**Private name mangling:** When an identifier that textually occurs in a " "class definition begins with two or more underscore characters and does not " "end in two or more underscores, it is considered a :dfn:`private name` of " "that class. Private names are transformed to a longer form before code is " "generated for them. The transformation inserts the class name, with leading " "underscores removed and a single underscore inserted, in front of the name. " "For example, the identifier ``__spam`` occurring in a class named ``Ham`` " "will be transformed to ``_Ham__spam``. This transformation is independent " "of the syntactical context in which the identifier is used. If the " "transformed name is extremely long (longer than 255 characters), " "implementation defined truncation may happen. If the class name consists " "only of underscores, no transformation is done." msgstr "" "**プライベートな名前のマングリング:** クラス定義内に書かれた識別子で、2つ以上" "のアンダースコアから始まり、末尾が2つ以上のアンダースコアで終わっていないもの" "は、そのクラスの :dfn:`プライベートな名前` とみなされます。プライベートな名前" "は、コードが生成される前により長い形式に変換されます。この変換によって、クラ" "ス名の先頭にアンダースコアがあれば除去し、先頭にアンダースコアを1つ付加し、名" "前の前に挿入されます。例えば、クラス名 ``Ham`` の中の識別子 ``__spam`` は、" "``_Ham__spam`` に変換されます。変換は識別子が使用されている構文のコンテキスト" "からは独立しています。変換された名前が非常に長い (255文字を超える) 場合、実装" "によっては名前の切り詰めが行われるかもしれません。クラス名がアンダースコアの" "みから成る場合は変換は行われません。" #: ../../reference/expressions.rst:102 msgid "Literals" msgstr "リテラル" #: ../../reference/expressions.rst:106 msgid "Python supports string and bytes literals and various numeric literals:" msgstr "" "Python では、文字列やバイト列リテラルと、様々な数値リテラルをサポートしていま" "す:" #: ../../reference/expressions.rst:112 msgid "" "Evaluation of a literal yields an object of the given type (string, bytes, " "integer, floating point number, complex number) with the given value. The " "value may be approximated in the case of floating point and imaginary " "(complex) literals. See section :ref:`literals` for details." msgstr "" "リテラルの評価は、与えられた型 (文字列、バイト列、整数、浮動小数点数、複素" "数) の与えられた値を持つオブジェクトを与えます。浮動小数点や虚数 (複素数) リ" "テラルの場合、値は近似値になる場合があります。詳しくは :ref:`literals` を参照" "してください。" #: ../../reference/expressions.rst:121 msgid "" "All literals correspond to immutable data types, and hence the object's " "identity is less important than its value. Multiple evaluations of literals " "with the same value (either the same occurrence in the program text or a " "different occurrence) may obtain the same object or a different object with " "the same value." msgstr "" "リテラルは全て変更不能なデータ型に対応します。このため、オブジェクトのアイデ" "ンティティはオブジェクトの値ほど重要ではありません。同じ値を持つ複数のリテラ" "ルを評価した場合、(それらのリテラルがプログラムの同じ場所由来のものであって" "も、そうでなくても) 同じオブジェクトを指しているか、まったく同じ値を持つ別の" "オブジェクトになります。" #: ../../reference/expressions.rst:131 msgid "Parenthesized forms" msgstr "丸括弧形式 (parenthesized form)" #: ../../reference/expressions.rst:137 msgid "" "A parenthesized form is an optional expression list enclosed in parentheses:" msgstr "丸括弧形式とは、式リストの一形態で、丸括弧で囲ったものです:" #: ../../reference/expressions.rst:142 msgid "" "A parenthesized expression list yields whatever that expression list yields: " "if the list contains at least one comma, it yields a tuple; otherwise, it " "yields the single expression that makes up the expression list." msgstr "" "丸括弧で囲われた式のリストは、個々の式が表現するものになります: リスト内に少" "なくとも一つのカンマが入っていた場合、タプルになります; そうでない場合、式の" "リストを構成している単一の式自体の値になります。" #: ../../reference/expressions.rst:148 msgid "" "An empty pair of parentheses yields an empty tuple object. Since tuples are " "immutable, the same rules as for literals apply (i.e., two occurrences of " "the empty tuple may or may not yield the same object)." msgstr "" "中身が空の丸括弧のペアは、空のタプルオブジェクトを表します。\n" "タプルは変更不能なので、リテラルと同じ規則が適用されます (すなわち、空のタプ" "ルが二箇所で使われると、それらは同じオブジェクトになることもあるし、ならない" "こともあります)。" #: ../../reference/expressions.rst:156 msgid "" "Note that tuples are not formed by the parentheses, but rather by use of the " "comma operator. The exception is the empty tuple, for which parentheses " "*are* required --- allowing unparenthesized \"nothing\" in expressions would " "cause ambiguities and allow common typos to pass uncaught." msgstr "" "タプルは丸括弧で作成されるのではなく、カンマによって作成されることに注意して" "ください。例外は空のタプルで、この場合には丸括弧が *必要です* --- 丸括弧のつ" "かない \"何も記述しない式 (nothing)\" を使えるようにしてしまうと、文法があい" "まいなものになってしまい、よくあるタイプミスが検出されなくなってしまいます。" #: ../../reference/expressions.rst:165 msgid "Displays for lists, sets and dictionaries" msgstr "リスト、集合、辞書の表示" #: ../../reference/expressions.rst:169 msgid "" "For constructing a list, a set or a dictionary Python provides special " "syntax called \"displays\", each of them in two flavors:" msgstr "" "リスト、集合、辞書を構築するために、 Python は \"表示 (display)\" と呼ばれる" "特別な構文を提供していて、次の二種類ずつがあります:" #: ../../reference/expressions.rst:172 msgid "either the container contents are listed explicitly, or" msgstr "コンテナの内容を明示的に列挙する" #: ../../reference/expressions.rst:174 msgid "" "they are computed via a set of looping and filtering instructions, called a :" "dfn:`comprehension`." msgstr "" ":dfn:`内包表記 (comprehension)` と呼ばれる、ループ処理とフィルター処理の組み" "合わせを用いた計算結果" #: ../../reference/expressions.rst:182 msgid "Common syntax elements for comprehensions are:" msgstr "内包表記の共通の構文要素は次の通りです:" #: ../../reference/expressions.rst:190 msgid "" "The comprehension consists of a single expression followed by at least one :" "keyword:`!for` clause and zero or more :keyword:`!for` or :keyword:`!if` " "clauses. In this case, the elements of the new container are those that " "would be produced by considering each of the :keyword:`!for` or :keyword:`!" "if` clauses a block, nesting from left to right, and evaluating the " "expression to produce an element each time the innermost block is reached." msgstr "" "内包表記はまず単一の式、続いて少なくとも 1 個の :keyword:`!for` 節、さらに続" "いて 0 個以上の :keyword:`!for` 節あるいは :keyword:`!if` 節からなります。\n" "この場合、各々の :keyword:`!for` 節や :keyword:`!if` 節を、左から右へ深くなっ" "ていくネストしたブロックとみなし、ネストの最内のブロックに到達するごとに内包" "表記の先頭にある式を評価した結果が、最終的にできあがるコンテナの各要素になり" "ます。" #: ../../reference/expressions.rst:197 msgid "" "However, aside from the iterable expression in the leftmost :keyword:`!for` " "clause, the comprehension is executed in a separate implicitly nested scope. " "This ensures that names assigned to in the target list don't \"leak\" into " "the enclosing scope." msgstr "" "ただし、最も左にある :keyword:`!for` 節のイテラブル式を除いて、内包表記は暗黙" "的にネストされた個別のスコープで実行されます。\n" "この仕組みのおかげで、対象のリスト内で代入された名前が外側のスコープに \"漏れ" "る\" ことはありません。" #: ../../reference/expressions.rst:201 msgid "" "The iterable expression in the leftmost :keyword:`!for` clause is evaluated " "directly in the enclosing scope and then passed as an argument to the " "implicitly nested scope. Subsequent :keyword:`!for` clauses and any filter " "condition in the leftmost :keyword:`!for` clause cannot be evaluated in the " "enclosing scope as they may depend on the values obtained from the leftmost " "iterable. For example: ``[x*y for x in range(10) for y in range(x, x+10)]``." msgstr "" "最も左にある :keyword:`!for` 節のイテラブル式は、それを直接囲んでいるスコープ" "でそのまま評価され、暗黙的な入れ子のスコープに引数として渡されます。\n" "後に続く :keyword:`!for` 節と、最も左にある :keyword:`!for` 節のフィルター条" "件はイテラブル式を直接囲んでいるスコープでは評価できません。というのは、それ" "らは最も左のイテラブルから得られる値に依存しているかもしれないからです。\n" "例えば次の通りです: ``[x*y for x in range(10) for y in range(x, x+10)]`` 。" #: ../../reference/expressions.rst:208 msgid "" "To ensure the comprehension always results in a container of the appropriate " "type, ``yield`` and ``yield from`` expressions are prohibited in the " "implicitly nested scope." msgstr "" "内包表記が常に適切な型のコンテナになるのを保証するために、 ``yield`` 式や " "``yield from`` 式は暗黙的な入れ子のスコープでは禁止されています。" #: ../../reference/expressions.rst:215 msgid "" "Since Python 3.6, in an :keyword:`async def` function, an :keyword:`!async " "for` clause may be used to iterate over a :term:`asynchronous iterator`. A " "comprehension in an :keyword:`!async def` function may consist of either a :" "keyword:`!for` or :keyword:`!async for` clause following the leading " "expression, may contain additional :keyword:`!for` or :keyword:`!async for` " "clauses, and may also use :keyword:`await` expressions. If a comprehension " "contains either :keyword:`!async for` clauses or :keyword:`!await` " "expressions it is called an :dfn:`asynchronous comprehension`. An " "asynchronous comprehension may suspend the execution of the coroutine " "function in which it appears. See also :pep:`530`." msgstr "" "Python 3.6 から、 :keyword:`async def` 関数では :keyword:`!async for` 節が :" "term:`asynchronous iterator` の反復処理をするのに使われることがありました。\n" ":keyword:`!async def` 関数に含まれる内包表記が、先頭の式に続く :keyword:`!" "for` 節あるいは :keyword:`!async for` 節で構成されていることや、追加の :" "keyword:`!for` 節あるいは :keyword:`!async for` 節を含んでいること、そのう" "え :keyword:`await` 式を使っていることがあるかもしれません。\n" "内包表記が :keyword:`!async for` 節あるいは :keyword:`!await` 式を含んでいる" "場合、それは :dfn:`非同期内包表記` と呼ばれます。\n" "非同期内包表記は、それが現れるコルーチン関数の実行を中断させるかもしれませ" "ん。\n" ":pep:`530` も参照してください。" #: ../../reference/expressions.rst:227 msgid "Asynchronous comprehensions were introduced." msgstr "非同期内包表記が導入されました。" #: ../../reference/expressions.rst:230 ../../reference/expressions.rst:403 msgid "``yield`` and ``yield from`` prohibited in the implicitly nested scope." msgstr "" "``yield`` および ``yield from`` は暗黙的な入れ子のスコープでは禁止となりまし" "た。" #: ../../reference/expressions.rst:237 msgid "List displays" msgstr "リスト表示" #: ../../reference/expressions.rst:247 msgid "" "A list display is a possibly empty series of expressions enclosed in square " "brackets:" msgstr "" "リスト表示は、角括弧で囲われた式の系列です。系列は空の系列であってもかまいま" "せん:" #: ../../reference/expressions.rst:253 msgid "" "A list display yields a new list object, the contents being specified by " "either a list of expressions or a comprehension. When a comma-separated " "list of expressions is supplied, its elements are evaluated from left to " "right and placed into the list object in that order. When a comprehension " "is supplied, the list is constructed from the elements resulting from the " "comprehension." msgstr "" "リスト表示は、新しいリストオブジェクトを与えます。リストの内容は、式のリスト" "またはリスト内包表記 (list comprehension) で指定されます。\n" "カンマで区切られた式のリストが与えられたときは、それらの各要素は左から右へと" "順に評価され、その順にリスト内に配置されます。\n" "内包表記が与えられたときは、内包表記の結果の要素でリストが構成されます。" #: ../../reference/expressions.rst:263 msgid "Set displays" msgstr "集合表示" #: ../../reference/expressions.rst:272 msgid "" "A set display is denoted by curly braces and distinguishable from dictionary " "displays by the lack of colons separating keys and values:" msgstr "" "集合表示は波括弧で表され、キーと値を分けるコロンがないことで辞書表現と区別さ" "れます:" #: ../../reference/expressions.rst:278 msgid "" "A set display yields a new mutable set object, the contents being specified " "by either a sequence of expressions or a comprehension. When a comma-" "separated list of expressions is supplied, its elements are evaluated from " "left to right and added to the set object. When a comprehension is " "supplied, the set is constructed from the elements resulting from the " "comprehension." msgstr "" "集合表示は、新しいミュータブルな集合オブジェクトを与えます。集合の内容は、式" "の並びまたは内包表記によって指定されます。\n" "カンマ区切りの式のリストが与えられたときは、その要素は左から右へ順に評価さ" "れ、集合オブジェクトに加えられます。\n" "内包表記が与えられたときは、内包表記の結果の要素で集合が構成されます。" #: ../../reference/expressions.rst:284 msgid "" "An empty set cannot be constructed with ``{}``; this literal constructs an " "empty dictionary." msgstr "空集合は ``{}`` で構成できません。このリテラルは空の辞書を構成します。" #: ../../reference/expressions.rst:291 msgid "Dictionary displays" msgstr "辞書表示" #: ../../reference/expressions.rst:302 msgid "" "A dictionary display is a possibly empty series of key/datum pairs enclosed " "in curly braces:" msgstr "" "辞書表示は、波括弧で囲われた、キーと値のペアからなる系列です。系列は空の系列" "であってもかまいません:" #: ../../reference/expressions.rst:311 msgid "A dictionary display yields a new dictionary object." msgstr "辞書表示は、新たな辞書オブジェクトを表します。" #: ../../reference/expressions.rst:313 msgid "" "If a comma-separated sequence of key/datum pairs is given, they are " "evaluated from left to right to define the entries of the dictionary: each " "key object is used as a key into the dictionary to store the corresponding " "datum. This means that you can specify the same key multiple times in the " "key/datum list, and the final dictionary's value for that key will be the " "last one given." msgstr "" "キーとデータからなる対の並びがカンマ区切りで与えられたときは、その要素は左か" "ら右へ評価され、辞書のエントリーを定義します。すなわち、それぞれのキーオブ" "ジェクトが、辞書内で対応するデータを保存するキーとして使われます。\n" "これにより、キーとデータのリストの中で同じキーを複数回指定することができ、そ" "のキーに対する最終的な辞書の値は、最後に与えられたものになります。" #: ../../reference/expressions.rst:323 msgid "" "A double asterisk ``**`` denotes :dfn:`dictionary unpacking`. Its operand " "must be a :term:`mapping`. Each mapping item is added to the new " "dictionary. Later values replace values already set by earlier key/datum " "pairs and earlier dictionary unpackings." msgstr "" "ダブルアスタリスク ``**`` は :dfn:`辞書のアンパック` を表します。このとき被演" "算子は :term:`mapping` でなければなりません。それぞれのmappingの要素は、新た" "な辞書に追加されます。キー/データの対もしくは辞書のアンパックによって先に追加" "された値は、後から追加された値によって上書きされます。" #: ../../reference/expressions.rst:328 msgid "Unpacking into dictionary displays, originally proposed by :pep:`448`." msgstr "辞書表示のアンパックは最初に :pep:`448` で提案されました。" #: ../../reference/expressions.rst:331 msgid "" "A dict comprehension, in contrast to list and set comprehensions, needs two " "expressions separated with a colon followed by the usual \"for\" and \"if\" " "clauses. When the comprehension is run, the resulting key and value elements " "are inserted in the new dictionary in the order they are produced." msgstr "" "辞書内包表記は、リストや集合の内包表記とは対照的に、通常の \"for\" や \"if\" " "節の前に、コロンで分けられた 2 つの式が必要です。内包表記が起動すると、結果の" "キーと値の要素が、作られた順に新しい辞書に挿入されます。" #: ../../reference/expressions.rst:339 msgid "" "Restrictions on the types of the key values are listed earlier in section :" "ref:`types`. (To summarize, the key type should be :term:`hashable`, which " "excludes all mutable objects.) Clashes between duplicate keys are not " "detected; the last datum (textually rightmost in the display) stored for a " "given key value prevails." msgstr "" "キーの値として使える型に関する制限は :ref:`types` 節ですでに列挙しています。" "(一言でいうと、キーは変更可能なオブジェクトを全て排除した :term:`hashable` で" "なければなりません。) 重複するキー間で衝突が起きても、衝突が検出されることは" "ありません; あるキーに対して、最後に渡されたデータ (プログラムテキスト上で" "は、辞書表記の最も右側値となるもの) が使われます。" #: ../../reference/expressions.rst:345 msgid "" "Prior to Python 3.8, in dict comprehensions, the evaluation order of key and " "value was not well-defined. In CPython, the value was evaluated before the " "key. Starting with 3.8, the key is evaluated before the value, as proposed " "by :pep:`572`." msgstr "" "Python 3.8 より前のバージョンでは、辞書内包表記において、キーと値の評価順序は" "明示されていませんでした。CPython では、値がキーより先に評価されていました。" "バージョン 3.8 からは :pep:`572` で提案されているように、キーが値より先に評価" "されます。" #: ../../reference/expressions.rst:355 msgid "Generator expressions" msgstr "ジェネレータ式" #: ../../reference/expressions.rst:362 msgid "A generator expression is a compact generator notation in parentheses:" msgstr "" "ジェネレータ式 (generator expression) とは、丸括弧を使ったコンパクトなジェネ" "レータ表記法です:" #: ../../reference/expressions.rst:367 msgid "" "A generator expression yields a new generator object. Its syntax is the " "same as for comprehensions, except that it is enclosed in parentheses " "instead of brackets or curly braces." msgstr "" "ジェネレータ式は新たなジェネレータオブジェクトを与えます。この構文は内包表記" "とほぼ同じですが、角括弧や波括弧ではなく、丸括弧で囲まれます。" #: ../../reference/expressions.rst:371 msgid "" "Variables used in the generator expression are evaluated lazily when the :" "meth:`~generator.__next__` method is called for the generator object (in the " "same fashion as normal generators). However, the iterable expression in the " "leftmost :keyword:`!for` clause is immediately evaluated, so that an error " "produced by it will be emitted at the point where the generator expression " "is defined, rather than at the point where the first value is retrieved. " "Subsequent :keyword:`!for` clauses and any filter condition in the leftmost :" "keyword:`!for` clause cannot be evaluated in the enclosing scope as they may " "depend on the values obtained from the leftmost iterable. For example: " "``(x*y for x in range(10) for y in range(x, x+10))``." msgstr "" "ジェネレータ式の中で使われている変数は、 (通常のジェネレータと同じように) そ" "のジェネレータオブジェクトに対して :meth:`~generator.__next__` メソッドが呼ば" "れるときまで評価が遅延されます。\n" "ただし、最も左にある :keyword:`!for` 節のイテラブル式は直ちに評価されます。そ" "のためそこで生じたエラーは、最初の値が得られた時点ではなく、ジェネレータ式が" "定義された時点で発せられます。\n" "後に続く :keyword:`!for` 節と、最も左にある :keyword:`!for` 節のフィルター条" "件はイテラブル式を直接囲んでいるスコープでは評価できません。というのは、それ" "らは最も左のイテラブルから得られる値に依存しているかもしれないからです。\n" "例えば次の通りです: ``(x*y for x in range(10) for y in range(x, x+10))`` 。" #: ../../reference/expressions.rst:382 msgid "" "The parentheses can be omitted on calls with only one argument. See " "section :ref:`calls` for details." msgstr "" "関数の唯一の引数として渡す場合には、丸括弧を省略できます。詳しくは :ref:" "`calls` 節を参照してください。" #: ../../reference/expressions.rst:385 msgid "" "To avoid interfering with the expected operation of the generator expression " "itself, ``yield`` and ``yield from`` expressions are prohibited in the " "implicitly defined generator." msgstr "" "ジェネレータ式自身の期待される動作を妨げないために、 ``yield`` 式や ``yield " "from`` 式は暗黙的に定義されたジェネレータでは禁止されています。" #: ../../reference/expressions.rst:389 msgid "" "If a generator expression contains either :keyword:`!async for` clauses or :" "keyword:`await` expressions it is called an :dfn:`asynchronous generator " "expression`. An asynchronous generator expression returns a new " "asynchronous generator object, which is an asynchronous iterator (see :ref:" "`async-iterators`)." msgstr "" "ジェネレータ式が :keyword:`!async for` 節あるいは :keyword:`await` 式を含んで" "いる場合、それは :dfn:`非同期ジェネレータ式` と呼ばれます。\n" "非同期ジェネレータ式は、非同期イテレータである新しい非同期ジェネレータオブ" "ジェクトを返します (:ref:`async-iterators` を参照してください)。" #: ../../reference/expressions.rst:395 msgid "Asynchronous generator expressions were introduced." msgstr "非同期ジェネレータ式が導入されました。" #: ../../reference/expressions.rst:398 msgid "" "Prior to Python 3.7, asynchronous generator expressions could only appear " "in :keyword:`async def` coroutines. Starting with 3.7, any function can use " "asynchronous generator expressions." msgstr "" "Python 3.7 より前では、非同期ジェネレータ式は :keyword:`async def` コルーチン" "でしか使えませんでした。\n" "3.7 からは、任意の関数で非同期ジェネレータ式が使えるようになりました。" #: ../../reference/expressions.rst:410 msgid "Yield expressions" msgstr "Yield 式" #: ../../reference/expressions.rst:422 msgid "" "The yield expression is used when defining a :term:`generator` function or " "an :term:`asynchronous generator` function and thus can only be used in the " "body of a function definition. Using a yield expression in a function's " "body causes that function to be a generator function, and using it in an :" "keyword:`async def` function's body causes that coroutine function to be an " "asynchronous generator function. For example::" msgstr "" "yield 式は :term:`ジェネレータ ` 関数や :term:`非同期ジェネレータ " "` 関数を定義するときに使われます。従って、関数定義の" "本体でのみ使えます。\n" "関数の本体で yield 式 を使用するとその関数はジェネレータ関数になり、 :" "keyword:`async def` 関数の本体で使用するとそのコルーチン関数は非同期ジェネ" "レータ関数になります。\n" "例えば次のようになります::" #: ../../reference/expressions.rst:435 msgid "" "Due to their side effects on the containing scope, ``yield`` expressions are " "not permitted as part of the implicitly defined scopes used to implement " "comprehensions and generator expressions." msgstr "" "含まれているスコープの副作用のため、 ``yield`` 式は暗黙的に定義されたスコープ" "の一部として内包表記やジェネレータ式を実装するのに使うことは許可されていませ" "ん。 " #: ../../reference/expressions.rst:439 msgid "" "Yield expressions prohibited in the implicitly nested scopes used to " "implement comprehensions and generator expressions." msgstr "" "yield 式は、暗黙的な入れ子のスコープで内包表記やジェネレータ式を実装するため" "の使用が禁止になりました。" #: ../../reference/expressions.rst:443 msgid "" "Generator functions are described below, while asynchronous generator " "functions are described separately in section :ref:`asynchronous-generator-" "functions`." msgstr "" "ジェネレータ関数についてはすぐ下で説明されています。非同期ジェネレータ関数" "は、 :ref:`asynchronous-generator-functions` 節に分けて説明されています。" #: ../../reference/expressions.rst:447 msgid "" "When a generator function is called, it returns an iterator known as a " "generator. That generator then controls the execution of the generator " "function. The execution starts when one of the generator's methods is " "called. At that time, the execution proceeds to the first yield expression, " "where it is suspended again, returning the value of :token:`~python-grammar:" "expression_list` to the generator's caller. By suspended, we mean that all " "local state is retained, including the current bindings of local variables, " "the instruction pointer, the internal evaluation stack, and the state of any " "exception handling. When the execution is resumed by calling one of the " "generator's methods, the function can proceed exactly as if the yield " "expression were just another external call. The value of the yield " "expression after resuming depends on the method which resumed the " "execution. If :meth:`~generator.__next__` is used (typically via either a :" "keyword:`for` or the :func:`next` builtin) then the result is :const:" "`None`. Otherwise, if :meth:`~generator.send` is used, then the result will " "be the value passed in to that method." msgstr "" #: ../../reference/expressions.rst:465 msgid "" "All of this makes generator functions quite similar to coroutines; they " "yield multiple times, they have more than one entry point and their " "execution can be suspended. The only difference is that a generator " "function cannot control where the execution should continue after it yields; " "the control is always transferred to the generator's caller." msgstr "" "これまで説明した内容から、ジェネレータ関数はコルーチンにとてもよく似ていま" "す。ジェネレータ関数は何度も生成し、1つ以上のエントリポイントを持ち、その実行" "は一時停止されます。ジェネレータ関数は yield した後で実行の継続を制御できない" "ことが唯一の違いです。その制御は常にジェネレータの呼び出し元へ移されます。" #: ../../reference/expressions.rst:471 msgid "" "Yield expressions are allowed anywhere in a :keyword:`try` construct. If " "the generator is not resumed before it is finalized (by reaching a zero " "reference count or by being garbage collected), the generator-iterator's :" "meth:`~generator.close` method will be called, allowing any pending :keyword:" "`finally` clauses to execute." msgstr "" "yield 式は :keyword:`try` 構造内で使用できます。ジェネレータの (参照カウント" "がゼロに達するか、ガベージコレクションによる) 完了前に再開されない場合、ジェ" "ネレータ-イテレータの :meth:`~generator.close` メソッドが呼ばれ、:keyword:" "`finally` 節が実行されます。" #: ../../reference/expressions.rst:480 msgid "" "When ``yield from `` is used, the supplied expression must be an " "iterable. The values produced by iterating that iterable are passed directly " "to the caller of the current generator's methods. Any values passed in with :" "meth:`~generator.send` and any exceptions passed in with :meth:`~generator." "throw` are passed to the underlying iterator if it has the appropriate " "methods. If this is not the case, then :meth:`~generator.send` will raise :" "exc:`AttributeError` or :exc:`TypeError`, while :meth:`~generator.throw` " "will just raise the passed in exception immediately." msgstr "" "``yield from `` を使用した場合、与えられた式はイテラブルでなければなり" "ません。そのイテラブルをイテレートすることで生成された値は現在のジェネレータ" "のメソッドの呼び出し元へ直接渡されます。:meth:`~generator.send` で渡されたあ" "らゆる値と :meth:`~generator.throw` で渡されたあらゆる例外は根底のイテレータ" "に適切なメソッドがあれば渡されます。適切なメソッドがない場合、:meth:" "`~generator.send` は :exc:`AttributeError` か :exc:`TypeError` を、:meth:" "`~generator.throw` は渡された例外を即座に送出します。" #: ../../reference/expressions.rst:489 msgid "" "When the underlying iterator is complete, the :attr:`~StopIteration.value` " "attribute of the raised :exc:`StopIteration` instance becomes the value of " "the yield expression. It can be either set explicitly when raising :exc:" "`StopIteration`, or automatically when the subiterator is a generator (by " "returning a value from the subgenerator)." msgstr "" "根底のイテレータの完了時、引き起こされた :exc:`StopIteration` インスタンス" "の :attr:`~StopIteration.value` 属性はその yield 式の値となります。\n" ":exc:`StopIteration` を起こす際に明示的にセットされるか、サブイテレータがジェ" "ネレータであれば (サブイテレータからかえる値で) 自動的にセットされるかのどち" "らかです。" #: ../../reference/expressions.rst:495 msgid "Added ``yield from `` to delegate control flow to a subiterator." msgstr "" "サブイテレータに制御フローを委譲するために ``yield from `` が追加されま" "した。" #: ../../reference/expressions.rst:498 msgid "" "The parentheses may be omitted when the yield expression is the sole " "expression on the right hand side of an assignment statement." msgstr "yield 式が代入文の単独の右辺式であるとき、括弧は省略できます。" #: ../../reference/expressions.rst:504 msgid ":pep:`255` - Simple Generators" msgstr ":pep:`255` - 単純なジェネレータ" #: ../../reference/expressions.rst:504 msgid "" "The proposal for adding generators and the :keyword:`yield` statement to " "Python." msgstr "Python へのジェネレータと :keyword:`yield` 文の導入提案。" #: ../../reference/expressions.rst:508 msgid ":pep:`342` - Coroutines via Enhanced Generators" msgstr ":pep:`342` - 拡張されたジェネレータを用いたコルーチン" #: ../../reference/expressions.rst:507 msgid "" "The proposal to enhance the API and syntax of generators, making them usable " "as simple coroutines." msgstr "" "シンプルなコルーチンとして利用できるように、ジェネレータの構文と API を拡張す" "る提案。" #: ../../reference/expressions.rst:512 msgid ":pep:`380` - Syntax for Delegating to a Subgenerator" msgstr ":pep:`380` - サブジェネレータへの委譲構文" #: ../../reference/expressions.rst:511 msgid "" "The proposal to introduce the :token:`~python-grammar:yield_from` syntax, " "making delegation to subgenerators easy." msgstr "" "サブジェネレータの委譲を簡単にするための、 :token:`~python-grammar:" "yield_from` 構文の導入提案。" #: ../../reference/expressions.rst:515 msgid ":pep:`525` - Asynchronous Generators" msgstr ":pep:`525` - 非同期ジェネレータ" #: ../../reference/expressions.rst:515 msgid "" "The proposal that expanded on :pep:`492` by adding generator capabilities to " "coroutine functions." msgstr "" "コルーチン関数へのジェネレータの実装能力の追加による :pep:`492` の拡張提案。" #: ../../reference/expressions.rst:522 msgid "Generator-iterator methods" msgstr "ジェネレータ-イテレータメソッド" #: ../../reference/expressions.rst:524 msgid "" "This subsection describes the methods of a generator iterator. They can be " "used to control the execution of a generator function." msgstr "" "この説ではジェネレータイテレータのメソッドについて説明します。これらはジェネ" "レータ関数の実行制御に使用できます。" #: ../../reference/expressions.rst:527 msgid "" "Note that calling any of the generator methods below when the generator is " "already executing raises a :exc:`ValueError` exception." msgstr "" "以下のジェネレータメソッドの呼び出しは、ジェネレータが既に実行中の場合 :exc:" "`ValueError` 例外を送出する点に注意してください。" #: ../../reference/expressions.rst:535 msgid "" "Starts the execution of a generator function or resumes it at the last " "executed yield expression. When a generator function is resumed with a :" "meth:`~generator.__next__` method, the current yield expression always " "evaluates to :const:`None`. The execution then continues to the next yield " "expression, where the generator is suspended again, and the value of the :" "token:`~python-grammar:expression_list` is returned to :meth:`__next__`'s " "caller. If the generator exits without yielding another value, a :exc:" "`StopIteration` exception is raised." msgstr "" "ジェネレータ関数の実行を開始するか、最後に yield 式が実行されたところから再開" "します。ジェネレータ関数が :meth:`~generator.__next__` メソッドによって再開さ" "れた時、その時点の :keyword:`yield` 式の値は常に :const:`None` と評価されま" "す。その後次の :keyword:`yield` 式まで実行し、ジェネレータは一時停止し、:" "token:`~python-grammar:expression_list` の値を :meth:`__next__` メソッドの呼" "び出し元に返します。ジェネレータが次の値を yield せずに終了した場合、:exc:" "`StopIteration` 例外が送出されます。" #: ../../reference/expressions.rst:544 msgid "" "This method is normally called implicitly, e.g. by a :keyword:`for` loop, or " "by the built-in :func:`next` function." msgstr "" "このメソッドは通常、例えば :keyword:`for` ループや組み込みの :func:`next` 関" "数によって暗黙に呼び出されます。" #: ../../reference/expressions.rst:550 msgid "" "Resumes the execution and \"sends\" a value into the generator function. " "The *value* argument becomes the result of the current yield expression. " "The :meth:`send` method returns the next value yielded by the generator, or " "raises :exc:`StopIteration` if the generator exits without yielding another " "value. When :meth:`send` is called to start the generator, it must be " "called with :const:`None` as the argument, because there is no yield " "expression that could receive the value." msgstr "" "ジェネレータ関数の内部へ値を \"送り\"、実行を再開します。引数の *value* はそ" "の時点の yield 式の結果になります。 :meth:`send` メソッドは次にジェネレータが" "生成した値を返し、ジェネレータが次の値を生成することなく終了すると :exc:" "`StopIteration` を送出します。 :meth:`send` が呼び出されてジェネレータが開始" "するときは、値を受け取る yield 式が存在しないので、 :const:`None` を引数とし" "て呼び出さなければなりません。" #: ../../reference/expressions.rst:562 msgid "" "Raises an exception at the point where the generator was paused, and returns " "the next value yielded by the generator function. If the generator exits " "without yielding another value, a :exc:`StopIteration` exception is raised. " "If the generator function does not catch the passed-in exception, or raises " "a different exception, then that exception propagates to the caller." msgstr "" "ジェネレータが中断した位置で例外を発生させて、そのジェネレータ関数が生成する" "次の値を返します。ジェネレータが値を生成することなく終了すると :exc:" "`StopIteration` が発生します。ジェネレータ関数が渡された例外を捕捉しない、も" "しくは違う例外を発生させるなら、その例外は呼び出し元へ伝搬されます。" #: ../../reference/expressions.rst:568 msgid "" "In typical use, this is called with a single exception instance similar to " "the way the :keyword:`raise` keyword is used." msgstr "" #: ../../reference/expressions.rst:571 msgid "" "For backwards compatibility, however, the second signature is supported, " "following a convention from older versions of Python. The *type* argument " "should be an exception class, and *value* should be an exception instance. " "If the *value* is not provided, the *type* constructor is called to get an " "instance. If *traceback* is provided, it is set on the exception, otherwise " "any existing :attr:`~BaseException.__traceback__` attribute stored in " "*value* may be cleared." msgstr "" #: ../../reference/expressions.rst:585 msgid "" "Raises a :exc:`GeneratorExit` at the point where the generator function was " "paused. If the generator function then exits gracefully, is already closed, " "or raises :exc:`GeneratorExit` (by not catching the exception), close " "returns to its caller. If the generator yields a value, a :exc:" "`RuntimeError` is raised. If the generator raises any other exception, it " "is propagated to the caller. :meth:`close` does nothing if the generator " "has already exited due to an exception or normal exit." msgstr "" "ジェネレータ関数が一時停止した時点で :exc:`GeneratorExit` を発生させます。\n" "そして、ジェネレータ関数が無事に終了するか、既にクローズされているか、(例外が" "捕捉されなかったために) :exc:`GeneratorExit` が送出された場合、 close は呼び" "出し元へ戻ります。\n" "ジェネレータが値を生成する場合 :exc:`RuntimeError` が発生します。\n" ":meth:`close` はジェネレータが例外や正常な終了により既に終了している場合は何" "もしません。" #: ../../reference/expressions.rst:596 msgid "Examples" msgstr "使用例" #: ../../reference/expressions.rst:598 msgid "" "Here is a simple example that demonstrates the behavior of generators and " "generator functions::" msgstr "" "以下の簡単なサンプルはジェネレータとジェネレータ関数の振る舞いを実際に紹介し" "ます::" #: ../../reference/expressions.rst:625 msgid "" "For examples using ``yield from``, see :ref:`pep-380` in \"What's New in " "Python.\"" msgstr "" "``yield from`` の使用例は、\"What's New in Python.\" の :ref:`pep-380` を参照" "してください。" #: ../../reference/expressions.rst:631 msgid "Asynchronous generator functions" msgstr "非同期ジェネレータ関数 (asynchronous generator function)" #: ../../reference/expressions.rst:633 msgid "" "The presence of a yield expression in a function or method defined using :" "keyword:`async def` further defines the function as an :term:`asynchronous " "generator` function." msgstr "" ":keyword:`async def` を使用して定義された関数やメソッドに yield 式があると、" "その関数は :term:`非同期ジェネレータ ` 関数として定義" "されます。" #: ../../reference/expressions.rst:637 msgid "" "When an asynchronous generator function is called, it returns an " "asynchronous iterator known as an asynchronous generator object. That object " "then controls the execution of the generator function. An asynchronous " "generator object is typically used in an :keyword:`async for` statement in a " "coroutine function analogously to how a generator object would be used in a :" "keyword:`for` statement." msgstr "" "非同期ジェネレータ関数が呼び出されると、非同期ジェネレータオブジェクトと呼ば" "れる非同期イテレータが返されます。\n" "そして、そのオブジェクトはジェネレータ関数の実行を制御します。\n" "通常、非同期ジェネレータオブジェクトは、コルーチン関数内の :keyword:`async " "for` 文で使われ、これはジェネレータオブジェクトが :keyword:`for` 文で使われる" "様子に類似します。" #: ../../reference/expressions.rst:644 msgid "" "Calling one of the asynchronous generator's methods returns an :term:" "`awaitable` object, and the execution starts when this object is awaited on. " "At that time, the execution proceeds to the first yield expression, where it " "is suspended again, returning the value of :token:`~python-grammar:" "expression_list` to the awaiting coroutine. As with a generator, suspension " "means that all local state is retained, including the current bindings of " "local variables, the instruction pointer, the internal evaluation stack, and " "the state of any exception handling. When the execution is resumed by " "awaiting on the next object returned by the asynchronous generator's " "methods, the function can proceed exactly as if the yield expression were " "just another external call. The value of the yield expression after resuming " "depends on the method which resumed the execution. If :meth:`~agen." "__anext__` is used then the result is :const:`None`. Otherwise, if :meth:" "`~agen.asend` is used, then the result will be the value passed in to that " "method." msgstr "" "非同期ジェネレータのメソッドの 1 つを呼び出すと :term:`awaitable` オブジェク" "トが返され、このオブジェクトが動く番になったときに実行が開始されます。\n" "そのときに実行は最初の yield 式まで進み、そこで再び中断され、 :token:" "`~python-grammar:expression_list` の値を待機中のコルーチンに返します。\n" "ジェネレータと同様に、中断とは、現在のローカル変数束縛、命令ポインタ、内部評" "価スタック、および例外処理の状態など、すべてのローカルな状態が保たれることを" "意味します。\n" "非同期ジェネレータのメソッドから次のオブジェクトが返されたことで実行が再開さ" "れると、関数はあたかも yield 式が単なる外部呼び出しであるかのように処理を進め" "ていきます。\n" "再開後の yield 式の値は、実行を再開したメソッドによって異なります。\n" ":meth:`~agen.__anext__` を使った場合は、結果は :const:`None` になります。\n" "そうではなく、 :meth:`~agen.asend` が使用された場合は、結果はそのメソッドに渡" "された値になります。" #: ../../reference/expressions.rst:659 msgid "" "If an asynchronous generator happens to exit early by :keyword:`break`, the " "caller task being cancelled, or other exceptions, the generator's async " "cleanup code will run and possibly raise exceptions or access context " "variables in an unexpected context--perhaps after the lifetime of tasks it " "depends, or during the event loop shutdown when the async-generator garbage " "collection hook is called. To prevent this, the caller must explicitly close " "the async generator by calling :meth:`~agen.aclose` method to finalize the " "generator and ultimately detach it from the event loop." msgstr "" #: ../../reference/expressions.rst:669 msgid "" "In an asynchronous generator function, yield expressions are allowed " "anywhere in a :keyword:`try` construct. However, if an asynchronous " "generator is not resumed before it is finalized (by reaching a zero " "reference count or by being garbage collected), then a yield expression " "within a :keyword:`!try` construct could result in a failure to execute " "pending :keyword:`finally` clauses. In this case, it is the responsibility " "of the event loop or scheduler running the asynchronous generator to call " "the asynchronous generator-iterator's :meth:`~agen.aclose` method and run " "the resulting coroutine object, thus allowing any pending :keyword:`!" "finally` clauses to execute." msgstr "" "非同期ジェネレータ関数では、 :keyword:`try` 構造内の任意の場所で yield 式が使" "用できます。\n" "ただし、非同期ジェネレータが、(参照カウントがゼロに達するか、ガベージコレク" "ションによる) 終了処理より前に再開されない場合、 :keyword:`!try` 構造内の " "yield 式は失敗となり、実行待ちだった :keyword:`finally` 節が実行されます。\n" "このケースでは、非同期ジェネレータが作動しているイベントループやスケジューラ" "の責務は、非同期ジェネレータの :meth:`~agen.aclose` メソッドを呼び出し、残り" "のコルーチンオブジェクトを実行し、それによって実行待ちだった :keyword:`!" "finally` 節が実行できるようにします。" #: ../../reference/expressions.rst:680 msgid "" "To take care of finalization upon event loop termination, an event loop " "should define a *finalizer* function which takes an asynchronous generator-" "iterator and presumably calls :meth:`~agen.aclose` and executes the " "coroutine. This *finalizer* may be registered by calling :func:`sys." "set_asyncgen_hooks`. When first iterated over, an asynchronous generator-" "iterator will store the registered *finalizer* to be called upon " "finalization. For a reference example of a *finalizer* method see the " "implementation of ``asyncio.Loop.shutdown_asyncgens`` in :source:`Lib/" "asyncio/base_events.py`." msgstr "" #: ../../reference/expressions.rst:689 msgid "" "The expression ``yield from `` is a syntax error when used in an " "asynchronous generator function." msgstr "" "``yield from `` 式は、非同期ジェネレータ関数で使われると文法エラーにな" "ります。" #: ../../reference/expressions.rst:696 msgid "Asynchronous generator-iterator methods" msgstr "非同期ジェネレータイテレータメソッド" #: ../../reference/expressions.rst:698 msgid "" "This subsection describes the methods of an asynchronous generator iterator, " "which are used to control the execution of a generator function." msgstr "" "この小節では、ジェネレータ関数の実行制御に使われる非同期ジェネレータイテレー" "タのメソッドについて説明します。" #: ../../reference/expressions.rst:706 msgid "" "Returns an awaitable which when run starts to execute the asynchronous " "generator or resumes it at the last executed yield expression. When an " "asynchronous generator function is resumed with an :meth:`~agen.__anext__` " "method, the current yield expression always evaluates to :const:`None` in " "the returned awaitable, which when run will continue to the next yield " "expression. The value of the :token:`~python-grammar:expression_list` of the " "yield expression is the value of the :exc:`StopIteration` exception raised " "by the completing coroutine. If the asynchronous generator exits without " "yielding another value, the awaitable instead raises a :exc:" "`StopAsyncIteration` exception, signalling that the asynchronous iteration " "has completed." msgstr "" #: ../../reference/expressions.rst:718 msgid "" "This method is normally called implicitly by a :keyword:`async for` loop." msgstr "" "このメソッドは通常、 :keyword:`for` ループによって暗黙に呼び出されます。" #: ../../reference/expressions.rst:723 msgid "" "Returns an awaitable which when run resumes the execution of the " "asynchronous generator. As with the :meth:`~generator.send()` method for a " "generator, this \"sends\" a value into the asynchronous generator function, " "and the *value* argument becomes the result of the current yield expression. " "The awaitable returned by the :meth:`asend` method will return the next " "value yielded by the generator as the value of the raised :exc:" "`StopIteration`, or raises :exc:`StopAsyncIteration` if the asynchronous " "generator exits without yielding another value. When :meth:`asend` is " "called to start the asynchronous generator, it must be called with :const:" "`None` as the argument, because there is no yield expression that could " "receive the value." msgstr "" #: ../../reference/expressions.rst:738 msgid "" "Returns an awaitable that raises an exception of type ``type`` at the point " "where the asynchronous generator was paused, and returns the next value " "yielded by the generator function as the value of the raised :exc:" "`StopIteration` exception. If the asynchronous generator exits without " "yielding another value, a :exc:`StopAsyncIteration` exception is raised by " "the awaitable. If the generator function does not catch the passed-in " "exception, or raises a different exception, then when the awaitable is run " "that exception propagates to the caller of the awaitable." msgstr "" #: ../../reference/expressions.rst:753 msgid "" "Returns an awaitable that when run will throw a :exc:`GeneratorExit` into " "the asynchronous generator function at the point where it was paused. If the " "asynchronous generator function then exits gracefully, is already closed, or " "raises :exc:`GeneratorExit` (by not catching the exception), then the " "returned awaitable will raise a :exc:`StopIteration` exception. Any further " "awaitables returned by subsequent calls to the asynchronous generator will " "raise a :exc:`StopAsyncIteration` exception. If the asynchronous generator " "yields a value, a :exc:`RuntimeError` is raised by the awaitable. If the " "asynchronous generator raises any other exception, it is propagated to the " "caller of the awaitable. If the asynchronous generator has already exited " "due to an exception or normal exit, then further calls to :meth:`aclose` " "will return an awaitable that does nothing." msgstr "" #: ../../reference/expressions.rst:769 msgid "Primaries" msgstr "プライマリ" #: ../../reference/expressions.rst:773 msgid "" "Primaries represent the most tightly bound operations of the language. Their " "syntax is:" msgstr "" "プライマリは、言語において最も結合の強い操作を表します。文法は以下のようにな" "ります:" #: ../../reference/expressions.rst:783 msgid "Attribute references" msgstr "属性参照" #: ../../reference/expressions.rst:789 msgid "An attribute reference is a primary followed by a period and a name:" msgstr "属性参照は、プライマリの後ろにピリオドと名前を連ねたものです:" #: ../../reference/expressions.rst:799 msgid "" "The primary must evaluate to an object of a type that supports attribute " "references, which most objects do. This object is then asked to produce the " "attribute whose name is the identifier. This production can be customized " "by overriding the :meth:`__getattr__` method. If this attribute is not " "available, the exception :exc:`AttributeError` is raised. Otherwise, the " "type and value of the object produced is determined by the object. Multiple " "evaluations of the same attribute reference may yield different objects." msgstr "" "プライマリの評価は、属性参照をサポートする型のオブジェクトでなければならず、" "これにはほとんどのオブジェクトが当てはまります。そしてこのオブジェクトは、名" "前が指定した識別子名であるような属性を生成しなければなりません。この生成は :" "meth:`__getattr__` メソッドをオーバーライドすることでカスタマイズできます。そ" "の属性が得られなければ、例外 :exc:`AttributeError` が送出されます。そうでなけ" "れば、生成されるオブジェクトの型と値は、属性を生成したオブジェクトにより決ま" "ります。同じ属性参照を複数回評価すると、互いに異なる属性オブジェクトが得られ" "ることがあります。" #: ../../reference/expressions.rst:811 msgid "Subscriptions" msgstr "添字表記 (subscription)" #: ../../reference/expressions.rst:826 msgid "" "The subscription of an instance of a :ref:`container class ` " "will generally select an element from the container. The subscription of a :" "term:`generic class ` will generally return a :ref:" "`GenericAlias ` object." msgstr "" #: ../../reference/expressions.rst:834 msgid "" "When an object is subscripted, the interpreter will evaluate the primary and " "the expression list." msgstr "" #: ../../reference/expressions.rst:837 msgid "" "The primary must evaluate to an object that supports subscription. An object " "may support subscription through defining one or both of :meth:`~object." "__getitem__` and :meth:`~object.__class_getitem__`. When the primary is " "subscripted, the evaluated result of the expression list will be passed to " "one of these methods. For more details on when ``__class_getitem__`` is " "called instead of ``__getitem__``, see :ref:`classgetitem-versus-getitem`." msgstr "" #: ../../reference/expressions.rst:844 msgid "" "If the expression list contains at least one comma, it will evaluate to a :" "class:`tuple` containing the items of the expression list. Otherwise, the " "expression list will evaluate to the value of the list's sole member." msgstr "" #: ../../reference/expressions.rst:848 msgid "" "For built-in objects, there are two types of objects that support " "subscription via :meth:`~object.__getitem__`:" msgstr "" "組み込みオブジェクトでは、:meth:`~object.__getitem__` によって添字表記をサ" "ポートするオブジェクトには 2 種類あります:" #: ../../reference/expressions.rst:851 msgid "" "Mappings. If the primary is a :term:`mapping`, the expression list must " "evaluate to an object whose value is one of the keys of the mapping, and the " "subscription selects the value in the mapping that corresponds to that key. " "An example of a builtin mapping class is the :class:`dict` class." msgstr "" "マッピング。プライマリが :term:`マッピング ` であれば、式リストの値" "評価結果はマップ内のいずれかのキー値に相当するオブジェクトにならなければなり" "ません。添字表記は、そのキーに対応するマッピング内の値 (value) を選択します。" "組み込みのマッピングクラスの例は :class:`dict` クラスです。" #: ../../reference/expressions.rst:855 msgid "" "Sequences. If the primary is a :term:`sequence`, the expression list must " "evaluate to an :class:`int` or a :class:`slice` (as discussed in the " "following section). Examples of builtin sequence classes include the :class:" "`str`, :class:`list` and :class:`tuple` classes." msgstr "" "シーケンス。プライマリが :term:`シーケンス ` であれば、式リストの評" "価結果は :class:`int` または :class:`slice` (以下の節で論じます) でなければな" "りません。組み込みのシーケンスクラスの例には :class:`str`、:class:`list`、:" "class:`tuple` クラスが含まれます。" #: ../../reference/expressions.rst:860 msgid "" "The formal syntax makes no special provision for negative indices in :term:" "`sequences `. However, built-in sequences all provide a :meth:" "`~object.__getitem__` method that interprets negative indices by adding the " "length of the sequence to the index so that, for example, ``x[-1]`` selects " "the last item of ``x``. The resulting value must be a nonnegative integer " "less than the number of items in the sequence, and the subscription selects " "the item whose index is that value (counting from zero). Since the support " "for negative indices and slicing occurs in the object's :meth:`__getitem__` " "method, subclasses overriding this method will need to explicitly add that " "support." msgstr "" "形式的な構文は :term:`シーケンス ` の負のインデックスにいかなる特例" "も与えません。しかし、すべての組み込みのシーケンスが与える :meth:`~object." "__getitem__` メソッドは、負のインデックスを、インデックスにシーケンスの長さを" "加えて解釈するので、例えば、 ``x[-1]`` は ``x`` の最後の要素を選択します。結" "果の値はシーケンスの要素数より小さな非負の整数でなければなりません。添字表記" "は、(0 から数えた) インデックスを持つ要素を選択します。負のインデックスのサ" "ポートは、オブジェクトの :meth:`__getitem__` メソッドに現れるので、このメソッ" "ドをオーバーライドするサブクラスは、明示的にこのサポートを追加する必要があり" "ます。" #: ../../reference/expressions.rst:874 msgid "" "A :class:`string ` is a special kind of sequence whose items are " "*characters*. A character is not a separate data type but a string of " "exactly one character." msgstr "" ":class:`文字列 ` は文字 (*character*) を要素とする特別な種類のシーケンス" "です。文字は個別の型ではなく、 1 文字だけからなる文字列です。" #: ../../reference/expressions.rst:882 msgid "Slicings" msgstr "スライス表記 (slicing)" #: ../../reference/expressions.rst:896 msgid "" "A slicing selects a range of items in a sequence object (e.g., a string, " "tuple or list). Slicings may be used as expressions or as targets in " "assignment or :keyword:`del` statements. The syntax for a slicing:" msgstr "" "スライス表記はシーケンスオブジェクト (文字列、タプルまたはリスト) におけるあ" "る範囲の要素を選択します。スライス表記は式として用いたり、代入や :keyword:" "`del` 文の対象として用いたりできます。スライス表記の構文は以下のようになりま" "す:" #: ../../reference/expressions.rst:909 msgid "" "There is ambiguity in the formal syntax here: anything that looks like an " "expression list also looks like a slice list, so any subscription can be " "interpreted as a slicing. Rather than further complicating the syntax, this " "is disambiguated by defining that in this case the interpretation as a " "subscription takes priority over the interpretation as a slicing (this is " "the case if the slice list contains no proper slice)." msgstr "" "上記の形式的な構文法にはあいまいなところがあります: 式リストに見えるものは、" "スライスリストにも見えるため、添字表記はスライス表記としても解釈されうるとい" "うことです。(スライスリストが適切なスライスを含まない場合)、これ以上の構文の" "複雑化はせず、スライス表記としての解釈よりも添字表記としての解釈が優先される" "ように定義することで、あいまいさを取り除いています。" #: ../../reference/expressions.rst:921 msgid "" "The semantics for a slicing are as follows. The primary is indexed (using " "the same :meth:`__getitem__` method as normal subscription) with a key that " "is constructed from the slice list, as follows. If the slice list contains " "at least one comma, the key is a tuple containing the conversion of the " "slice items; otherwise, the conversion of the lone slice item is the key. " "The conversion of a slice item that is an expression is that expression. " "The conversion of a proper slice is a slice object (see section :ref:" "`types`) whose :attr:`~slice.start`, :attr:`~slice.stop` and :attr:`~slice." "step` attributes are the values of the expressions given as lower bound, " "upper bound and stride, respectively, substituting ``None`` for missing " "expressions." msgstr "" "スライス表記に対する意味付けは、以下のようになります。プライマリの値評価結果" "は、以下に述べるようにしてスライスリストから生成されたキーによって (通常の添" "字表記と同じ :meth:`__getitem__` メソッドを使って) インデクス指定できなければ" "なりません。スライスリストに一つ以上のカンマが含まれている場合、キーは各スラ" "イス要素を値変換したものからなるタプルになります; それ以外の場合、単一のスラ" "イス要素自体を値変換したものがキーになります。一個の式であるスライス要素は、" "その式に変換されます。適切なスライスは、スライスオブジェクト (:ref:`types` 参" "照) に変換され、その :attr:`~slice.start`, :attr:`~slice.stop` および :attr:" "`~slice.step` 属性は、それぞれ指定した下境界、上境界、およびとび幅 (stride) " "になります。式がない場所は ``None`` で置き換えられます。" #: ../../reference/expressions.rst:945 msgid "Calls" msgstr "呼び出し (call)" #: ../../reference/expressions.rst:947 msgid "" "A call calls a callable object (e.g., a :term:`function`) with a possibly " "empty series of :term:`arguments `:" msgstr "" "呼び出しは、呼び出し可能オブジェクト (例えば :term:`function`) を :term:" "`arguments ` の系列とともに呼び出します。系列は空の系列であってもか" "まいません:" #: ../../reference/expressions.rst:964 msgid "" "An optional trailing comma may be present after the positional and keyword " "arguments but does not affect the semantics." msgstr "" "最後の位置引数やキーワード引数の後にカンマをつけてもかまいません。構文の意味" "付けに影響を及ぼすことはありません。" #: ../../reference/expressions.rst:970 msgid "" "The primary must evaluate to a callable object (user-defined functions, " "built-in functions, methods of built-in objects, class objects, methods of " "class instances, and all objects having a :meth:`__call__` method are " "callable). All argument expressions are evaluated before the call is " "attempted. Please refer to section :ref:`function` for the syntax of " "formal :term:`parameter` lists." msgstr "" "プライマリの評価は呼び出し可能オブジェクトでなければなりません。 (ユーザ定義" "関数、組み込み関数、組み込みオブジェクトのメソッド、クラスオブジェクト、クラ" "スインスタンスのメソッド、および :meth:`__call__` メソッドを持つ全てのオブ" "ジェクトが呼び出し可能です)。引数式は全て、呼び出しを試みる前に評価されます。" "仮引数 (formal :term:`parameter`) リストの構文については :ref:`function` を参" "照してください。" #: ../../reference/expressions.rst:978 msgid "" "If keyword arguments are present, they are first converted to positional " "arguments, as follows. First, a list of unfilled slots is created for the " "formal parameters. If there are N positional arguments, they are placed in " "the first N slots. Next, for each keyword argument, the identifier is used " "to determine the corresponding slot (if the identifier is the same as the " "first formal parameter name, the first slot is used, and so on). If the " "slot is already filled, a :exc:`TypeError` exception is raised. Otherwise, " "the value of the argument is placed in the slot, filling it (even if the " "expression is ``None``, it fills the slot). When all arguments have been " "processed, the slots that are still unfilled are filled with the " "corresponding default value from the function definition. (Default values " "are calculated, once, when the function is defined; thus, a mutable object " "such as a list or dictionary used as default value will be shared by all " "calls that don't specify an argument value for the corresponding slot; this " "should usually be avoided.) If there are any unfilled slots for which no " "default value is specified, a :exc:`TypeError` exception is raised. " "Otherwise, the list of filled slots is used as the argument list for the " "call." msgstr "" "キーワード引数が存在する場合、以下のようにして最初に位置引数 (positional " "argument) に変換されます。まず、値の入っていないスロットが仮引数に対して生成" "されます。N 個の位置引数がある場合、位置引数は先頭の N スロットに配置されま" "す。次に、各キーワード引数について、識別子を使って対応するスロットを決定しま" "す (識別子が最初の仮引数名と同じなら、最初のスロットを使う、といった具合で" "す)。スロットがすでにすべて埋まっていたなら :exc:`TypeError` 例外が送出されま" "す。それ以外の場合、引数値をスロットに埋めていきます。 (式が ``None`` であっ" "ても、その式でスロットを埋めます)。全ての引数が処理されたら、まだ埋められてい" "ないスロットをそれぞれに対応する関数定義時のデフォルト値で埋めます。(デフォル" "ト値は、関数が定義されたときに一度だけ計算されます; 従って、リストや辞書のよ" "うな変更可能なオブジェクトがデフォルト値として使われると、対応するスロットに" "引数を指定しない限り、このオブジェクトが全ての呼び出しから共有されます; この" "ような状況は通常避けるべきです。) デフォルト値が指定されていない、値の埋めら" "れていないスロットが残っている場合 :exc:`TypeError` 例外が送出されます。そう" "でない場合、値の埋められたスロットからなるリストが呼び出しの引数として使われ" "ます。" #: ../../reference/expressions.rst:998 msgid "" "An implementation may provide built-in functions whose positional parameters " "do not have names, even if they are 'named' for the purpose of " "documentation, and which therefore cannot be supplied by keyword. In " "CPython, this is the case for functions implemented in C that use :c:func:" "`PyArg_ParseTuple` to parse their arguments." msgstr "" "実装では、名前を持たない位置引数を受け取る組み込み関数を提供されるかもしれま" "せん。そういった引数がドキュメント化のために '名付けられて' いたとしても、実" "際には名付けられていないのでキーワードでは提供されません。 CPython では、C 言" "語で実装された関数の、名前を持たない位置引数をパースするために :c:func:" "`PyArg_ParseTuple` を使用します。" #: ../../reference/expressions.rst:1004 msgid "" "If there are more positional arguments than there are formal parameter " "slots, a :exc:`TypeError` exception is raised, unless a formal parameter " "using the syntax ``*identifier`` is present; in this case, that formal " "parameter receives a tuple containing the excess positional arguments (or an " "empty tuple if there were no excess positional arguments)." msgstr "" "仮引数スロットの数よりも多くの位置引数がある場合、構文 ``*identifier`` を使っ" "て指定された仮引数がないかぎり、 :exc:`TypeError` 例外が送出されます; 仮引数 " "``*identifier`` がある場合、この仮引数は余分な位置引数が入ったタプル (もしく" "は、余分な位置引数がない場合には空のタプル) を受け取ります。" #: ../../reference/expressions.rst:1010 msgid "" "If any keyword argument does not correspond to a formal parameter name, a :" "exc:`TypeError` exception is raised, unless a formal parameter using the " "syntax ``**identifier`` is present; in this case, that formal parameter " "receives a dictionary containing the excess keyword arguments (using the " "keywords as keys and the argument values as corresponding values), or a " "(new) empty dictionary if there were no excess keyword arguments." msgstr "" "キーワード引数のいずれかが仮引数名に対応しない場合、構文 ``**identifier`` を" "使って指定された仮引数がない限り、 :exc:`TypeError` 例外が送出されます; 仮引" "数 ``**identifier`` がある場合、この仮引数は余分なキーワード引数が入った " "(キーワードをキーとし、引数値をキーに対応する値とした) 辞書を受け取ります。余" "分なキーワード引数がない場合には、空の (新たな) 辞書を受け取ります。" #: ../../reference/expressions.rst:1021 msgid "" "If the syntax ``*expression`` appears in the function call, ``expression`` " "must evaluate to an :term:`iterable`. Elements from these iterables are " "treated as if they were additional positional arguments. For the call " "``f(x1, x2, *y, x3, x4)``, if *y* evaluates to a sequence *y1*, ..., *yM*, " "this is equivalent to a call with M+4 positional arguments *x1*, *x2*, " "*y1*, ..., *yM*, *x3*, *x4*." msgstr "" "関数呼び出しに ``*expression`` という構文が現れる場合は、 ``expression`` の評" "価結果は :term:`イテラブル ` でなければなりません。\n" "そのイテラブルの要素は、追加の位置引数であるかのように扱われます。\n" "``f(x1, x2, *y, x3, x4)`` という呼び出しにおいて、 *y* の評価結果がシーケン" "ス *y1*, ..., *yM* だった場合は、この呼び出しは M+4 個の位置引数 *x1*, *x2*, " "*y1*, ..., *yM*, *x3*, *x4* での呼び出しと同じになります。" #: ../../reference/expressions.rst:1028 msgid "" "A consequence of this is that although the ``*expression`` syntax may appear " "*after* explicit keyword arguments, it is processed *before* the keyword " "arguments (and any ``**expression`` arguments -- see below). So::" msgstr "" "この結論としては、 ``*expression`` 構文がキーワード引数の *後ろ* に来ることも" "ありますが、キーワード引数 (と任意の ``**expression`` 引数 -- 下を参照) より" "も *前* にあるものとして処理されます。\n" "従って、このような動作になります::" #: ../../reference/expressions.rst:1044 msgid "" "It is unusual for both keyword arguments and the ``*expression`` syntax to " "be used in the same call, so in practice this confusion does not arise." msgstr "" "キーワード引数と ``*expression`` 構文を同じ呼び出しで一緒に使うことはあまりな" "いので、実際に上記のような混乱が生じることはありません。" #: ../../reference/expressions.rst:1050 msgid "" "If the syntax ``**expression`` appears in the function call, ``expression`` " "must evaluate to a :term:`mapping`, the contents of which are treated as " "additional keyword arguments. If a parameter matching a key has already been " "given a value (by an explicit keyword argument, or from another unpacking), " "a :exc:`TypeError` exception is raised." msgstr "" "関数呼び出しで ``**expression`` 構文が使われた場合、 ``expression`` の評価結" "果は :term:`マッピング ` でなければなりません。その内容は追加のキー" "ワード引数として扱われます。\n" "キーにマッチする引数が (明示的なキーワード引数によって、あるいは他のアンパッ" "クの中で) 既に値を与えられていたなら、 :exc:`TypeError` 例外が送出されます。" #: ../../reference/expressions.rst:1056 msgid "" "When ``**expression`` is used, each key in this mapping must be a string. " "Each value from the mapping is assigned to the first formal parameter " "eligible for keyword assignment whose name is equal to the key. A key need " "not be a Python identifier (e.g. ``\"max-temp °F\"`` is acceptable, although " "it will not match any formal parameter that could be declared). If there is " "no match to a formal parameter the key-value pair is collected by the ``**`` " "parameter, if there is one, or if there is not, a :exc:`TypeError` exception " "is raised." msgstr "" #: ../../reference/expressions.rst:1066 msgid "" "Formal parameters using the syntax ``*identifier`` or ``**identifier`` " "cannot be used as positional argument slots or as keyword argument names." msgstr "" "``*identifier`` や ``**identifier`` 構文を使った仮引数は、位置引数スロットや" "キーワード引数名にすることができません。" #: ../../reference/expressions.rst:1069 msgid "" "Function calls accept any number of ``*`` and ``**`` unpackings, positional " "arguments may follow iterable unpackings (``*``), and keyword arguments may " "follow dictionary unpackings (``**``). Originally proposed by :pep:`448`." msgstr "" "関数呼び出しは任意の数の ``*`` アンパックと ``**`` アンパックを受け取り、位置" "引数はイテラブルアンパック (``*``) の後ろに置け、キーワード引数は辞書アンパッ" "ク (``**``) の後ろに置けるようになりました。\n" "最初に :pep:`448` で提案されました。" #: ../../reference/expressions.rst:1075 msgid "" "A call always returns some value, possibly ``None``, unless it raises an " "exception. How this value is computed depends on the type of the callable " "object." msgstr "" "呼び出しを行うと、例外を送出しない限り、常に何らかの値を返します。 ``None`` " "を返す場合もあります。戻り値がどのように算出されるかは、呼び出し可能オブジェ" "クトの形態によって異なります。" #: ../../reference/expressions.rst:1079 msgid "If it is---" msgstr "各形態では---" #: ../../reference/expressions.rst:1092 msgid "a user-defined function:" msgstr "ユーザ定義関数:" #: ../../reference/expressions.rst:1088 msgid "" "The code block for the function is executed, passing it the argument list. " "The first thing the code block will do is bind the formal parameters to the " "arguments; this is described in section :ref:`function`. When the code " "block executes a :keyword:`return` statement, this specifies the return " "value of the function call." msgstr "" "関数のコードブロックに引数リストが渡され、実行されます。コードブロックは、ま" "ず仮引数を実引数に結合 (bind) します; この動作については :ref:`function` で記" "述しています。コードブロックで :keyword:`return` 文が実行される際に、関数呼び" "出しの戻り値 (return value) が決定されます。" #: ../../reference/expressions.rst:1106 msgid "a built-in function or method:" msgstr "組み込み関数またはメソッド:" #: ../../reference/expressions.rst:1105 msgid "" "The result is up to the interpreter; see :ref:`built-in-funcs` for the " "descriptions of built-in functions and methods." msgstr "" "結果はインタプリタに依存します; 組み込み関数やメソッドの詳細は :ref:`built-" "in-funcs` を参照してください。" #: ../../reference/expressions.rst:1113 msgid "a class object:" msgstr "クラスオブジェクト:" #: ../../reference/expressions.rst:1113 msgid "A new instance of that class is returned." msgstr "そのクラスの新しいインスタンスが返されます。" #: ../../reference/expressions.rst:1123 msgid "a class instance method:" msgstr "クラスインスタンスメソッド:" #: ../../reference/expressions.rst:1121 msgid "" "The corresponding user-defined function is called, with an argument list " "that is one longer than the argument list of the call: the instance becomes " "the first argument." msgstr "" "対応するユーザ定義の関数が呼び出されます。このとき、呼び出し時の引数リストよ" "り一つ長い引数リストで呼び出されます: インスタンスが引数リストの先頭に追加さ" "れます。" #: ../../reference/expressions.rst:1132 msgid "a class instance:" msgstr "クラスインスタンス:" #: ../../reference/expressions.rst:1130 msgid "" "The class must define a :meth:`__call__` method; the effect is then the same " "as if that method was called." msgstr "" "クラスで :meth:`__call__` メソッドが定義されていなければなりません; :meth:" "`__call__` メソッドが呼び出された場合と同じ効果をもたらします。" #: ../../reference/expressions.rst:1138 ../../reference/expressions.rst:1917 msgid "Await expression" msgstr "Await 式" #: ../../reference/expressions.rst:1140 msgid "" "Suspend the execution of :term:`coroutine` on an :term:`awaitable` object. " "Can only be used inside a :term:`coroutine function`." msgstr "" ":term:`awaitable` オブジェクトでの :term:`coroutine` 実行を一時停止します。\n" ":term:`coroutine function` 内でのみ使用できます。" #: ../../reference/expressions.rst:1152 msgid "The power operator" msgstr "べき乗演算 (power operator)" #: ../../reference/expressions.rst:1158 msgid "" "The power operator binds more tightly than unary operators on its left; it " "binds less tightly than unary operators on its right. The syntax is:" msgstr "" "べき乗演算は、左側にある単項演算子よりも強い結合優先順位となります。一方、右" "側にある単項演算子よりは弱い結合優先順位になっています。構文は以下のようにな" "ります:" #: ../../reference/expressions.rst:1164 msgid "" "Thus, in an unparenthesized sequence of power and unary operators, the " "operators are evaluated from right to left (this does not constrain the " "evaluation order for the operands): ``-1**2`` results in ``-1``." msgstr "" "従って、べき乗演算子と単項演算子からなる演算列が丸括弧で囲われていない場合、" "演算子は右から左へと評価されます (この場合は演算子の評価順序を強制しません。" "つまり ``-1**2`` は ``-1`` になります)。" #: ../../reference/expressions.rst:1168 msgid "" "The power operator has the same semantics as the built-in :func:`pow` " "function, when called with two arguments: it yields its left argument raised " "to the power of its right argument. The numeric arguments are first " "converted to a common type, and the result is of that type." msgstr "" "べき乗演算子の意味は、二つの引数で呼び出される組み込み関数 :func:`pow` と同じ" "で、左引数を右引数乗して与えます。数値引数はまず共通の型に変換され、結果はそ" "の型です。" #: ../../reference/expressions.rst:1173 msgid "" "For int operands, the result has the same type as the operands unless the " "second argument is negative; in that case, all arguments are converted to " "float and a float result is delivered. For example, ``10**2`` returns " "``100``, but ``10**-2`` returns ``0.01``." msgstr "" "整数の被演算子では、第二引数が負でない限り、結果は被演算子と同じ型になりま" "す; 第二引数が負の場合、全ての引数は浮動小数点型に変換され、浮動小数点型が返" "されます。例えば ``10**2`` は ``100`` を返しますが、``10**-2`` は ``0.01`` を" "返します。" #: ../../reference/expressions.rst:1178 msgid "" "Raising ``0.0`` to a negative power results in a :exc:`ZeroDivisionError`. " "Raising a negative number to a fractional power results in a :class:" "`complex` number. (In earlier versions it raised a :exc:`ValueError`.)" msgstr "" "``0.0`` を負の数でべき乗すると :exc:`ZeroDivisionError` を送出します。負の数" "を小数でべき乗した結果は複素数 (:class:`complex` number) になります。 (以前の" "バージョンでは :exc:`ValueError` を送出していました)" #: ../../reference/expressions.rst:1182 msgid "" "This operation can be customized using the special :meth:`__pow__` method." msgstr "" #: ../../reference/expressions.rst:1187 msgid "Unary arithmetic and bitwise operations" msgstr "単項算術演算とビット単位演算 (unary arithmetic and bitwise operation)" #: ../../reference/expressions.rst:1193 msgid "All unary arithmetic and bitwise operations have the same priority:" msgstr "全ての単項算術演算とビット単位演算は、同じ優先順位を持っています:" #: ../../reference/expressions.rst:1204 msgid "" "The unary ``-`` (minus) operator yields the negation of its numeric " "argument; the operation can be overridden with the :meth:`__neg__` special " "method." msgstr "" #: ../../reference/expressions.rst:1212 msgid "" "The unary ``+`` (plus) operator yields its numeric argument unchanged; the " "operation can be overridden with the :meth:`__pos__` special method." msgstr "" #: ../../reference/expressions.rst:1219 msgid "" "The unary ``~`` (invert) operator yields the bitwise inversion of its " "integer argument. The bitwise inversion of ``x`` is defined as ``-(x+1)``. " "It only applies to integral numbers or to custom objects that override the :" "meth:`__invert__` special method." msgstr "" "単項演算子 ``~`` (反転) は、整数引数をビット単位反転 (bitwise invert) したも" "のを与えます。``x`` のビット単位反転は、``-(x+1)`` として定義されています。こ" "の演算子は整数や :meth:`__invert__` 特殊メソッドをオーバーライドするカスタム" "オブジェクトにのみ適用されます。" #: ../../reference/expressions.rst:1228 msgid "" "In all three cases, if the argument does not have the proper type, a :exc:" "`TypeError` exception is raised." msgstr "" "上記の三つはいずれも、引数が正しい型でない場合には :exc:`TypeError` 例外が送" "出されます。" #: ../../reference/expressions.rst:1235 msgid "Binary arithmetic operations" msgstr "二項算術演算 (binary arithmetic operation)" #: ../../reference/expressions.rst:1239 msgid "" "The binary arithmetic operations have the conventional priority levels. " "Note that some of these operations also apply to certain non-numeric types. " "Apart from the power operator, there are only two levels, one for " "multiplicative operators and one for additive operators:" msgstr "" "二項算術演算は、慣習的な優先順位を踏襲しています。演算子のいずれかは、特定の" "非数値型にも適用されるので注意してください。べき乗 (power) 演算子を除き、演算" "子には二つのレベル、すなわち乗算的 (multiplicatie) 演算子と加算的 (additie) " "演算子しかありません:" #: ../../reference/expressions.rst:1254 msgid "" "The ``*`` (multiplication) operator yields the product of its arguments. " "The arguments must either both be numbers, or one argument must be an " "integer and the other must be a sequence. In the former case, the numbers " "are converted to a common type and then multiplied together. In the latter " "case, sequence repetition is performed; a negative repetition factor yields " "an empty sequence." msgstr "" "``*`` (乗算: multiplication) 演算子は、引数同士の積を与えます。引数は、両方と" "も数値であるか、片方が整数で他方がシーケンスかのどちらかでなければなりませ" "ん。前者の場合、数値は共通の型に変換された後乗算されます。後者の場合、シーケ" "ンスの繰り返し操作が行われます。繰り返し数を負にすると、空のシーケンスを与え" "ます。" #: ../../reference/expressions.rst:1260 msgid "" "This operation can be customized using the special :meth:`__mul__` and :meth:" "`__rmul__` methods." msgstr "" #: ../../reference/expressions.rst:1267 msgid "" "The ``@`` (at) operator is intended to be used for matrix multiplication. " "No builtin Python types implement this operator." msgstr "" "``@`` (at) 演算子は行列の乗算に対し使用されます。\n" "Python の組み込み型はこの演算子を実装していません。" #: ../../reference/expressions.rst:1278 msgid "" "The ``/`` (division) and ``//`` (floor division) operators yield the " "quotient of their arguments. The numeric arguments are first converted to a " "common type. Division of integers yields a float, while floor division of " "integers results in an integer; the result is that of mathematical division " "with the 'floor' function applied to the result. Division by zero raises " "the :exc:`ZeroDivisionError` exception." msgstr "" "``/`` (除算: division) および ``//`` (切り捨て除算: floor division) は、引数" "同士の商を与えます。数値引数はまず共通の型に変換されます。整数の除算結果は浮" "動小数点になりますが、整数の切り捨て除算結果は整数になります; この場合、結果" "は数学的な除算に 'floor' 関数 を適用したものになります。ゼロによる除算を行う" "と :exc:`ZeroDivisionError` 例外を送出します。" #: ../../reference/expressions.rst:1285 msgid "" "This operation can be customized using the special :meth:`__truediv__` and :" "meth:`__floordiv__` methods." msgstr "" #: ../../reference/expressions.rst:1292 msgid "" "The ``%`` (modulo) operator yields the remainder from the division of the " "first argument by the second. The numeric arguments are first converted to " "a common type. A zero right argument raises the :exc:`ZeroDivisionError` " "exception. The arguments may be floating point numbers, e.g., ``3.14%0.7`` " "equals ``0.34`` (since ``3.14`` equals ``4*0.7 + 0.34``.) The modulo " "operator always yields a result with the same sign as its second operand (or " "zero); the absolute value of the result is strictly smaller than the " "absolute value of the second operand [#]_." msgstr "" "``%`` (剰余: modulo) 演算は、第一引数を第二引数で除算したときの剰余になりま" "す。数値引数はまず共通の型に変換されます。右引数値がゼロの場合には :exc:" "`ZeroDivisionError` 例外が送出されます。引数値は浮動小数点でもよく。例えば " "``3.14%0.7`` は ``0.34`` になります (``3.14`` は ``4*0.7 + 0.34`` だからで" "す)。剰余演算子は常に第二引数と同じ符号 (またはゼロ) の結果になります; 剰余演" "算の結果の絶対値は、常に第二引数の絶対値よりも小さくなります。 [#]_" #: ../../reference/expressions.rst:1301 msgid "" "The floor division and modulo operators are connected by the following " "identity: ``x == (x//y)*y + (x%y)``. Floor division and modulo are also " "connected with the built-in function :func:`divmod`: ``divmod(x, y) == (x//" "y, x%y)``. [#]_." msgstr "" "切り捨て除算演算と剰余演算は、恒等式: ``x == (x//y)*y + (x%y)`` の関係にあり" "ます。切り捨て除算や剰余はまた、組み込み関数 :func:`divmod`: ``divmod(x, y) " "== (x//y, x%y)`` とも関係しています。 [#]_ 。" #: ../../reference/expressions.rst:1306 msgid "" "In addition to performing the modulo operation on numbers, the ``%`` " "operator is also overloaded by string objects to perform old-style string " "formatting (also known as interpolation). The syntax for string formatting " "is described in the Python Library Reference, section :ref:`old-string-" "formatting`." msgstr "" "``%`` 演算子は、数値に対する剰余演算を行うのに加えて、文字列 (string) オブ" "ジェクトにオーバーロードされ、旧式の文字列の書式化 (いわゆる補間) を行いま" "す。文字列の書式化の構文は Python ライブラリリファレンス :ref:`old-string-" "formatting` 節を参照してください。" #: ../../reference/expressions.rst:1311 msgid "" "The *modulo* operation can be customized using the special :meth:`__mod__` " "method." msgstr "" #: ../../reference/expressions.rst:1313 msgid "" "The floor division operator, the modulo operator, and the :func:`divmod` " "function are not defined for complex numbers. Instead, convert to a " "floating point number using the :func:`abs` function if appropriate." msgstr "" "切り捨て除算演算子、剰余演算子、および :func:`divmod` 関数は、複素数に対して" "は定義されていません。目的に合うならば、代わりに :func:`abs` を使って浮動小数" "点に変換してください。" #: ../../reference/expressions.rst:1322 msgid "" "The ``+`` (addition) operator yields the sum of its arguments. The " "arguments must either both be numbers or both be sequences of the same " "type. In the former case, the numbers are converted to a common type and " "then added together. In the latter case, the sequences are concatenated." msgstr "" "``+`` (加算) 演算は、引数同士の和を与えます。引数は双方とも数値型か、双方とも" "同じ型のシーケンスでなければなりません。前者の場合、数値は共通の型に変換さ" "れ、加算されます。後者の場合、シーケンスは結合 (concatenate) されます。" #: ../../reference/expressions.rst:1327 msgid "" "This operation can be customized using the special :meth:`__add__` and :meth:" "`__radd__` methods." msgstr "" #: ../../reference/expressions.rst:1335 msgid "" "The ``-`` (subtraction) operator yields the difference of its arguments. " "The numeric arguments are first converted to a common type." msgstr "" "``-`` (減算) 演算は、引数間で減算を行った値を返します。数値引数はまず共通の型" "に変換されます。" #: ../../reference/expressions.rst:1338 msgid "" "This operation can be customized using the special :meth:`__sub__` method." msgstr "" #: ../../reference/expressions.rst:1344 msgid "Shifting operations" msgstr "シフト演算 (shifting operation)" #: ../../reference/expressions.rst:1351 msgid "" "The shifting operations have lower priority than the arithmetic operations:" msgstr "シフト演算は、算術演算よりも低い優先順位を持っています:" #: ../../reference/expressions.rst:1356 msgid "" "These operators accept integers as arguments. They shift the first argument " "to the left or right by the number of bits given by the second argument." msgstr "" "これらは整数を引数にとります。引数は共通の型に変換されます。シフト演算は第一" "引数を、第二引数で与えられたビット数だけ、左または右にビットシフトします。" #: ../../reference/expressions.rst:1359 msgid "" "This operation can be customized using the special :meth:`__lshift__` and :" "meth:`__rshift__` methods." msgstr "" #: ../../reference/expressions.rst:1364 msgid "" "A right shift by *n* bits is defined as floor division by ``pow(2,n)``. A " "left shift by *n* bits is defined as multiplication with ``pow(2,n)``." msgstr "" "*n* ビットの右シフトは ``pow(2,n)`` による除算として定義されます。*n* ビット" "の左シフトは ``pow(2,n)`` による乗算として定義されます。" #: ../../reference/expressions.rst:1371 msgid "Binary bitwise operations" msgstr "ビット単位演算の二項演算 (binary bitwise operation)" #: ../../reference/expressions.rst:1375 msgid "Each of the three bitwise operations has a different priority level:" msgstr "" "以下の三つのビット単位演算には、それぞれ異なる優先順位レベルがあります:" #: ../../reference/expressions.rst:1386 msgid "" "The ``&`` operator yields the bitwise AND of its arguments, which must be " "integers or one of them must be a custom object overriding :meth:`__and__` " "or :meth:`__rand__` special methods." msgstr "" #: ../../reference/expressions.rst:1395 msgid "" "The ``^`` operator yields the bitwise XOR (exclusive OR) of its arguments, " "which must be integers or one of them must be a custom object overriding :" "meth:`__xor__` or :meth:`__rxor__` special methods." msgstr "" #: ../../reference/expressions.rst:1404 msgid "" "The ``|`` operator yields the bitwise (inclusive) OR of its arguments, which " "must be integers or one of them must be a custom object overriding :meth:" "`__or__` or :meth:`__ror__` special methods." msgstr "" #: ../../reference/expressions.rst:1412 msgid "Comparisons" msgstr "比較" #: ../../reference/expressions.rst:1424 msgid "" "Unlike C, all comparison operations in Python have the same priority, which " "is lower than that of any arithmetic, shifting or bitwise operation. Also " "unlike C, expressions like ``a < b < c`` have the interpretation that is " "conventional in mathematics:" msgstr "" "C 言語と違って、Python における比較演算子は同じ優先順位をもっており、全ての算" "術演算子、シフト演算子、ビット単位演算子よりも低くなっています。また ``a < b " "< c`` が数学で伝統的に用いられているのと同じ解釈になる点も C 言語と違います:" #: ../../reference/expressions.rst:1434 msgid "" "Comparisons yield boolean values: ``True`` or ``False``. Custom :dfn:`rich " "comparison methods` may return non-boolean values. In this case Python will " "call :func:`bool` on such value in boolean contexts." msgstr "" #: ../../reference/expressions.rst:1440 msgid "" "Comparisons can be chained arbitrarily, e.g., ``x < y <= z`` is equivalent " "to ``x < y and y <= z``, except that ``y`` is evaluated only once (but in " "both cases ``z`` is not evaluated at all when ``x < y`` is found to be " "false)." msgstr "" "比較はいくらでも連鎖することができます。例えば ``x < y <= z`` は ``x < y and " "y <= z`` と等価になります。ただしこの場合、前者では ``y`` はただ一度だけ評価" "される点が異なります (どちらの場合でも、 ``x < y`` が偽になると ``z`` の値は" "まったく評価されません)。" #: ../../reference/expressions.rst:1444 msgid "" "Formally, if *a*, *b*, *c*, ..., *y*, *z* are expressions and *op1*, " "*op2*, ..., *opN* are comparison operators, then ``a op1 b op2 c ... y opN " "z`` is equivalent to ``a op1 b and b op2 c and ... y opN z``, except that " "each expression is evaluated at most once." msgstr "" "形式的には、 *a*, *b*, *c*, ..., *y*, *z* が式で *op1*, *op2*, ..., *opN* が" "比較演算子である場合、 ``a op1 b op2 c ... y opN z`` は ``a op1 b and b op2 " "c and ... y opN z`` と等価になります。ただし、前者では各式は多くても一度しか" "評価されません。" #: ../../reference/expressions.rst:1449 msgid "" "Note that ``a op1 b op2 c`` doesn't imply any kind of comparison between *a* " "and *c*, so that, e.g., ``x < y > z`` is perfectly legal (though perhaps not " "pretty)." msgstr "" "``a op1 b op2 c`` と書いた場合、 *a* から *c* までの範囲にあるかどうかのテス" "トを指すのではないことに注意してください。例えば ``x < y > z`` は (きれいな書" "き方ではありませんが) 完全に正しい文法です。" #: ../../reference/expressions.rst:1454 msgid "Value comparisons" msgstr "値の比較" #: ../../reference/expressions.rst:1456 msgid "" "The operators ``<``, ``>``, ``==``, ``>=``, ``<=``, and ``!=`` compare the " "values of two objects. The objects do not need to have the same type." msgstr "" "演算子 ``<``, ``>``, ``==``, ``>=``, ``<=``, および ``!=`` は2つのオブジェク" "トの値を比較します。\n" "オブジェクトが同じ型を持つ必要はりません。" #: ../../reference/expressions.rst:1459 msgid "" "Chapter :ref:`objects` states that objects have a value (in addition to type " "and identity). The value of an object is a rather abstract notion in " "Python: For example, there is no canonical access method for an object's " "value. Also, there is no requirement that the value of an object should be " "constructed in a particular way, e.g. comprised of all its data attributes. " "Comparison operators implement a particular notion of what the value of an " "object is. One can think of them as defining the value of an object " "indirectly, by means of their comparison implementation." msgstr "" ":ref:`objects` の章では、オブジェクトは (型や id に加えて) 値を持つことを述べ" "ています。\n" "オブジェクトの値は Python ではやや抽象的な概念です: 例えば、オブジェクトの値" "にアクセスする正統な方法はありません。\n" "また、その全てのデータ属性から構成されるなどの特定の方法で、オブジェクトの値" "を構築する必要性もありません。\n" "比較演算子は、オブジェクトの値とは何かについての特定の概念を実装していま" "す。\n" "この比較の実装によって、間接的にオブジェクトの値を定義していると考えることも" "できます。" #: ../../reference/expressions.rst:1468 msgid "" "Because all types are (direct or indirect) subtypes of :class:`object`, they " "inherit the default comparison behavior from :class:`object`. Types can " "customize their comparison behavior by implementing :dfn:`rich comparison " "methods` like :meth:`__lt__`, described in :ref:`customization`." msgstr "" "全ての型は (直接的あるいは間接的に) :class:`object` のサブクラスとなっている" "ので、デフォルトの比較の振る舞いを :class:`object` から継承しています。\n" ":ref:`customization` で解説されているように、型を使って :dfn:`rich " "comparison methods` である :meth:`__lt__` などのメソッドを実装することで、 比" "較の振る舞いをカスタマイズできます。" #: ../../reference/expressions.rst:1474 msgid "" "The default behavior for equality comparison (``==`` and ``!=``) is based on " "the identity of the objects. Hence, equality comparison of instances with " "the same identity results in equality, and equality comparison of instances " "with different identities results in inequality. A motivation for this " "default behavior is the desire that all objects should be reflexive (i.e. " "``x is y`` implies ``x == y``)." msgstr "" "等価比較 (``==`` および ``!=``) のデフォルトの振る舞いは、オブジェクトの同一" "性に基づいています。\n" "従って、同一のインスタンスの等価比較の結果は等しいとなり、同一でないインスタ" "ンスの等価比較の結果は等しくないとなります。\n" "デフォルトの振る舞いをこのようにしたのは、全てのオブジェクトを反射的 " "(reflexive つまり ``x is y`` ならば ``x == y``) なものにしたかったからです。" #: ../../reference/expressions.rst:1481 msgid "" "A default order comparison (``<``, ``>``, ``<=``, and ``>=``) is not " "provided; an attempt raises :exc:`TypeError`. A motivation for this default " "behavior is the lack of a similar invariant as for equality." msgstr "" "デフォルトの順序比較 (``<``, ``>``, ``<=``, ``>=``) は提供されません; 比較し" "ようとすると :exc:`TypeError` が送出されます。\n" "この振る舞いをデフォルトの振る舞いにした動機は、等価性と同じような不変性が欠" "けているからです。" #: ../../reference/expressions.rst:1485 msgid "" "The behavior of the default equality comparison, that instances with " "different identities are always unequal, may be in contrast to what types " "will need that have a sensible definition of object value and value-based " "equality. Such types will need to customize their comparison behavior, and " "in fact, a number of built-in types have done that." msgstr "" "同一でないインスタンスは常に等価でないとする等価比較のデフォルトの振る舞い" "は、型が必要とするオブジェクトの値や値に基づいた等価性の実用的な定義とは対照" "的に思えるでしょう。\n" "そのような型では比較の振る舞いをカスタマイズする必要が出てきて、実際にたくさ" "んの組み込み型でそれが行われています。" #: ../../reference/expressions.rst:1491 msgid "" "The following list describes the comparison behavior of the most important " "built-in types." msgstr "次のリストでは、最重要の組み込み型の比較の振る舞いを解説しています。" #: ../../reference/expressions.rst:1494 msgid "" "Numbers of built-in numeric types (:ref:`typesnumeric`) and of the standard " "library types :class:`fractions.Fraction` and :class:`decimal.Decimal` can " "be compared within and across their types, with the restriction that complex " "numbers do not support order comparison. Within the limits of the types " "involved, they compare mathematically (algorithmically) correct without loss " "of precision." msgstr "" "いくつかの組み込みの数値型 (:ref:`typesnumeric`) と標準ライブラリの型 :class:" "`fractions.Fraction` および :class:`decimal.Decimal` は、これらの型の範囲で異" "なる型とも比較できますが、複素数では順序比較がサポートされていないという制限" "があります。\n" "関わる型の制限の範囲内では、精度のロス無しに数学的に (アルゴリズム的に) 正し" "い比較が行われます。" #: ../../reference/expressions.rst:1501 msgid "" "The not-a-number values ``float('NaN')`` and ``decimal.Decimal('NaN')`` are " "special. Any ordered comparison of a number to a not-a-number value is " "false. A counter-intuitive implication is that not-a-number values are not " "equal to themselves. For example, if ``x = float('NaN')``, ``3 < x``, ``x < " "3`` and ``x == x`` are all false, while ``x != x`` is true. This behavior " "is compliant with IEEE 754." msgstr "" "非数値である ``float('NaN')`` と ``decimal.Decimal('NaN')`` は特別です。\n" "数と非数値との任意の順序比較は偽です。\n" "直観に反する帰結として、非数値は自分自身と等価ではないことになります。\n" "例えば ``x = float('NaN')`` ならば、 ``3 < x``, ``x < 3``, ``x == x`` は全て" "偽で、``x != x`` は真です。\n" "この振る舞いは IEEE 754 に従ったものです。" #: ../../reference/expressions.rst:1508 msgid "" "``None`` and ``NotImplemented`` are singletons. :PEP:`8` advises that " "comparisons for singletons should always be done with ``is`` or ``is not``, " "never the equality operators." msgstr "" #: ../../reference/expressions.rst:1512 msgid "" "Binary sequences (instances of :class:`bytes` or :class:`bytearray`) can be " "compared within and across their types. They compare lexicographically " "using the numeric values of their elements." msgstr "" "バイナリシーケンス (:class:`bytes` または :class:`bytearray` のインスタンス) " "は、これらの型の範囲で異なる型とも比較できます。\n" "比較は要素の数としての値を使った辞書式順序で行われます。" #: ../../reference/expressions.rst:1516 msgid "" "Strings (instances of :class:`str`) compare lexicographically using the " "numerical Unicode code points (the result of the built-in function :func:" "`ord`) of their characters. [#]_" msgstr "" "文字列 (:class:`str` のインスタンス) の比較は、文字の Unicode のコードポイン" "トの数としての値 (組み込み関数 :func:`ord` の返り値) を使った辞書式順序で行わ" "れます。 [#]_" #: ../../reference/expressions.rst:1520 msgid "Strings and binary sequences cannot be directly compared." msgstr "文字列とバイナリシーケンスは直接には比較できません。" #: ../../reference/expressions.rst:1522 msgid "" "Sequences (instances of :class:`tuple`, :class:`list`, or :class:`range`) " "can be compared only within each of their types, with the restriction that " "ranges do not support order comparison. Equality comparison across these " "types results in inequality, and ordering comparison across these types " "raises :exc:`TypeError`." msgstr "" "シーケンス (:class:`tuple`, :class:`list`, or :class:`range` のインスタンス) " "の比較は、同じ型どうしでしか行えず、 range は順序比較をサポートしていませ" "ん。\n" "異なる型どうしの等価比較の結果は等価でないとなり、異なる型どうしの順序比較" "は :exc:`TypeError` を送出します。" #: ../../reference/expressions.rst:1528 msgid "" "Sequences compare lexicographically using comparison of corresponding " "elements. The built-in containers typically assume identical objects are " "equal to themselves. That lets them bypass equality tests for identical " "objects to improve performance and to maintain their internal invariants." msgstr "" #: ../../reference/expressions.rst:1533 msgid "" "Lexicographical comparison between built-in collections works as follows:" msgstr "組み込みのコレクションどうしの辞書式比較は次のように動作します:" #: ../../reference/expressions.rst:1535 msgid "" "For two collections to compare equal, they must be of the same type, have " "the same length, and each pair of corresponding elements must compare equal " "(for example, ``[1,2] == (1,2)`` is false because the type is not the same)." msgstr "" "比較の結果が等価となる2つのコレクションは、同じ型、同じ長さ、対応する要素どう" "しの比較の結果が等価でなければなりません (例えば、 ``[1,2] == (1,2)`` は型が" "同じでないので偽です)。" #: ../../reference/expressions.rst:1540 msgid "" "Collections that support order comparison are ordered the same as their " "first unequal elements (for example, ``[1,2,x] <= [1,2,y]`` has the same " "value as ``x <= y``). If a corresponding element does not exist, the " "shorter collection is ordered first (for example, ``[1,2] < [1,2,3]`` is " "true)." msgstr "" "順序比較をサポートしているコレクションの順序は、最初の等価でない要素の順序と" "同じになります (例えば、 ``[1,2,x] <= [1,2,y]`` は ``x <= y`` と同じ値になり" "ます)。\n" "対応する要素が存在しない場合、短い方のコレクションの方が先の順序となります " "(例えば、 ``[1,2] < [1,2,3]`` は真です)。" #: ../../reference/expressions.rst:1546 msgid "" "Mappings (instances of :class:`dict`) compare equal if and only if they have " "equal ``(key, value)`` pairs. Equality comparison of the keys and values " "enforces reflexivity." msgstr "" "マッピング (:class:`dict` のインスタンス) の比較の結果が等価となるのは、同じ " "``(key, value)`` を持っているときかつそのときに限ります。\n" "キーと値の等価比較では反射性が強制されます。" #: ../../reference/expressions.rst:1550 msgid "" "Order comparisons (``<``, ``>``, ``<=``, and ``>=``) raise :exc:`TypeError`." msgstr "" "順序比較 (``<``, ``>``, ``<=``, ``>=``) は :exc:`TypeError` を送出します。" #: ../../reference/expressions.rst:1552 msgid "" "Sets (instances of :class:`set` or :class:`frozenset`) can be compared " "within and across their types." msgstr "" "集合 (:class:`set` または :class:`frozenset` のインスタンス) の比較は、これら" "の型の範囲で異なる型とも行えます。" #: ../../reference/expressions.rst:1555 msgid "" "They define order comparison operators to mean subset and superset tests. " "Those relations do not define total orderings (for example, the two sets " "``{1,2}`` and ``{2,3}`` are not equal, nor subsets of one another, nor " "supersets of one another). Accordingly, sets are not appropriate arguments " "for functions which depend on total ordering (for example, :func:`min`, :" "func:`max`, and :func:`sorted` produce undefined results given a list of " "sets as inputs)." msgstr "" "集合には、部分集合あるいは上位集合かどうかを基準とする順序比較が定義されてい" "ます。\n" "この関係は全順序を定義しません (例えば、 ``{1,2}`` と ``{2,3}`` という2つの集" "合は片方がもう一方の部分集合でもなく上位集合でもありません)。\n" "従って、集合は全順序性に依存する関数の引数として適切ではありません (例え" "ば、 :func:`min`, :func:`max`, :func:`sorted` は集合のリストを入力として与え" "ると未定義な結果となります)。" #: ../../reference/expressions.rst:1563 msgid "Comparison of sets enforces reflexivity of its elements." msgstr "集合の比較では、その要素の反射性が強制されます。" #: ../../reference/expressions.rst:1565 msgid "" "Most other built-in types have no comparison methods implemented, so they " "inherit the default comparison behavior." msgstr "" "他の組み込み型のほとんどは比較メソッドが実装されておらず、デフォルトの比較の" "振る舞いを継承します。" #: ../../reference/expressions.rst:1568 msgid "" "User-defined classes that customize their comparison behavior should follow " "some consistency rules, if possible:" msgstr "" "比較の振る舞いをカスタマイズしたユーザ定義クラスは、可能なら次の一貫性の規則" "に従う必要があります:" #: ../../reference/expressions.rst:1571 msgid "" "Equality comparison should be reflexive. In other words, identical objects " "should compare equal:" msgstr "" "等価比較は反射的でなければなりません。\n" "つまり、同一のオブジェクトは等しくなければなりません:" #: ../../reference/expressions.rst:1574 msgid "``x is y`` implies ``x == y``" msgstr "``x is y`` ならば ``x == y``" #: ../../reference/expressions.rst:1576 msgid "" "Comparison should be symmetric. In other words, the following expressions " "should have the same result:" msgstr "" "比較は対称的でなければなりません。\n" "つまり、以下の式の結果は同じでなければなりません:" #: ../../reference/expressions.rst:1579 msgid "``x == y`` and ``y == x``" msgstr "``x == y`` と ``y == x``" #: ../../reference/expressions.rst:1581 msgid "``x != y`` and ``y != x``" msgstr "``x != y`` と ``y != x``" #: ../../reference/expressions.rst:1583 msgid "``x < y`` and ``y > x``" msgstr "``x < y`` と ``y > x``" #: ../../reference/expressions.rst:1585 msgid "``x <= y`` and ``y >= x``" msgstr "``x <= y`` と ``y >= x``" #: ../../reference/expressions.rst:1587 msgid "" "Comparison should be transitive. The following (non-exhaustive) examples " "illustrate that:" msgstr "" "比較は推移的でなければなりません。\n" "以下の (包括的でない) 例がその説明です:" #: ../../reference/expressions.rst:1590 msgid "``x > y and y > z`` implies ``x > z``" msgstr "``x > y and y > z`` ならば ``x > z``" #: ../../reference/expressions.rst:1592 msgid "``x < y and y <= z`` implies ``x < z``" msgstr "``x < y and y <= z`` ならば ``x < z``" #: ../../reference/expressions.rst:1594 msgid "" "Inverse comparison should result in the boolean negation. In other words, " "the following expressions should have the same result:" msgstr "" "比較の逆は真偽値の否定でなければなりません。\n" "つまり、以下の式の結果は同じでなければなりません:" #: ../../reference/expressions.rst:1597 msgid "``x == y`` and ``not x != y``" msgstr "``x == y`` と ``not x != y``" #: ../../reference/expressions.rst:1599 msgid "``x < y`` and ``not x >= y`` (for total ordering)" msgstr "``x < y`` と ``not x >= y`` (全順序の場合)" #: ../../reference/expressions.rst:1601 msgid "``x > y`` and ``not x <= y`` (for total ordering)" msgstr "``x > y`` と ``not x <= y`` (全順序の場合)" #: ../../reference/expressions.rst:1603 msgid "" "The last two expressions apply to totally ordered collections (e.g. to " "sequences, but not to sets or mappings). See also the :func:`~functools." "total_ordering` decorator." msgstr "" "最後の2式は全順序コレクションに当てはまります (たとえばシーケンスには当てはま" "りますが、集合やマッピングには当てはまりません)。\n" ":func:`~functools.total_ordering` デコレータも参照してください。" #: ../../reference/expressions.rst:1607 msgid "" "The :func:`hash` result should be consistent with equality. Objects that are " "equal should either have the same hash value, or be marked as unhashable." msgstr "" ":func:`hash` の結果は等価性と一貫している必要があります。\n" "等価なオブジェクトどうしは同じハッシュ値を持つか、ハッシュ値が計算できないも" "のとされる必要があります。" #: ../../reference/expressions.rst:1611 msgid "" "Python does not enforce these consistency rules. In fact, the not-a-number " "values are an example for not following these rules." msgstr "" "Python はこの一貫性規則を強制しません。\n" "事実、非数値がこの規則に従わない例となります。" #: ../../reference/expressions.rst:1620 msgid "Membership test operations" msgstr "所属検査演算" #: ../../reference/expressions.rst:1622 msgid "" "The operators :keyword:`in` and :keyword:`not in` test for membership. ``x " "in s`` evaluates to ``True`` if *x* is a member of *s*, and ``False`` " "otherwise. ``x not in s`` returns the negation of ``x in s``. All built-in " "sequences and set types support this as well as dictionary, for which :" "keyword:`!in` tests whether the dictionary has a given key. For container " "types such as list, tuple, set, frozenset, dict, or collections.deque, the " "expression ``x in y`` is equivalent to ``any(x is e or x == e for e in y)``." msgstr "" "演算子 :keyword:`in` および :keyword:`not in` は所属関係を調べます。\n" "``x in s`` の評価は、 *x* が *s* の要素であれば ``True`` となり、そうでなけれ" "ば ``False`` となります。\n" "``x not in s`` は ``x in s`` の否定を返します。\n" "すべての組み込みのシーケンス型と集合型に加えて、辞書も :keyword:`!in` を辞書" "が与えられたキーを持っているかを調べる演算子としてサポートしています。\n" "リスト、タプル、集合、凍結集合、辞書、 collections.deque のようなコンテナ型に" "おいて、式 ``x in y`` は ``any(x is e or x == e for e in y)`` と等価です。" #: ../../reference/expressions.rst:1630 msgid "" "For the string and bytes types, ``x in y`` is ``True`` if and only if *x* is " "a substring of *y*. An equivalent test is ``y.find(x) != -1``. Empty " "strings are always considered to be a substring of any other string, so " "``\"\" in \"abc\"`` will return ``True``." msgstr "" "文字列やバイト列型については、 ``x in y`` は *x* が *y* の部分文字列であると" "き、かつそのときに限り ``True`` になります。これは ``y.find(x) != -1`` と等価" "です。空文字列は、他の任意の文字列の部分文字列とみなされます。従って ``\"\" " "in \"abc\"`` は ``True`` を返すことになります。" #: ../../reference/expressions.rst:1635 msgid "" "For user-defined classes which define the :meth:`__contains__` method, ``x " "in y`` returns ``True`` if ``y.__contains__(x)`` returns a true value, and " "``False`` otherwise." msgstr "" ":meth:`__contains__` メソッドを実装したユーザ定義クラスでは、 ``y." "__contains__(x)`` の返り値が真となる場合に ``x in y`` の返り値は ``True`` と" "なり、そうでない場合は ``False`` となります。" #: ../../reference/expressions.rst:1639 msgid "" "For user-defined classes which do not define :meth:`__contains__` but do " "define :meth:`__iter__`, ``x in y`` is ``True`` if some value ``z``, for " "which the expression ``x is z or x == z`` is true, is produced while " "iterating over ``y``. If an exception is raised during the iteration, it is " "as if :keyword:`in` raised that exception." msgstr "" ":meth:`__contains__` を定義していないが :meth:`__iter__` は定義しているユーザ" "定義クラスでは、 ``x in y`` は ``x is z or x == z`` が真となるようなある値 " "``z`` が ``y`` 内にわたる反復で生成された場合、 ``True`` となります。もし、反" "復の間に例外が発生すれば、 :keyword:`in` が例外を発生させたようにみえます。" #: ../../reference/expressions.rst:1645 msgid "" "Lastly, the old-style iteration protocol is tried: if a class defines :meth:" "`__getitem__`, ``x in y`` is ``True`` if and only if there is a non-negative " "integer index *i* such that ``x is y[i] or x == y[i]``, and no lower integer " "index raises the :exc:`IndexError` exception. (If any other exception is " "raised, it is as if :keyword:`in` raised that exception)." msgstr "" "最終的には、旧式の反復プロトコルの実行を試みます、もし :meth:`__getitem__` を" "定義しているようなユーザ定義クラスでは、 ``x in y`` は ``x is y[i] or x == " "y[i]`` となるような非負の整数インデクス *i* が存在し、それより小さい整数イン" "デクスが :exc:`IndexError` を送出しないとき、かつそのときにかぎり ``True`` と" "なります。 (別の何らかの例外が送出された場合、例外は :keyword:`in` から送出さ" "れたかのようになります)。" #: ../../reference/expressions.rst:1657 msgid "" "The operator :keyword:`not in` is defined to have the inverse truth value " "of :keyword:`in`." msgstr "" "演算子 :keyword:`not in` は :keyword:`in` の真理値を反転した値として定義され" "ています。" #: ../../reference/expressions.rst:1670 msgid "Identity comparisons" msgstr "同一性の比較" #: ../../reference/expressions.rst:1672 msgid "" "The operators :keyword:`is` and :keyword:`is not` test for an object's " "identity: ``x is y`` is true if and only if *x* and *y* are the same " "object. An Object's identity is determined using the :meth:`id` function. " "``x is not y`` yields the inverse truth value. [#]_" msgstr "" "演算子 :keyword:`is` および :keyword:`is not` は、オブジェクトの同一性に対す" "るテストを行います: ``x is y`` は、 *x* と *y* が同じオブジェクトを指すとき、" "かつそのときに限り真になります。\n" "オブジェクトの同一性は :meth:`id` 関数を使って判定されます。\n" "``x is not y`` は :keyword:`is` の真値を反転したものになります。 [#]_" #: ../../reference/expressions.rst:1684 msgid "Boolean operations" msgstr "ブール演算 (boolean operation)" #: ../../reference/expressions.rst:1695 msgid "" "In the context of Boolean operations, and also when expressions are used by " "control flow statements, the following values are interpreted as false: " "``False``, ``None``, numeric zero of all types, and empty strings and " "containers (including strings, tuples, lists, dictionaries, sets and " "frozensets). All other values are interpreted as true. User-defined " "objects can customize their truth value by providing a :meth:`__bool__` " "method." msgstr "" "ブール演算のコンテキストや、式が制御フローの文で使われる際には、次の値は偽だ" "と解釈されます: ``False`` 、 ``None`` 、すべての型における数値の 0、空の文字" "列、空のコンテナ (文字列、タプル、リスト、辞書、集合、凍結集合など)。\n" "それ以外の値は真だと解釈されます。\n" "ユーザ定義のオブジェクトは、 :meth:`__bool__` メソッドを与えることで、真偽値" "をカスタマイズできます。" #: ../../reference/expressions.rst:1704 msgid "" "The operator :keyword:`not` yields ``True`` if its argument is false, " "``False`` otherwise." msgstr "" "演算子 :keyword:`not` は、引数が偽である場合には ``True`` を、それ以外の場合" "には ``False`` になります。" #: ../../reference/expressions.rst:1709 msgid "" "The expression ``x and y`` first evaluates *x*; if *x* is false, its value " "is returned; otherwise, *y* is evaluated and the resulting value is returned." msgstr "" "式 ``x and y`` は、まず *x* を評価します; *x* が偽なら *x* の値を返します; そ" "れ以外の場合には、 *y* を評価した結果値を返します。" #: ../../reference/expressions.rst:1714 msgid "" "The expression ``x or y`` first evaluates *x*; if *x* is true, its value is " "returned; otherwise, *y* is evaluated and the resulting value is returned." msgstr "" "式 ``x or y`` は、まず *x* を評価します; *x* が真なら *x* の値を返します; そ" "れ以外の場合には、 *y* を評価した結果値を返します。" #: ../../reference/expressions.rst:1717 msgid "" "Note that neither :keyword:`and` nor :keyword:`or` restrict the value and " "type they return to ``False`` and ``True``, but rather return the last " "evaluated argument. This is sometimes useful, e.g., if ``s`` is a string " "that should be replaced by a default value if it is empty, the expression " "``s or 'foo'`` yields the desired value. Because :keyword:`not` has to " "create a new value, it returns a boolean value regardless of the type of its " "argument (for example, ``not 'foo'`` produces ``False`` rather than ``''``.)" msgstr "" "なお、 :keyword:`and` も :keyword:`or` も、返す値を ``True`` や ``False`` に" "制限せず、最後に評価した引数を返します。\n" "この仕様が便利なときもあります。例えば ``s`` が文字列で、空文字列ならデフォル" "トの値に置き換えたいとき、式 ``s or 'foo'`` は望んだ値を与えます。\n" ":keyword:`not` は必ず新しい値を作成するので、引数の型に関係なくブール値を返し" "ます (例えば、 ``not 'foo'`` は ``''`` ではなく ``False`` になります)。" #: ../../reference/expressions.rst:1733 msgid "Assignment expressions" msgstr "代入式" #: ../../reference/expressions.rst:1738 msgid "" "An assignment expression (sometimes also called a \"named expression\" or " "\"walrus\") assigns an :token:`~python-grammar:expression` to an :token:" "`~python-grammar:identifier`, while also returning the value of the :token:" "`~python-grammar:expression`." msgstr "" #: ../../reference/expressions.rst:1743 msgid "One common use case is when handling matched regular expressions:" msgstr "" #: ../../reference/expressions.rst:1750 msgid "Or, when processing a file stream in chunks:" msgstr "" #: ../../reference/expressions.rst:1757 msgid "" "Assignment expressions must be surrounded by parentheses when used as sub-" "expressions in slicing, conditional, lambda, keyword-argument, and " "comprehension-if expressions and in ``assert`` and ``with`` statements. In " "all other places where they can be used, parentheses are not required, " "including in ``if`` and ``while`` statements." msgstr "" #: ../../reference/expressions.rst:1764 msgid "See :pep:`572` for more details about assignment expressions." msgstr "代入式に関してより詳しくは :pep:`572` を参照してください。" #: ../../reference/expressions.rst:1771 msgid "Conditional expressions" msgstr "条件式 (Conditional Expressions)" #: ../../reference/expressions.rst:1783 msgid "" "Conditional expressions (sometimes called a \"ternary operator\") have the " "lowest priority of all Python operations." msgstr "" "条件式 (しばしば \"三項演算子\" と呼ばれます) は最も優先度が低いPython の演算" "です。" #: ../../reference/expressions.rst:1786 msgid "" "The expression ``x if C else y`` first evaluates the condition, *C* rather " "than *x*. If *C* is true, *x* is evaluated and its value is returned; " "otherwise, *y* is evaluated and its value is returned." msgstr "" "``x if C else y`` という式は最初に *x* ではなく条件 *C* を評価します。 *C* " "が true の場合 *x* が評価され値が返されます。 それ以外の場合には *y* が評価さ" "れ返されます。" #: ../../reference/expressions.rst:1790 msgid "See :pep:`308` for more details about conditional expressions." msgstr "条件演算に関してより詳しくは :pep:`308` を参照してください。" #: ../../reference/expressions.rst:1797 msgid "Lambdas" msgstr "ラムダ (lambda)" #: ../../reference/expressions.rst:1808 msgid "" "Lambda expressions (sometimes called lambda forms) are used to create " "anonymous functions. The expression ``lambda parameters: expression`` yields " "a function object. The unnamed object behaves like a function object " "defined with:" msgstr "" "ラムダ式 (ラムダ形式とも呼ばれます) は無名関数を作成するのに使います。\n" "式 ``lambda parameters: expression`` は関数オブジェクトになります。\n" "この無名オブジェクトは以下に定義されている関数オブジェクト同様に動作します:" #: ../../reference/expressions.rst:1817 msgid "" "See section :ref:`function` for the syntax of parameter lists. Note that " "functions created with lambda expressions cannot contain statements or " "annotations." msgstr "" "引数の一覧の構文は :ref:`関数定義 ` を参照してください。ラムダ式で" "作成された関数は文やアノテーションを含むことができない点に注意してください。" #: ../../reference/expressions.rst:1825 msgid "Expression lists" msgstr "式のリスト" #: ../../reference/expressions.rst:1839 msgid "" "Except when part of a list or set display, an expression list containing at " "least one comma yields a tuple. The length of the tuple is the number of " "expressions in the list. The expressions are evaluated from left to right." msgstr "" "リスト表示や辞書表示の一部になっているものを除き、少なくとも一つのカンマを含" "む式のリストはタプルになります。\n" "タプルの長さは、リストにある式の数に等しくなります。\n" "式は左から右へ評価されます。" #: ../../reference/expressions.rst:1848 msgid "" "An asterisk ``*`` denotes :dfn:`iterable unpacking`. Its operand must be " "an :term:`iterable`. The iterable is expanded into a sequence of items, " "which are included in the new tuple, list, or set, at the site of the " "unpacking." msgstr "" "アスタリスク ``*`` は :dfn:`イテラブルのアンパック` を意味します。\n" "この被演算子は :term:`イテラブル ` でなければなりません。\n" "このイテラブルはアンパックされた位置で要素のシーケンスに展開され、新しいタプ" "ル、リスト、集合に入れ込まれます。" #: ../../reference/expressions.rst:1853 msgid "" "Iterable unpacking in expression lists, originally proposed by :pep:`448`." msgstr "" "式リストでのイテラブルのアンパックは最初に :pep:`448` で提案されました。" #: ../../reference/expressions.rst:1858 msgid "" "The trailing comma is required only to create a single tuple (a.k.a. a " "*singleton*); it is optional in all other cases. A single expression " "without a trailing comma doesn't create a tuple, but rather yields the value " "of that expression. (To create an empty tuple, use an empty pair of " "parentheses: ``()``.)" msgstr "" "単一要素のタプル (別名 *単集合 (singleton)* ) を作りたければ、末尾にカンマが" "必要です。単一の式だけで、末尾にカンマをつけない場合には、タプルではなくその" "式の値になります (空のタプルを作りたいなら、中身が空の丸括弧ペア: ``()`` を使" "います。)" #: ../../reference/expressions.rst:1868 msgid "Evaluation order" msgstr "評価順序" #: ../../reference/expressions.rst:1872 msgid "" "Python evaluates expressions from left to right. Notice that while " "evaluating an assignment, the right-hand side is evaluated before the left-" "hand side." msgstr "" "Python は、式を左から右へと順に評価します。\n" "ただし、代入式を評価するときは、右辺が左辺よりも先に評価されます。" #: ../../reference/expressions.rst:1875 msgid "" "In the following lines, expressions will be evaluated in the arithmetic " "order of their suffixes::" msgstr "" "以下に示す実行文の各行での評価順序は、添え字の数字順序と同じになります::" #: ../../reference/expressions.rst:1889 msgid "Operator precedence" msgstr "演算子の優先順位" #: ../../reference/expressions.rst:1894 msgid "" "The following table summarizes the operator precedence in Python, from " "highest precedence (most binding) to lowest precedence (least binding). " "Operators in the same box have the same precedence. Unless the syntax is " "explicitly given, operators are binary. Operators in the same box group " "left to right (except for exponentiation, which groups from right to left)." msgstr "" #: ../../reference/expressions.rst:1900 msgid "" "Note that comparisons, membership tests, and identity tests, all have the " "same precedence and have a left-to-right chaining feature as described in " "the :ref:`comparisons` section." msgstr "" ":ref:`comparisons` 節で述べられているように、比較、所属、同一性のテストは全て" "が同じ優先順位を持っていて、左から右に連鎖するという特徴を持っていることに注" "意してください。" #: ../../reference/expressions.rst:1906 msgid "Operator" msgstr "演算子" #: ../../reference/expressions.rst:1906 msgid "Description" msgstr "説明" #: ../../reference/expressions.rst:1908 msgid "``(expressions...)``," msgstr "``(expressions...)``," #: ../../reference/expressions.rst:1910 msgid "``[expressions...]``, ``{key: value...}``, ``{expressions...}``" msgstr "``[expressions...]``, ``{key: value...}``, ``{expressions...}``" #: ../../reference/expressions.rst:1908 msgid "" "Binding or parenthesized expression, list display, dictionary display, set " "display" msgstr "結合式または括弧式、リスト表示、辞書表示、集合表示" #: ../../reference/expressions.rst:1914 msgid "``x[index]``, ``x[index:index]``, ``x(arguments...)``, ``x.attribute``" msgstr "``x[index]``, ``x[index:index]``, ``x(arguments...)``, ``x.attribute``" #: ../../reference/expressions.rst:1914 msgid "Subscription, slicing, call, attribute reference" msgstr "添字指定、スライス操作、呼び出し、属性参照" #: ../../reference/expressions.rst:1917 msgid ":keyword:`await x `" msgstr ":keyword:`await x `" #: ../../reference/expressions.rst:1919 msgid "``**``" msgstr "``**``" #: ../../reference/expressions.rst:1919 msgid "Exponentiation [#]_" msgstr "べき乗 [#]_" #: ../../reference/expressions.rst:1921 msgid "``+x``, ``-x``, ``~x``" msgstr "``+x``, ``-x``, ``~x``" #: ../../reference/expressions.rst:1921 msgid "Positive, negative, bitwise NOT" msgstr "正数、負数、ビット単位 NOT" #: ../../reference/expressions.rst:1923 msgid "``*``, ``@``, ``/``, ``//``, ``%``" msgstr "``*``, ``@``, ``/``, ``//``, ``%``" #: ../../reference/expressions.rst:1923 msgid "" "Multiplication, matrix multiplication, division, floor division, remainder " "[#]_" msgstr "乗算、行列乗算、除算、切り捨て除算、剰余 [#]_" #: ../../reference/expressions.rst:1927 msgid "``+``, ``-``" msgstr "``+``, ``-``" #: ../../reference/expressions.rst:1927 msgid "Addition and subtraction" msgstr "加算および減算" #: ../../reference/expressions.rst:1929 msgid "``<<``, ``>>``" msgstr "``<<``, ``>>``" #: ../../reference/expressions.rst:1929 msgid "Shifts" msgstr "シフト演算" #: ../../reference/expressions.rst:1931 msgid "``&``" msgstr "``&``" #: ../../reference/expressions.rst:1931 msgid "Bitwise AND" msgstr "ビット単位 AND" #: ../../reference/expressions.rst:1933 msgid "``^``" msgstr "``^``" #: ../../reference/expressions.rst:1933 msgid "Bitwise XOR" msgstr "ビット単位 XOR" #: ../../reference/expressions.rst:1935 msgid "``|``" msgstr "``|``" #: ../../reference/expressions.rst:1935 msgid "Bitwise OR" msgstr "ビット単位 OR" #: ../../reference/expressions.rst:1937 msgid "" ":keyword:`in`, :keyword:`not in`, :keyword:`is`, :keyword:`is not`, ``<``, " "``<=``, ``>``, ``>=``, ``!=``, ``==``" msgstr "" ":keyword:`in`, :keyword:`not in`, :keyword:`is`, :keyword:`is not`, ``<``, " "``<=``, ``>``, ``>=``, ``!=``, ``==``" #: ../../reference/expressions.rst:1937 msgid "Comparisons, including membership tests and identity tests" msgstr "所属や同一性のテストを含む比較" #: ../../reference/expressions.rst:1941 msgid ":keyword:`not x `" msgstr ":keyword:`not x `" #: ../../reference/expressions.rst:1941 msgid "Boolean NOT" msgstr "ブール演算 NOT" #: ../../reference/expressions.rst:1943 msgid ":keyword:`and`" msgstr ":keyword:`and`" #: ../../reference/expressions.rst:1943 msgid "Boolean AND" msgstr "ブール演算 AND" #: ../../reference/expressions.rst:1945 msgid ":keyword:`or`" msgstr ":keyword:`or`" #: ../../reference/expressions.rst:1945 msgid "Boolean OR" msgstr "ブール演算 OR" #: ../../reference/expressions.rst:1947 msgid ":keyword:`if ` -- :keyword:`!else`" msgstr ":keyword:`if ` -- :keyword:`!else`" #: ../../reference/expressions.rst:1947 msgid "Conditional expression" msgstr "条件式" #: ../../reference/expressions.rst:1949 msgid ":keyword:`lambda`" msgstr ":keyword:`lambda`" #: ../../reference/expressions.rst:1949 msgid "Lambda expression" msgstr "ラムダ式" #: ../../reference/expressions.rst:1951 msgid "``:=``" msgstr "``:=``" #: ../../reference/expressions.rst:1951 msgid "Assignment expression" msgstr "代入式" #: ../../reference/expressions.rst:1956 msgid "Footnotes" msgstr "脚注" #: ../../reference/expressions.rst:1957 msgid "" "While ``abs(x%y) < abs(y)`` is true mathematically, for floats it may not be " "true numerically due to roundoff. For example, and assuming a platform on " "which a Python float is an IEEE 754 double-precision number, in order that " "``-1e-100 % 1e100`` have the same sign as ``1e100``, the computed result is " "``-1e-100 + 1e100``, which is numerically exactly equal to ``1e100``. The " "function :func:`math.fmod` returns a result whose sign matches the sign of " "the first argument instead, and so returns ``-1e-100`` in this case. Which " "approach is more appropriate depends on the application." msgstr "" "``abs(x%y) < abs(y)`` は数学的には真となりますが、浮動小数点に対する演算の場" "合には、値丸め (roundoff) のために数値計算的に真にならない場合があります。例" "えば、Python の浮動小数点型が IEEE754 倍精度数型になっているプラットフォーム" "を仮定すると、 ``-1e-100 % 1e100`` は ``1e100`` と同じ符号になるはずなのに、" "計算結果は ``-1e-100 + 1e100`` となります。これは数値計算的には厳密に " "``1e100`` と等価です。関数 :func:`math.fmod` は、最初の引数と符号が一致するよ" "うな値を返すので、上記の場合には ``-1e-100`` を返します。どちらのアプローチが" "適切かは、アプリケーションに依存します。" #: ../../reference/expressions.rst:1966 msgid "" "If x is very close to an exact integer multiple of y, it's possible for ``x//" "y`` to be one larger than ``(x-x%y)//y`` due to rounding. In such cases, " "Python returns the latter result, in order to preserve that ``divmod(x,y)[0] " "* y + x % y`` be very close to ``x``." msgstr "" "x が y の正確な整数倍に非常に近いと、丸めのために ``x//y`` が ``(x-x%y)//y`` " "よりも 1 だけ大きくなる可能性があります。そのような場合、Python は " "``divmod(x,y)[0] * y + x % y`` が ``x`` に非常に近くなるという関係を保つため" "に、後者の値を返します。" #: ../../reference/expressions.rst:1971 msgid "" "The Unicode standard distinguishes between :dfn:`code points` (e.g. U+0041) " "and :dfn:`abstract characters` (e.g. \"LATIN CAPITAL LETTER A\"). While most " "abstract characters in Unicode are only represented using one code point, " "there is a number of abstract characters that can in addition be represented " "using a sequence of more than one code point. For example, the abstract " "character \"LATIN CAPITAL LETTER C WITH CEDILLA\" can be represented as a " "single :dfn:`precomposed character` at code position U+00C7, or as a " "sequence of a :dfn:`base character` at code position U+0043 (LATIN CAPITAL " "LETTER C), followed by a :dfn:`combining character` at code position U+0327 " "(COMBINING CEDILLA)." msgstr "" "Unicode 標準では、 :dfn:`コードポイント (code point)` (例えば、U+0041) と :" "dfn:`抽象文字 (abstract character)` (例えば、\"LATIN CAPITAL LETTER A\") を区" "別します。\n" "Unicode のほとんどの抽象文字は 1 つのコードポイントだけを使って表現されます" "が、複数のコードポイントの列を使っても表現できる抽象文字もたくさんありま" "す。\n" "例えば、抽象文字 \"LATIN CAPITAL LETTER C WITH CEDILLA\" はコード位置 U+00C7 " "にある :dfn:`合成済み文字 (precomposed character)` 1 つだけでも表現できます" "し、コード位置 U+0043 (LATIN CAPITAL LETTER C) にある :dfn:`基底文字 (base " "character)` の後ろに、コード位置 U+0327 (COMBINING CEDILLA) にある :dfn:`結合" "文字 (combining character)` が続く列としても表現できます。" #: ../../reference/expressions.rst:1982 msgid "" "The comparison operators on strings compare at the level of Unicode code " "points. This may be counter-intuitive to humans. For example, ``\"\\u00C7\" " "== \"\\u0043\\u0327\"`` is ``False``, even though both strings represent the " "same abstract character \"LATIN CAPITAL LETTER C WITH CEDILLA\"." msgstr "" "文字列の比較操作は Unicode のコードポイントのレベルで行われます。\n" "これは人間にとっては直感的ではないかもしれません。\n" "例えば、 ``\"\\u00C7\" == \"\\u0043\\u0327\"`` は、どちらの文字も同じ抽象文" "字 \"LATIN CAPITAL LETTER C WITH CEDILLA\" を表現しているにもかかわらず、その" "結果は ``False`` となります。" #: ../../reference/expressions.rst:1987 msgid "" "To compare strings at the level of abstract characters (that is, in a way " "intuitive to humans), use :func:`unicodedata.normalize`." msgstr "" "抽象文字のレベルで (つまり、人間にとって直感的な方法で) 文字列を比較するに" "は :func:`unicodedata.normalize` を使ってください。" #: ../../reference/expressions.rst:1990 msgid "" "Due to automatic garbage-collection, free lists, and the dynamic nature of " "descriptors, you may notice seemingly unusual behaviour in certain uses of " "the :keyword:`is` operator, like those involving comparisons between " "instance methods, or constants. Check their documentation for more info." msgstr "" "自動的なガベージコレクション、フリーリスト、ディスクリプタの動的特性のため" "に、インスタンスメソッドや定数の比較を行うようなときに :keyword:`is` 演算子の" "利用は、一見すると普通ではない振る舞いだと気付くかもしれません。詳細はそれぞ" "れのドキュメントを確認してください。" #: ../../reference/expressions.rst:1995 msgid "" "The power operator ``**`` binds less tightly than an arithmetic or bitwise " "unary operator on its right, that is, ``2**-1`` is ``0.5``." msgstr "" "べき乗演算子 ``**`` は、右側にある単項算術演算子あるいは単項ビット演算子より" "弱い結合優先順位となります。\n" "つまり ``2**-1`` は ``0.5`` になります。" #: ../../reference/expressions.rst:1998 msgid "" "The ``%`` operator is also used for string formatting; the same precedence " "applies." msgstr "" "``%`` 演算子は文字列フォーマットにも使われ、同じ優先順位が当てはまります。"