python - can lambda have more than one return

前端 未结 4 498
忘了有多久
忘了有多久 2021-02-05 02:22

I know lambda doesn\'t have a return expression. Normally

def one_return(a):
    #logic is here
    c = a + 1
    return c

can be written:

4条回答
  •  孤街浪徒
    2021-02-05 02:54

    Print the table of 2 and 3 with a single range iteration.

    >>> list(map(lambda n: n*2, range(1,11)))
    [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
    
    
    >>> list(map(lambda n: (n*2, n*3) , range(1,11)))
    [(2, 3), (4, 6), (6, 9), (8, 12), (10, 15), (12, 18), (14, 21), (16, 24), (18, 27), (20, 30)]
    

提交回复
热议问题