Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.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
Python3:在cmd中输入以返回函数_Python_Python 3.x_Function_Input - Fatal编程技术网

Python3:在cmd中输入以返回函数

Python3:在cmd中输入以返回函数,python,python-3.x,function,input,Python,Python 3.x,Function,Input,我目前正在努力学习“艰苦学习Python”,并开始了关于函数的第一个练习。只需创建一些函数并将它们打印出来,就像本书前面的示例一样 代码: cmd中的输出: C:\Users\[USER]\Google Drive\Python\Learn Python the Hard Way>python ex18.py arg1: 'Zed', arg2: 'Shaw' arg1: 'Zed', arg2: 'Shaw' arg1: 'First!' I got nothing. 我想在这方面做一

我目前正在努力学习“艰苦学习Python”,并开始了关于函数的第一个练习。只需创建一些函数并将它们打印出来,就像本书前面的示例一样

代码:

cmd中的输出:

C:\Users\[USER]\Google Drive\Python\Learn Python the Hard Way>python ex18.py
arg1: 'Zed', arg2: 'Shaw'
arg1: 'Zed', arg2: 'Shaw'
arg1: 'First!'
I got nothing.
我想在这方面做一些研究,所以在运行它时,我不想只给我上面的四行代码,而是希望能够输入函数的名称,然后返回结果。我尝试了以下内容,但也许我不明白Python是如何工作的

x = input("> ")
print(x)
我对术语不太清楚,但在cmd中会给出以下信息:

C:\Users\[USER]\Google Drive\Python\Learn Python the Hard Way>python ex18.py
> print_none()  # This is something I write myself
I got nothing.
例如:

/home/denis/zmqPG/bin/python /home/denis/PycharmProjects/useless/so2.py
F name:print_one(5)
arg1: 5

这个问题可能有点模糊,但我自己找到了解决办法。我想要的是将脚本的“导入”功能导入cmd,然后允许输入命令并返回之前硬编码的行:

C:\Users\[User]\Google Drive\Python\Learn Python the Hard Way>python
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] on 
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ex18
arg1: 'Zed', arg2: 'Shaw'
arg1: 'Zed', arg2: 'Shaw'
arg1: 'First!'
I got nothing.
>>> ex18.print_none()
I got nothing.
>>>

返回方法调用的结果?我试图更改问题,现在有意义吗?是的,因此您希望指定一个方法名称,然后执行它并将结果打印到控制台。是的,这就是我试图做的。我回滚了您的最新编辑(仍然可以从中获得)-您的问题应该严格地保持为一个问题,尽管你非常欢迎发表你自己的答案,甚至接受它来标记这个问题已经解决。另见。
/home/denis/zmqPG/bin/python /home/denis/PycharmProjects/useless/so2.py
F name:print_one(5)
arg1: 5
C:\Users\[User]\Google Drive\Python\Learn Python the Hard Way>python
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] on 
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ex18
arg1: 'Zed', arg2: 'Shaw'
arg1: 'Zed', arg2: 'Shaw'
arg1: 'First!'
I got nothing.
>>> ex18.print_none()
I got nothing.
>>>