我正试图用“pythonex18.py”命令从电子书学习Python中运行这个文件,但它没有输出任何东西。怎么了?你知道吗
# this one is like your scripts with argv
def print_two(*args):
arg1, arg2 = args
print "arg1: %r, arg2: %r" % (arg1, arg2)
# ok, that *args is actually pointless, we can just do this
def print_two_again(arg1, arg2):
print "arg1: %r, arg2: %r" % (arg1, arg2)
# this takes just one argument
def print_one(arg1):
print "arg1: %r" % arg1
# this one takes no arguments
def print_none():
print "I got nothin'."
很可能,在定义函数之后,您没有调用它们。你知道吗
在那些方法之后。叫他们例如:
您可以将它放在文件的末尾,或者如果您要在shell中导入文件,您可以直接在后面键入它。你知道吗
因为该文件实际上没有调用任何函数,所以没有任何输出。你知道吗
文件定义了四个函数。:)
尝试将调用添加到
print_none
、print_one
,依此类推:您正在定义函数,但看起来并不是在调用它们。你知道吗
相关问题 更多 >
编程相关推荐