Python – 这个函数声明有什么问题?

huangapple go评论67阅读模式
英文:

Python - What is wrong with this fucniton declaration?

问题

SyntaxError: 无效的语法

我遇到了一个SyntaxError。我在网上查看后发现这应该是正确的声明方式。这有什么问题吗?

英文:
def convert(self, path: str):
                                     ^
SyntaxError: invalid syntax

i am getting a SyntaxError. I checked online and saw this is how it should be declared. what is wrong with this?

答案1

得分: 4

如果函数已定义,则必须有代码或pass,否则当您不想立即实现代码时。

def foo():
    pass

或者,如果您想在函数被使用时发出警告。

def foo():
    raise(Exception("NotImplemented"))
英文:

if function defined it must have a code or pass instead when you don't want to implement code right now.

def foo():
   pass

or if you want to warn when function used

def foo():
    raise(Exception("NotImplemented"))

答案2

得分: 0

there is nothing in your function just continue your code where I put print().
same with all others things like "if" and "for".

def convert(self, path: str):
print()

英文:

there is nothing in your function just continue your code where I put print().
same with all others things like "if" and "for".

def convert(self, path: str):
	print()

huangapple
  • 本文由 发表于 2023年1月9日 18:04:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/75055683.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定