社区所有版块导航
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中,如何调用函数内部的函数?[暂停]

devinxxd • 6 年前 • 635 次点击  

我想调用函数内部的函数来打印c。有两个函数。

def ash():
    def jsh():
        k = 5
        j = k*5
        return j

    def ush():

        a = 5
        b = 6
        c = a + b
        return c

print(ush())
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/50982
文章 [ 1 ]  |  最新文章 6 年前
Jean-Paul Calderone
Reply   •   1 楼
Jean-Paul Calderone    7 年前

你叫它就像你叫任何东西一样。使用调用语法: ...(...) .

你的挑战是有一个对象的引用,这样你就可以调用它。最明显的解决方案是返回函数。

def ash():
    def ush():
        a = 5
        b = 6
        c = a + b
        return c
    return ush

print(ash()())
# or
ush = ash()
print(ush())