Learn about Python Program to Get First Digit of a Number in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.
Contents
Python Program to Get First Digit of a Number
# Program to get the first digit of number
# input from user
num = int(input('Enter any Number: '))
# accessing first digit
while (num >= 10):
num = num // 10
# printing first digit
print('The first digit of number:', num)
Output:
Enter any Number: 654
The first digit of number: 6
Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.
Similar Code : Program to Reverse a Negative Number in Python