Python千萬要注意的全局變量和局部變量問題

一、直接在函數中調用全局變量python m = 100 def fun(): print("m1:",m) fun() print("m2:", m)  輸出:函數 二、函數體內調用與全局變量同名的局部變量code m = 100 def fun(): m = 50 print("m1:",m) fun() print("m2:", m) 輸出:blog 解釋:在函數體內
相關文章
相關標籤/搜索