How to check last digit of number

前端 未结 8 1892
情歌与酒
情歌与酒 2020-12-06 04:21

Is there a way to get the last digit of a number. I am trying to find variables that end with \"1\" like 1,11,21,31,41,etc..

If I use a text variable I can simply pu

相关标签:
8条回答
  • 2020-12-06 05:02

    By using iteration and the in built function of 'digit' the number is treated as binary and so it goes from backwards to forwards. Here is an example of a bit of code for you.

    for digit in binary:
        denary= denary*2 + int(digit)
    
    0 讨论(0)
  • 2020-12-06 05:03

    The simplest and most efficient way is to use the reminder :

    last_digit = orginal_number % 10
    
    0 讨论(0)
提交回复
热议问题