擅长:python、mysql、java
<p>所以是的,当你开始的时候,这会让人困惑,我同意你的观点。所以让我让它变得超级简单。你知道吗</p>
<p>python中的函数<code>def</code>是包含代码的容器。它们只运行一次就完成了。
类是在类中包含一组函数(称为方法)的实例,这些函数可以操作类中的数据,直到类关闭,或者程序使用指定的实例完成。你知道吗</p>
<pre><code>x = Classname() #creates an instance of the class now named x
x.start() # runs the function start inside the class. Can pass variables, or use existing variables under the self. notation.
</code></pre>
<p>模块是包含函数或类的文件。所有模块均已导入。你知道吗</p>
<pre><code>import os
from os import getcwd #function or class inside the modeul
</code></pre>
<p>他们可以这样称呼:</p>
<pre><code>print(os.getcwd())
print(getcwd())
</code></pre>
<p>可以导入任何.py文件。如果目录中有一个名为<code>__init__.py</code>的文件,则可以导入该目录。文件可以为空。然后目录名成为模块名,单个文件是这样导入的子模块:</p>
<pre><code>import myfolder.mymodule
from myfolder import mymodule # the same as above
</code></pre>
<p>那是我能做的最简单的事了。还有什么问题,你需要看一下文件。但你最好的办法是做实验,用错误的方法去做,直到你用正确的方法去做才是最好的老师。你知道吗</p>