Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

python get digits of number

# x: The int number
# n: Digit index
def digit_extraction_by_index(x, n):
    return (abs(x) // (10 ** n)) % 10

print(digit_extraction_by_index(123, 0)) # 3
print(digit_extraction_by_index(123, 1)) # 2
 
PREVIOUS NEXT
Tagged: #python #digits #number
ADD COMMENT
Topic
Name
6+3 =