【发布时间】:2021-12-29 12:02:29
【问题描述】:
这是我的代码。我什至不能使用数据库。
我需要在函数变量值中不使用 return 语句类。
class Hello:
def alex_details():
name = "Hello"
last_nem = "World"
def liam_details():
name = "Hello"
last_name = "World"
hi = Hello()
print(hi.alex_details.name)
错误:
print(hi.alex_details.name)
AttributeError: 'function' object has no attribute 'name'
【问题讨论】:
-
有很多方法可以做到这一点,但目前,这两个函数中只有局部变量。避免返回语句的原因是什么?
-
如果你想要命名空间使用嵌套类。
-
我想使用它的不同功能和类
标签: python python-3.x