简体   繁体   中英

Why am I getting an invalid syntax

I am trying to set my init and when trying to set (x,y), I am getting an invalid Syntax error on the open parentheses on the coordinates.

I feel like this is going to be an obvious mistake but I've been looking at it too long and could use some fresh eyes...

def __init__(self, (x,y), size, color = (255,255,255)):
        self.x = x
        self.y = y
        self.size = size
        self.color = color
        self.width = width

Since x and y are elements of a tuple (if that's what you're trying to create) you don't need to assign individual element in parameters.

def __init__(self, coordinates, size, color = (255,255,255)):
        self.x = coordinates[0]
        self.y = coordinates[1]
        self.size = size
        self.color = color
        self.width = width

You have to write __init__(self, v , size, color = (255,255,255)) and pass every v as a list.

def __init__(self, v, size, color = (255,255,255)):
        self.x = v[0] #first coordinate of v
        self.y = v[1] #second coordinate of v
        self.size = size
        self.color = color
        self.width = width

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM