在python中检查回文数时运算符//的含义是什么

What is the meaning of operator // when checking palindrome number in python

所以我得到了这段代码来检查一个数字是否是回文,它工作正常但我对 while 循环中某些运算符的用法有疑问。在原始变量和整数10之间使用的运算符//。它对原始 p 值做了什么,是除法还是?这是我正在使用的代码

def test_palindrome(p):
    o=p#store the original value of p in some variable
    reversed_number=0#declare reversed_number and init to zero
    while(p>0):
        rem=p%10#Get the remainder of argument and ten
        reversed_number=reversed_number*10+rem
        p=p//10#This is the operator whose function is in question, am not sure if its dividing
    if(reversed_number==o):#do comparison with original input and return 
        print(f"{o} is a palindrome")
    else:
        print(f"{o} is not a palindrome")
test_palindrome(number)

//表示楼层划分。楼层除法将始终为您提供结果的整数楼层

您的程序首先会检查 p>0。让我们说 p = 1001.

1001 // 10 = 1001001/10 = 100.1

如果您使用 p/10 而不是 p//10p 永远不会小于 0。小数:0.1(示例)将始终存在。因此,条件 p>0 将始终为真,从而破坏您的程序。


如评论中所述,this post 可能有用。