Python - substr [英] Python - substr
本文介绍了Python - substr的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要能够获取数字的最后一位.
I need to be able to get the last digit of a number.
即,我需要从 12 返回 2.
i.e., I need 2 to be returned from: 12.
像这样在 PHP 中:$minute = substr(date('i'), -1)
但我在 Python 中需要这个.
Like this in PHP: $minute = substr(date('i'), -1)
but I need this in Python.
任何想法
推荐答案
last_digit = str(number)[-1]
这篇关于Python - substr的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文