Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/281.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/153.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 IDE冻结错误,关于函数的问题_Python_Python 3.x_Algorithm_Sum - Fatal编程技术网

Python IDE冻结错误,关于函数的问题

Python IDE冻结错误,关于函数的问题,python,python-3.x,algorithm,sum,Python,Python 3.x,Algorithm,Sum,为什么每次我搬家, obj/=10。在第8行,当我运行此代码时,IDE冻结 def print_sum(obj): s = 0 if isinstance(obj, int): while obj: s += obj % 10 obj //= 10 print('Sum of digits:', s) print_sum(12345) 我能知道obj/=10的确切用途吗? 你能解释一

为什么每次我搬家, obj/=10。在第8行,当我运行此代码时,IDE冻结

def print_sum(obj):

    s = 0

    if isinstance(obj, int):
        while obj:
            s += obj % 10
            obj //= 10 
        print('Sum of digits:', s)

   
print_sum(12345)
我能知道obj/=10的确切用途吗?
你能解释一下这个函数会发生什么吗?

因为如果不改变obj,你就会陷入无限循环。
obj//=10
整数除以obj,直到它为0,循环结束。

obj=obj//10
代码冻结,因为您不更新
obj
,因此不退出while