Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

how to take first digit of number python

import math

def first_n_digits(num, n):
    return num // 10 ** (int(math.log(num, 10)) - n + 1)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #digit #number #python
ADD COMMENT
Topic
Name
8+1 =