打印命令行参数时额外输出无 [英] Extra output none while printing an command line argument
问题描述
这是我学习python的第一天。所以对你们中的许多人来说这是一个白费问题。请看下面的代码:
#!/ usr / bin / env python
import sys
def hello(name):
name = name +'!!!!'
print'hello',name
def main():
print hello(sys.argv [1])$ b
$ b if __name__ =='__main__':
main()
当我运行它时
$ .// Python-1.py爱丽丝
hello爱丽丝!!!!
None
现在,我无法理解
None 来自哪里?
解决方案计数
hello
函数中打印hello alice !!!
,和打印hello
函数的结果。因为hello
函数没有返回一个值(你会用return
语句)做一个值,它会结束返回对象None
。main
函数中的None
。It's my day 1 of learning python. so it's a noob question for many of you. See the following code:
#!/usr/bin/env python import sys def hello(name): name = name + '!!!!' print 'hello', name def main(): print hello(sys.argv[1]) if __name__ == '__main__': main()
when I run it
$ ./Python-1.py alice hello alice!!!! None
Now, I have trouble understanding where this
"None"
came from?解决方案Count the number of
"hello alice!!!"
in thehello
function, and printing the result of thehello
function. Because thehello
function doesn't return a value (which you'd do with thereturn
statement), it ends up returning the objectNone
. Yourmain
function ends up printingNone
.这篇关于打印命令行参数时额外输出无的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!