Python--错误总结1

来源:互联网 发布:欧洲人怎么看中国知乎 编辑:程序博客网 时间:2024/05/17 20:28

最近被安利了一本讲Python的书(《Python编程:从入门到实践》)#这大概就是悲剧的开端

首先,因为最早学的是C++还有C,所以并不是很注意缩进的问题(心情简单.jpg),然后,然后就没有然后了,(╯‵□′)╯︵┻━┻ (╯‵□′)╯︵┻━┻

好了,回归正题:

下面展示的代码来自↑上面提到的书第四章

#先展示正确代码

magicians = ['alice', 'david', 'carolina']for magician in magicians:    print(magician.title() + ", that was a great trick!")

输出:

Alice, that was a great trick!
David, that was a great trick!
Carolina, that was a great trick!

 #这个是第一个错误类型

 magicians = ['alice', 'david', 'carolina']for magician in magicians:    print(magician.title() + ", that was a great trick!")

File "/usercode/file.py", line 1
    magicians = ['alice', 'david', 'carolina']
    ^
IndentationError: unexpected indent

在解释这个错误之前,我们先认识一个单词 逃)

  • 朗文当代高级英语辞典

in‧dent 1
 /ɪn'dent,ɪnˋdɛnt/ v. [T ]
 [ɪn'dent] 

MEANINGS 义项

  • to start a line of writing further towards the middle of the page than other lines

    〔书写时〕将〔行首〕缩格

    Use the Tab key to indent the first line of the paragraph. 用跳格键把该段的首行缩格。

in‧dent 2
 /'ɪndent,ˋɪndɛnt/ n. [C ]
 ['ɪndent] 
【尤英】

MEANINGS 义项

  • 1.

    an official order for goods or equipment

    〔正式的〕订(货)单

    [+ for]

    He cancelled the indent for silk scarves. 他取消了真丝围巾的订单。

  • 2.

    an indentation

    行首空格;凹口

       
    • 21世纪大英汉词典

indent /in'dent; 'indent/

  • vt.
    • 1.

      把(边缘等)刻成锯齿状:

      to indent the edge of a wood board

      把一块木板的边缘刻成锯齿状

    • 2.

      使凹进,使凹入:

      The sea indents the coast.

      海水将海岸冲击得凹凸不平。

    • 3.

      把(多份文件等)沿骑缝线割开(或撕开)(以备将来检验文件真伪)

      展开更多
  • vi.
    • 1.

      形成锯齿状;形成凹口

    • 2.

      缩进排印,缩格书写

    • 3.

      签订合同

      展开更多
  • n.
    • 1.

      锯齿形缺口;(V形)凹口

    • 2.

      1. (印刷中的)首行缩排;(书写中的)首行缩格

      2. (缩排等时留出的)空格;缩格排印(或书写)的首行(或段落)

    • 3.

      师徒契约;定期服务合同

      展开更多

    indent /in'dent; 'indent/

    • vt.
      • 1.

        压凹痕于,压印于

      • 2.

        压印(图案等):

        to indent patterns

        压印图案

    • n.
      • 凹痕,凹坑

    通过与正确代码的比较可以很容易发现其不同之处,即第一行开头处有一个空格(╯‵□′)╯︵┻━┻

    原来学C++的时候完全没有遇到过,结果这里卡了两天,我还以为是编译器的问题,(╯‵□′)╯︵┻━┻

    #接下来是第二个错误

    magicians = ['alice', 'david', 'carolina']for magician in magicians:print(magician.title() + ", that was a great trick!")

     File "/usercode/file.py", line 3
        print(magician.title() + ", that was a great trick!")
            ^
    IndentationError: expected an indented block

    这里竟然又要求缩进了掀桌(Python,大概是在折磨我那弱小的心灵……)


    原创粉丝点击