【问题标题】:How can i print a function contained within another function and called by a third function?如何打印包含在另一个函数中并由第三个函数调用的函数?
【发布时间】:2022-11-19 11:56:45
【问题描述】:

我想打印 10,但出现错误:AttributeError: 'function' object has no attribute 'x'

怎么修?谢谢

def function1():
    def x(): 
        a=10
        return a
  
def function2():
    y = function1.x()
    return y

function2()


【问题讨论】:

标签: python python-3.x function


【解决方案1】:

您需要 return x 并调用 function1 作为函数

def function1():
    def x(): 
        a=10
        return a
    return x
  
def function2():
    y = function1().x()
    return y

function2()

【讨论】:

    猜你喜欢
    • 2021-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-29
    • 1970-01-01
    • 1970-01-01
    • 2014-07-14
    相关资源
    最近更新 更多