Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 在python返回函数中返回多个值_Python 3.x - Fatal编程技术网

Python 3.x 在python返回函数中返回多个值

Python 3.x 在python返回函数中返回多个值,python-3.x,Python 3.x,我的函数打印列表中每个元素的索引,该索引在给定列表中被2除。我想知道是否有方法返回所有索引而不是打印 def printEvenIndex(referenceTuple): for i in referenceTuple: if i % 2 ==0: indexOfEvenIntegers = referenceTuple.index(i) print(indexOfEvenInt

我的函数打印列表中每个元素的索引,该索引在给定列表中被2除。我想知道是否有方法返回所有索引而不是打印

def printEvenIndex(referenceTuple):                     

    for i in referenceTuple:
        if i % 2 ==0:
            indexOfEvenIntegers = referenceTuple.index(i)
            print(indexOfEvenIntegers)
    return indexOfEvenIntegers 



referenceTuple = (6,5,3,4,1)
print(printEvenIndex(referenceTuple))
现在打印语句打印0,3,这是有效的。
但返回函数只返回3。有没有办法告诉返回函数返回每个可被2整除的元素?我想返回所有索引,而不是打印它。

只需创建一个列表并将索引附加到那里:

def readEvenIndexes(referenceTuple):  
    """ Named it readEventIndexes, as we are not printing anymore """                   
    indexes = []
    for index, i in enumerate(referenceTuple):
        if i % 2 ==0:
            indexes.append(index)

    return indexes 


referenceTuple = (6,5,3,4,1)
print(readEvenIndexes(referenceTuple))