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

前端 未结 29 990
小鲜肉
小鲜肉 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:44

    Not really. There are a few ways to modify whitespace rules for a given line of code, but you will still need indent levels to determine scope.

    You can terminate statements with ; and then begin a new statement on the same line. (Which people often do when golfing.)

    If you want to break up a single line into multiple lines you can finish a line with the \ character which means the current line effectively continues from the first non-whitespace character of the next line. This visually appears violate the usual whitespace rules but is legal.

    My advice: don't use tabs if you are having tab/space confusion. Use spaces, and choose either 2 or 3 spaces as your indent level.

    A good editor will make it so you don't have to worry about this. (python-mode for emacs, for example, you can just use the tab key and it will keep you honest).

提交回复
热议问题