2024-10-02 18:14:39 发布
网友
我有一个代码如下
b=1 c=50 d=1 e=5 . . . St= tritriangle(1,b,c,d,e) . . .
在另一个.py file中,我有如下函数:
.py file
def tritriangle(Ashape,Bshape,Cshape,Dshape,Eshape) Cshape *= 1.0 Fshape *= Cshape return Fshape
这里python给出了Cshape的UnboundLocalError。这有什么问题?你知道吗
UnboundLocalError
因为引用Fshape之前没有定义它。如果它引用全局变量,则必须在函数中声明global Fshape,才能更改其值。你知道吗
Fshape
global Fshape
因为引用
Fshape
之前没有定义它。如果它引用全局变量,则必须在函数中声明global Fshape
,才能更改其值。你知道吗相关问题 更多 >
编程相关推荐