本文介绍了语法错误:无效的语法我每次把一个数组作为参数的时间__init__的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,此方法:

 进口pygame的
进口一举成名类ContenedoresPorCapa():    高清__init __(个体经营,层[]):
        self.mapasCapas = LEN(self.mapas.capas)
        因为我在范围内(mapasCapas):
            返回层[I]


解决方案

您不需要 [] 参数列表:

 进口pygame的
进口一举成名类ContenedoresPorCapa:
    高清__init __(自我,层):
        self.mapasCapas = LEN(self.mapas.capas)
        因为我在范围内(mapasCapas):
            返回层[I]

另外,还要注意收益 __ ING值的init __ 类的方法(构造函数)是没有意义的(而且会产生运行时类型错误,为Aशwiniचhaudhary好心指出)。

另外,()在类的定义到底是多余的。

此外,这种循环只会重复一次,然后立即返回:

 为我的range(mapasCapas):
    返回层[I]

除非你描述你的目标是什么,这似乎是不可能给你提供任何进一步的指导(不是强烈推荐阅读像)。

For example, this method:

import pygame
import mapas

class ContenedoresPorCapa():

    def __init__(self, layers[]):
        self.mapasCapas = len(self.mapas.capas)
        for i in range(mapasCapas):
            return layers[i]
解决方案

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).

这篇关于语法错误:无效的语法我每次把一个数组作为参数的时间__init__的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 06:57