Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何检查Python中的shell中是否调用了函数?_Python_Function - Fatal编程技术网

如何检查Python中的shell中是否调用了函数?

如何检查Python中的shell中是否调用了函数?,python,function,Python,Function,创建一个函数,每次调用时从事实列表中打印一个随机事实 我的代码: import random def FACT_FUNCTION(): x = ["Albert Einstien created the theory of relativity","The world record for the one hundred meter dash is nine point five eight seconds","The founder o

创建一个函数,每次调用时从事实列表中打印一个随机事实

我的代码:

import random
def FACT_FUNCTION():
    x = ["Albert Einstien created the theory of relativity","The world record for the one hundred meter dash is nine point five eight seconds","The founder of apple is Steve Jobs","Google's current CEO is Sundar Pichai"]
    s = random.choice(x)
到目前为止,我已经做了所有的事情,但是我该怎么做呢 我检查我的函数是否已被调用。我想 这个问题是要看的 如果在中调用了函数 但是我不确定。如果有人 可以提供一个代码,这将是很好的!
谢谢

将打印语句添加到函数中。将函数调用添加到程序中

import random
def FACT_FUNCTION():
    x = ["Albert Einstien created the theory of relativity","The world record for the one hundred meter dash is nine point five eight seconds","The founder of apple is Steve Jobs","Google's current CEO is Sundar Pichai"]
    s = random.choice(x)
    print(s)
FACT_FUNCTION()
保存名为FACT_FUNCTION.py的文件。使用以下命令在终端中运行:

python3 FACT_FUNCTION.py

当然,你们可以让你们的函数从文件中读取一个计数器,递增它,然后写回它。这就是你的意思吗?按照我对提示的解释,你已经满足了要求(除了你不打印外)。函数除了被调用外,什么都不做。在函数中输入的任何内容都将在函数被调用时发生。基本上,您已经考虑过了—您只需要在函数中打印一个
。您所说的“函数在shell中被调用”是什么意思?从terminal/cmd只能运行程序,而不能运行该程序中的独立函数。通过命令“python3 filename.py”运行它,并使程序调用该函数。