Is there a way around coding in Python without the tab, indent & whitespace criteria?

前端 未结 29 1002
小鲜肉
小鲜肉 2020-12-31 14:05

I want to start using Python for small projects but the fact that a misplaced tab or indent can throw a compile error is really getting on my nerves. Is there some type of s

29条回答
  •  一生所求
    2020-12-31 14:39

    The real answer to your question is that if you are going to use the language you need to learn its syntax. Just as an error in indenting python can generate a compiler error, an error using braces in various other languages can also generate a compiler error.

    Even worse it can be silently misinterpreted by the compiler to do the wrong thing. This is particularly dangerous when the indenting doesn't match the desired meaning. I.e. in many other languages:

    If(first condition)
       if (second condition)
          do something interesting;
    else
      do something different;
    

    Will lead to unpleasant surprises.

    Python forces you to write code that looks like what it does. This is a good thing for other programmers who have to read your code, or for you when you try to read your own code after a month or so.

提交回复
热议问题