w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Syntax error: invalid syntax every time I put an array as an argument to __init__

You don't need the [] in the parameter list:

import pygame
import mapas

class ContenedoresPorCapa:
    def __init__(self, layers):
        self.mapasCapas = len(self.mapas.capas)
        for i in range(mapasCapas):
            return layers[i]

Also, note that returning values from __init__ methods of classes (constructors) is meaningless (and will produce a runtime TypeError, as Aशwini चhaudhary kindly pointed out).

Also the () at the end of the class definition is redundant.

Furthermore, this for loop will only iterate once and then return immediately:

for i in range(mapasCapas):
    return layers[i]

Unless you describe what your goal is, it seems impossible to offer you any further guidance (other than strongly recommending to read something like http://learnpythonthehardway.org).

© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.