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
Source by www.programiz.com #
 
PREVIOUS NEXT
Tagged: #python #digits #number
ADD COMMENT
Topic
Name
8+8 =