diff --git a/README.md b/README.md index 3cc3d9b..745e4be 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,8 @@ 本人边学习Python3,边把一些小脚本(自己写的和网上找的)经过本机测试后然后同步到github上,供初学者下载研究,欢迎fork,也欢迎提交新的Python小脚本,特别是一些有趣好玩的小程序!有什么问题可以通过Issues讨论,喜欢的话点Star或分享给别人哦! 学习Python3记录博客: -http://www.tantengvip.com/category/develop/python3/ +http://blog.tanteng.me/category/develop/python3/ + +注:IDE是PyCharm4.5,Python版本是3.4.3 + +欢迎大家提交好的学习Python3的脚本,我会合并进来! diff --git a/args_kwargs.py b/args_kwargs.py index 67edeb8..4095ca7 100644 --- a/args_kwargs.py +++ b/args_kwargs.py @@ -7,6 +7,7 @@ def alias(*args, **kwargs): print('args=', args) print('kwargs=', kwargs) + return alias(3, 23, 3, 3,a='hello',b=3,c='C') diff --git a/closure.py b/closure.py index 47dd67c..57fe5dd 100644 --- a/closure.py +++ b/closure.py @@ -1,8 +1,9 @@ def hellocounter (name): - count=[0] + count=0 #PYTHON 2.x 中,要写count=[0] def counter(): - count[0]+=1 - print('Hello,',name,',',count[0],' access!') + nonlocal count #PYTHON 2.x 中,此行和下一行要换成count[0]+=1 + count+=1 + print('Hello,',name,',',count,' access!')#PYTHON 2.x 中请自觉换成str(count[0]) return counter hello = hellocounter('ma6174') @@ -10,6 +11,18 @@ def counter(): hello() hello() +''' +执行结果 +>>> hello() +Hello, ma6174 , 1 access! +>>> hello() +Hello, ma6174 , 2 access! +>>> hello() +Hello, ma6174 , 3 access! +''' +##为什么PYTHON 2.x中不直接写count而用list?这是python2的一个bug,如果用count话,会报这样一个错误: +##UnboundLocalError: local variable 'count' referenced before assignment. + def make_adder(addend): def adder(augend): return augend + addend