简体   繁体   English

在python中调用库函数

[英]Calling library functions in python

Case I: In some cases, I use the library name to call some set of function ie, np.median().案例一:在某些情况下,我使用库名称来调用一些函数集,即 np.median()。
Case II: And in some cases, I use the variable name and library name to call another set of function ie, np.mean(heights) or heights.mean().情况二:在某些情况下,我使用变量名和库名来调用另一组函数,即 np.mean(heights) 或 heights.mean()。
In case II, I am able to use both library name and variable name.在情况 II 中,我可以同时使用库名和变量名。 In case I, only library name works.在情况下,只有库名有效。

My doubt is how to differentiate these tow sets of functions.我的疑问是如何区分这两组功能。 If I am wrong in anyway, please clear my thoughts.如果我错了,请清除我的想法。 (here i am referring to python language) (这里我指的是python语言)

thank you.谢谢你。

In the first case you're calling a method (function) of the library.在第一种情况下,您正在调用库的方法(函数)。 Libraries are usually class instances or collections of functions within a module.库通常是模块内的类实例或函数集合。

In the second example instead, you're again calling a function from the module but in this case it returns a ndarray (a numpy list basically) which itself has some methods that can be called on it.相反,在第二个示例中,您再次从模块调用一个函数,但在这种情况下,它返回一个 ndarray(基本上是一个 numpy 列表),它本身有一些可以调用的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM