Find first and last digits of a number | Python3 program to find first and last digits of a number ; Find the first digit ; Find total number of digits - 1 ; Find first digit ; Return first digit ; Find the last digit ; return the last digit ; Driver Code
import math NEW_LINE def firstDigit ( n ) : NEW_LINE INDENT digits = ( int ) ( math . log10 ( n ) ) NEW_LINE n = ( int ) ( n / pow ( 10 , digits ) ) NEW_LINE return n ; NEW_LINE DEDENT def lastDigit ( n ) : NEW_LINE INDENT return ( n % 10 ) NEW_LINE DEDENT n = 98562 ; NEW_LINE print ( firstDigit ( n ) , end = " ▁ " ) NEW_LINE print ( lastDigit ( n ) ) NEW_LINE