Python中模块和类之间的区别 [英] Difference between Module and Class in Python

查看:262
本文介绍了Python中模块和类之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以给模块中的变量赋值吗?如果是,那么类和模块之间有什么区别?

Can I assign value to a variable in the module? If yes, what is the difference between a class and module?

PS:我是Java人士(以防它有助于解释)。谢谢。

PS: I'm a Java guy (in case it helps in the way of explaining). Thanks.

推荐答案


  • 模块


    模块是一个包含Python定义和语句的文件。

    A module is a file containing Python definitions and statements.


  • 作为 doc 说。

    因此python中的模块只是组织代码,并且包含python类或仅函数。
    如果您在项目中需要这些类或函数,只需导入即可。
    例如,python中的 math 模块仅包含一堆函数,您只需调用所需的那些函数( math.sin )。
    只需看看这个问题

    So a module in python is simply a way to organize the code, and it contains either python classes or just functions. If you need those classes or functions in your project, you just import them. For instance, the math module in python contains just a bunch of functions, and you just call those needed (math.sin). Just have a look at this question.

    另一方面,python类类似于java类,只是结构略有不同。

    On the other hand a python class is something similar to a java class, it's only structured in a slightly different way.

    这篇关于Python中模块和类之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆