社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

如何将输入作为参数传递给python中的另一个函数?它不

Alex • 5 年前 • 1567 次点击  
def executeCommand(myDoc): 
    print(myDoc)
    return 

def insert():
    print("insert command:")
    return

def delete():
    print("delete command:")
    return

def main():
    print("Functional Text Editor ")
    executeCommand(input("Type in file name: "))

if __name__ == '__main__':
    main()

然后,主运行会提示“键入文件名:”但之后不执行任何操作。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/40979
 
1567 次点击  
文章 [ 1 ]  |  最新文章 5 年前
Anurag A S
Reply   •   1 楼
Anurag A S    6 年前

程序中的executecommand函数接受输入mydoc并打印输入。
当程序运行时,它正是这样做的。以下给定示例中的输入hello被视为函数executecommand的输入。此函数打印 hello 并返回到调用程序main,然后由于没有更多语句而终止。

>>> def executeCommand(myDoc): 
...     print(myDoc)
...     return 
... 
>>> def insert():
...     print("insert command:")
...     return
... 
>>> def delete():
...     print("delete command:")
...     return
... 
>>> def main():
...     print("Functional Text Editor ")
...     executeCommand(input("Type in file name: "))
... 
>>> if __name__ == '__main__':
...     main()
... 
Functional Text Editor 
Type in file name: hello
hello
>>>