Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
>>> x = 'foo' >>> {0: locals().get('x')} {0: 'foo'} >>> {0: locals().get('x' + spam) for spam in ['']} {0: None}
この行動の不一致の理由は何ですか?
dict 内包表記とジェネレーター内包表記は、独自のローカル スコープを作成します。リスト内包表記は Python 2.x にはありませんが、Python 3 にはあります。