<span id="7ztzv"></span>
<sub id="7ztzv"></sub>

<span id="7ztzv"></span><form id="7ztzv"></form>

<span id="7ztzv"></span>

        <address id="7ztzv"></address>

            習題 2: 注釋和井號?

            程序里的注釋是很重要的。它們可以用自然語言告訴你某段代碼的功能是什么。在你想要臨時移除一段代碼時,你還可以用注解的方式將這段代碼臨時禁用。接下來的練習將讓你學會注釋:

            1
            2
            3
            4
            5
            6
            7
            8
            9
            # A comment, this is so you can read your program later.
            # Anything after the # is ignored by python.
            
            print "I could have code like this." # and the comment after is ignored
            
            # You can also use a comment to "disable" or comment out a piece of code:
            # print "This won't run."
            
            print "This will run."
            

            從現在開始,我將用這樣的方式來寫代碼。我一直在強調“完全相同”,不過你也不必按照字面意思理解。你的程序在屏幕上的顯示可能會有些不同,不過重要的是你在文本編輯器中輸入的文本的正確性。事實上,我可以用任何編輯器寫出這段程序,而且內容是完全一樣的。

            你應該看到的結果?

            $ python ex2.py 
            I could have code like this.
            This will run.
            $
            

            再次說明,我不會再貼各種屏幕截圖了。你應該明白上面的內容是輸出內容的字面翻譯,而 $ python ... 和最后的 $ 之間才是你應該關心的內容。

            加分習題?

            1. 弄清楚”#”符號的作用。而且記住它的名字。(中文為井號,英文為 octothorpe 或者 pound character)。
            2. 打開你的 ex2.py 文件,從后往前逐行檢查。從最后一行開始,倒著逐個單詞單詞檢查回去。
            3. 有沒有發現什么錯誤呢?有的話就改正過來.
            4. 朗讀你寫的習題,把每個字符都讀出來。有沒有發現更多的錯誤呢?有的話也一樣改正過來。

            Project Versions

            Table Of Contents

            Previous topic

            習題 1: 第一個程序

            Next topic

            習題 3: 數字和數學計算

            This Page

            <span id="7ztzv"></span>
            <sub id="7ztzv"></sub>

            <span id="7ztzv"></span><form id="7ztzv"></form>

            <span id="7ztzv"></span>

                  <address id="7ztzv"></address>

                      亚洲欧美在线