缺少预期输出

2024-04-20 07:05:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图用“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'."  

Tags: py命令isdefargsthisonejust
3条回答

很可能,在定义函数之后,您没有调用它们。你知道吗

在那些方法之后。叫他们例如:

print_none()

您可以将它放在文件的末尾,或者如果您要在shell中导入文件,您可以直接在后面键入它。你知道吗

因为该文件实际上没有调用任何函数,所以没有任何输出。你知道吗

文件定义了四个函数。:)

尝试将调用添加到print_noneprint_one,依此类推:

print_none()
print_one("hello")
print_two("hello", "world")
print_two_again("hello", "world")

您正在定义函数,但看起来并不是在调用它们。你知道吗

相关问题 更多 >