본문 바로가기
programming/Python

[Python] 숫자를 역순으로 출력

by LO-OmJ 2021. 9. 19.

내가 아는 방법 1 - 반복문 이용

x = int(input())
res = 0
while x>0:
    t = x%10
    res = res*10+t
    x = x//10
print(res)

 

방법 2 - 문자열 이용

x = int(input())
print(int(str(x)[::-1]))

'programming > Python' 카테고리의 다른 글

[Python] for else 문  (0) 2021.04.22

댓글