U87
V2EX  ›  问与答

py 中, nonlocal 与 global 变量问题

  •  
  •   U87 · Jul 20, 2018 · 1510 views
    This topic created in 2859 days ago, the information mentioned may be changed or developed.

    最近写东西时遇到 local variable 'x' referenced before assignment 后来查是因为 python 3.x 以后对局部变量问题改进了引入了 nonlocal,可以避免使用全局变量的风险 但是小弟有一问题,一个函数中几个 for 循环后居然有报 local variable 'x' referenced before assignment 这种错

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3684 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 04:49 · PVG 12:49 · LAX 21:49 · JFK 00:49
    ♥ Do have faith in what you're doing.