开发者

Why does importing as modules and writing creates a different result?

def matrixdets(a):
    x=(a[0][0] * a[1][1] * a[2][2]) + \
      (a[0][1] * a[1][2] * a[2][0]) + \
      (a[0][2] * a[1][0] * a[2][1])
    print(x)

I wrote this co开发者_如何学运维de to find a certain value of a matrix. It returns a number when I type the function in python. However, when i import this as a module, it just returns the matrix i orginally entered. Why does that happen?


As Graeme said, it doesn't return anything. When you import it, the function gets compiled at the time of importation.

Does your module define a and then run matrixdets on it? It will do that even when you import the function from a module, since importing a module executes all the code inside it.

You need to be clearer about what precisely you're doing and what your output is.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜