LoginSignup
0
0

More than 5 years have passed since last update.

Python > ifインデント内で定義したoptを使ってその上位でチェックする (if opt:)

Last updated at Posted at 2018-03-23
動作環境
ideone (Python 3.5)

if文のインデントにて_qを定義して、その_qをifでチェックしている。

以下のような実装だ。
https://ideone.com/wDTrPu

val = 314

if val == 314:
    opt = True
else:
    opt = False

if opt:
    print('opt')
opt

optのスコープはifインデント内でなく、その上位側にも見えているのか。

link

謝辞

@shiracamus さんのコメントにてPythonでは関数単位のスコープであることを教えていただきました。

情報感謝です。

0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0