为何遍历*argv的参数是控制台会有None出现?
巴扎黑
巴扎黑 2016-11-08 16:47:58
0
1
1041
#!/usr/bin/env python# encoding: utf-8def test_args(*args):
    for arg in args:        print argprint test_args('hi', 24, 5)

运行上面这段代码控制台会多输出一个none是什么意思?

C:\Python27\python.exe C:/Users/Administrator/PycharmProjects/demo/interpy/1.3.py
hi245NoneProcess finished with exit code 0


巴扎黑
巴扎黑

全部回覆(1)
phpcn_u29

如果写成这样,最后不会多一个None:

#!/usr/bin/env python# encoding: utf-8def test_args(*args):
    for arg in args:        print arg
test_args('hi', 24, 5)

你的写法多一个None是因为:函数test_args中没定义返回值,默认会返回None,当你print test_arg('hi', 24, 5)的时候,就把函数的返回值None打印出来了。


熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!