获取整数的最后三位数 [英] Get last three digits of an integer

查看:242
本文介绍了获取整数的最后三位数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望将一个整数,如23457689更改为689,12457245到245等。

I wish to change an integer such as 23457689 to 689, 12457245 to 245 etc.

我不要求数字舍入,也不希望有转换为String。

I do not require the numbers to be rounded and do not wish to have to convert to String.

如何在Python 2.7中完成这项工作?

Any ideas how this can be done in Python 2.7?

推荐答案

使用操作:

>>> x = 23457689
>>> x % 1000
689

mod (即 modulo )操作。

% is the mod (i.e. modulo) operation.

这篇关于获取整数的最后三位数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆