![](/img/trans.png)
[英]why do i get MethodError: objects of type Float64 are not callable?
[英]MethodError: objects of type Float64 are not callable
我做了一个函数来查找球体的体积:
function volume_sphere(r)
(4/3)(round(π, sigdigits=6))(r)^3
end
julia> println(volume_sphere(5))
我收到此错误消息:
错误:MethodError:Float64 类型的对象不可调用
堆栈跟踪:
[1] volume_sphere(::Int64) 在 C:\\Users\\Practice.jl:27
[2] 在 none:0 处的顶级范围
问题从何而来?
此处详细解释了此问题。
简而言之,不允许在两个带括号的表达式的并列中省略*
,也不允许在带括号的表达式之前放置变量。 因此这是一个有效的代码:
4/3*round(π, sigdigits=6)*r^3
但是您可以编写例如2r+3(r^2+1)r
并且它将是有效的代码行。
function volume_sphere(r)
(4/3)*(round(π, sigdigits=6))*(r^3)
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.