how to take first digit of number python

Solutions on MaxInterview for how to take first digit of number python by the best coders in the world

showing results for - "how to take first digit of number python"
Lilie
18 Feb 2016
1>>> number = 1520
2>>> int(str(number)[:2])
315
4
Zeke
17 Mar 2017
1import math
2
3def first_n_digits(num, n):
4    return num // 10 ** (int(math.log(num, 10)) - n + 1)
5
queries leading to this page
python get first 3 digits of operationhow to take first 10 digit of string pythonpython get first digit of intget first digit of int pythonpython first number of inthow to get first numbers pythonhow to take first integer of an number in pythonhow to get first digit of a number pythonget first digit pythonhow to get first digit of a numberfirst digit of a number pythonget first digit of a float pythonpython get first digit of numberhow to get first digit of a number in pythonfirst digit of number pythonpython get first 3 digits of numberhow to find first digit in string python python get 1st digit from numberhow to get first number of a digit using log function in pythonpython first 5 digit of integerhow to get first and last digit from 4 digit number in pythonfirst digit accessing in int in pythonfirst digit of a number in pythonhow to get the first digit of a sentence in pythonhow to get first digit of a number in python modulushow to take the first digit of a number in pythonget first digit of lettetpythonpython int get first digitfind first digit of a number pythonget first digit of number pythonprint first digit of a number in pythonpython first 10 digitsdpython use first number of numberhow to get the first digit of a number in pythonpython number only first 4 numberhow to get first digit of integer pythonint how to take first 4 digits pythonhow to get the first digit of number in pythonhow to take first digit of number pythonhow to find the first digit of a number in pythonhow to take first digit of number python