python 之闭包

时间:2021-08-30 08:21:46   收藏:0   阅读:4

闭包


def counter(start_at=0):
    count = [start_at]
	
    def inner():
        count[0] += 1
    	return count[0]

    return count

a = counter(10)
print(a())
print(a())
print(a())

# ---------输出结果----------
# 11
# 12
# 13

原文:https://www.cnblogs.com/gxfaxe/p/15197811.html

评论(0)
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!