ä¾ãã°ãforæã®ãããã¯ã¯globalç°å¢ã¨åãã§ã¹ã³ã¼ããããããã¦ããªãã globalã¹ã³ã¼ãã¯æ®éã«å®ç¾©ãããªãã¸ã§ã¯ãã§ã次ã®ããã«é¢æ°ããã§ãã¢ã¯ã»ã¹å¯è½ã x = 1 #globalãªãã¸ã§ã¯ã def f(): return x print f() å®è¡çµæã 1 é¢æ°ã®ãã¼ã«ã«ã¹ã³ã¼ãã¨ããã®ã¯ def f(): x = 1 return x ã¨ããããã«é¢æ°ã®ä¸ã§å®è¡ããå¤æ°ã ã¡ãªã¿ã«ãå½ããåãããããªããã x = 0 class cl(object): global x x = 2 ãªã©ã¨ããããã«ã¯ã©ã¹ãããã¯ã®ä¸ã§globalå¤æ°ã®å¤ãå¤æ´ãããã¨ãã§ãããæ®éã¯ã¡ã½ããä¸ã§å¤ãæ¸ãæããã¨æãã®ã§ãä¸ã®ããã«ã¯ã©ã¹å®ç¾©ã§ç´æ¥å¤ãå¤ããããã«ã¯ããªãã¨æããã ãã¨ãã¯ã©ã¹ãããã¯ã¯ã¯ã©ã¹å¤æ°ãããã®ã§ãglobalã¨ã¯ã©ã¹ãããã¯ã¯ã¹ã³ã¼ããåãããã¦ã
{{#tags}}- {{label}}
{{/tags}}