[Python] Indent and block comments in function

在使用區域註解之後的程式碼會顯示錯誤訊息:

IndentationError: unexpected indent

I am using Python 2 /Python 3 and wrote the following:

def arithmetic(A):
x=1
"""
Some comments here
"""
if x=1:
x=1
elif x=2:
x=2
return 0

But it has the indentation issue:

if x=1: ^
IndentationError: unexpected indent

So how to write comments in the function?


解法:

def arithmetic(A):
x=1
"""
Some comments here
"""
if x==1:
x=1
elif x==2:
x=2
return 0

The """ xxx """ is a docstring. Yes, it can be used as a comment, but it winds up being part of the actual code, so it needs to be indented。

原來註解也要內縮 @_@;

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *