Learn about First Digit of Number using Built-in Function In Python in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.
Contents
First Digit of Number using Built-in Function In Python
# Python Program to get the first digit of number
# math module
import math
# input
num = int(input('Enter any Number: '))
# access first digit
digits = int(math.log10(num))
first_digit = int(num / pow(10, digits))
# printing first digit
print('The first digit of number:', first_digit)
Output:
Enter any Number: 34
The first digit of number: 3
Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.
Similar Code : Python Program to Get First Digit of a Number