0

私はPythonが初めてで、次の基本的なPython構文を理解しようとしています。前もって感謝します。

foo = self._setup['bar']

更新: 以前のコード セグメントのタイプミスを修正しました。

4

1 に答える 1

4

pythonはキーワードではないため、これは有効な Python ではありません。

>>> foo = python self._setup['bar']
  File "<stdin>", line 1
    foo = python self._setup['bar']
                    ^
SyntaxError: invalid syntax

有効な Python コードは次のようになります

foo = self._setup['bar']

これは次のように構成されます。

self                     # Get the value of self (typically the current object)
self._setup              # Get the attribute "_setup" of that value
self._setup['bar']       # Get the item "bar" of the attribute value
foo = self._setup['bar'] # Assign the result to the variable foo

これらはすべて非常に基本的な構造です。詳細については、Python チュートリアルを参照してください。

于 2012-05-31T19:19:40.770 に答える