英文:
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()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论