Python : What is the purpose of a colon in an if statement?

后端 未结 4 1808
暗喜
暗喜 2021-01-29 17:21

I have this piece of python code below.

def m(list):
    v = list[0]
    for e in list:
        if v < e:
            v = e
        return v

values = [[3, 4,         


        
4条回答
  •  孤独总比滥情好
    2021-01-29 17:24

    if v < e: v = e
    

    can be read: "If v is less than e, make v the value of e."

    As above you should put a new line to make it read easier:

    if v < e:
        v = e
    

提交回复
热议问题