【python超入門 #011】スコープ

スコープとは

資料
スライド

ソースコード
https://github.com/pon-wchoco/python_beginner/tree/main/src/py011

def main():
    hensu_main = "メイン変数"

    # 範囲1
    def scope1():
        hensu_scope1 = "スコープ1の変数"

        # 範囲2
        def scope2():
            hensu_scope2 = "スコープ2の変数"

            # 範囲3-1
            def scope3_1():
                hensu_scope3_1 = "スコープ3_1の変数"
                print(hensu_scope3_1)

            # 範囲3-1
            def scope3_2():
                hensu_scope3_2 = "スコープ3_2の変数"
                print(hensu_scope3_2)

            print(hensu_scope2)
            scope3_1()
            scope3_2()

        print(hensu_scope1)
        scope2()

    print(hensu_main)
    scope1()

if __name__ == "__main__":
    main()

メンターやってます!

個別でのご相談も承っております☆
お気軽にお問い合わせください!
https://menta.work/plan/6341?share=score

Amazon.co.jp : python 入門

コメント

タイトルとURLをコピーしました