模擬C/C++的static變數 - GaryLee

模擬C/C++的static變數 - GaryLee

瀏覽:501
日期:2025-05-24
在C/C++內,我們常會用如下的方法來弄一個所謂的static變數。 void func() { static int a = 10; a += 1; printf("%d\n", a); } 但是,在Python內,似乎沒有所謂的static變數。除非你去宣告一個global變數。但是,global變數往往容易讓code變得複雜,而且區分不 ......看更多