search
尋找貓咪~QQ 地點 桃園市桃園區 Taoyuan , Taoyuan

PYTHON機器學習自學/自修 整理[00016] ~ 語言技術:PYTHON GOSSIP(變數範圍) – jashliao部落格

PYTHON機器學習自學/自修 整理[00016] ~ 語言技術:PYTHON GOSSIP(變數範圍)



程式

import sys
import decimal#精準度/精度 運算

x = 10
y = 10
def some():
	x = 20#區域變數
	print(x)#印區域變數
	print(y)#印全域變數

some()
print(x)#印全域變數
print(y)#印全域變數

print('---------')#印全域變數

x = 10# 全域
def outer():
    y = 20# 在 outer() 函式範圍
    def inner():
        z = 30# 在 inner() 函式範圍
        print(x)# 內建範圍 print,全域的 x
        print(y)# 內建範圍 print,外包 outer() 函式的 y
        print(z)
    inner()
      
outer()#不能直接使用嵌入函數 inner()
print(x)# 內建範圍 print,全域的 x



熱門推薦

本文由 jashliaoeuwordpress 提供 原文連結

寵物協尋 相信 終究能找到回家的路
寫了7763篇文章,獲得2次喜歡
留言回覆
回覆
精彩推薦