Python 利用while语句进行整数倒置

Python中怎样利用取余整除及while语句将任意整数倒置?

a=int(input())
b=0
while a:
    b=b*10+a%10
    a=a//10
print(b)

#整数取余
print(123%10)
#while任意整数倒置
class Solution:
    def reverse(self, x: int) -> int:

        res = 0
        if x == 0:
            return 0
        y = abs(x)
        while y != 0:
            res = res * 10 + y % 10
            y = y // 10
        if res > pow(2, 31) - 1 or res < pow(-2, 31):
            return 0
        return res if x > 0 else -res