Discuss / Python / fighting

fighting

Topic source

def product(x, *y):

    for i in y:

        x=x*i

    return x

请问第一个product(5)为什么等于5呢,y=()不是0个参数等于0吗

fly-hj

#3 Created at ... [Delete] [Delete and Lock User]

问1:乘积式子中只有因式5,所以product(5)等于5

问2:

fly-hj

#4 Created at ... [Delete] [Delete and Lock User]

sorry,刚刚回复错了。感觉应该是当y()参数为空时,for循环语句直接就被跳过了,然后直接执行return x(x为5)


  • 1

Reply