开发者

syntax error in python function definitions

开发者 https://www.devze.com 2023-02-24 11:43 出处:网络
sorry if I sound like a complete idiot when asking this, I\'m very new to Python. When I create a func开发者_运维问答tion like this :

sorry if I sound like a complete idiot when asking this, I'm very new to Python. When I create a func开发者_运维问答tion like this :

def load_content(name, colorkey=None, datatype):

It tells me there is a syntax error. From what I can tell, this is the right way to write a function. Like I said, I'm very new. Does anyone know what's wrong here?


You can't have default arguments between non-default arguments

def load_content(name, colorkey=None, datatype=None):

or

def load_content(name, datatype, colorkey=None):


Default arguments must be at the end of the argument list, but before *args and **kwargs.


Default parameter MUST be the last variable. So change to:

def load_content(name, datatype, colorkey=None):
...
0

精彩评论

暂无评论...
验证码 换一张
取 消