Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何划分为多个部分_Python_Python 3.x_Jupyter - Fatal编程技术网

Python 如何划分为多个部分

Python 如何划分为多个部分,python,python-3.x,jupyter,Python,Python 3.x,Jupyter,你能帮帮我吗。 我正在读一本面向初学者的Python书籍,我想在一个笔记本文件中测试我学到的所有新东西。(我使用Jupyter) 我对下面的例子有一些评论。我打算在我忘了什么的时候用这个笔记本 我如何划分每个章节,使其独立,并且不影响同一笔记本文件中的其他练习? 我希望这个问题有意义 亲切问候,, Nesh您可以将每个章节分成几个类,这样(只要语法正确)每个类都不会影响其他类。例如: #! /usr/bin/env python3 class chapter1: def run(sel

你能帮帮我吗。 我正在读一本面向初学者的Python书籍,我想在一个笔记本文件中测试我学到的所有新东西。(我使用Jupyter)

我对下面的例子有一些评论。我打算在我忘了什么的时候用这个笔记本

我如何划分每个章节,使其独立,并且不影响同一笔记本文件中的其他练习? 我希望这个问题有意义

亲切问候,,
Nesh

您可以将每个章节分成几个类,这样(只要语法正确)每个类都不会影响其他类。例如:

#! /usr/bin/env python3

class chapter1:
    def run(self):

        #in this chapter I learned how to print to the console:
        print ("Hello world")

class chapter2:
    def run(self):

        #in this chapter I learned how to print variables
        a = 1;
        b = 2;
        print ("%i + %i = %i" % (a,b,a+b))

#here is where you can run each chapter if you want
c1 = chapter1()
c1.run() # this will output "Hello world"

c2 = chapter2()
c2.run() # this will output "1 + 2 = 3"

编辑:对不起,当我回答这个问题时,我没有意识到Jupyter是什么。这个答案的目标是将所有笔记保存在一个文本文件中。

这正是我需要的。非常感谢您抽出时间。