Skip to main content
 首页 » 编程设计

python之Python 的 a, b = b, a 是如何工作的

2025年05月04日13kenshinobiy

<分区>

我知道我的意愿看起来微不足道,但我无法弄清楚为什么“停止”不等于零,因为“开始”值已经被覆盖。但是当我从函数中模拟相同的场景时,它确实做到了覆盖它。我在这里遗漏了什么吗?

def interval(start, stop =None, step = 1 ): 
    'Imitates range() for step >0 ' 
    if stop is None: 
        start, stop = 0, start #since start is already 0, why isn't stop as well? 
        print start,stop , step 
    result = [] 
    i = start 
    while i< stop: 
        result.append(i) 
        i+=step  
    return result