Python中int()函数的用法浅析

作者:苌同学 时间:2022-08-18 09:45:12 

int()是Python的一个内部函数 

Python系统帮助里面是这么说的


>>> help(int)
Help on class int in module __builtin__:
class int(object)
| int(x[, base]) -> integer
|  
| Convert a string or number to an integer, if possible. A floating point
| argument will be truncated towards zero (this does not include a string
| representation of a floating point number!) When converting a string, use
| the optional base. It is an error to supply a base when converting a
| non-string. If base is zero, the proper base is guessed based on the
| string content. If the argument is outside the integer range a
| long object will be returned instead.
>>> int(12.0)
12

int()函数可以将一个数转化为整数 


>>> int('12',16)
18  


这里有两个地方要注意:1)12要以字符串的形式进行输入,如果是带参数base的话


2)这里并不是将12转换为16进制的数,而是说12就是一个16进制的数,int()函数将其用十进制数表示,如下




>>> int('0xa',16)
10
>>> int('10',8)
8

总结

以上所述是小编给大家介绍Python中int()函数的用法浅析网站的支持!

来源:http://blog.csdn.net/changzhi1990/article/details/23825919

标签:python,int(),函数
0
投稿

猜你喜欢

  • 正则 global 属性介绍

    2008-03-18 20:50:00
  • 如何从SQL数据库中调用图片?

    2009-11-15 19:59:00
  • 如何判断js脚本加载完成

    2008-11-04 13:53:00
  • python使用matplotlib模块绘制多条折线图、散点图

    2021-07-28 06:41:20
  • python变量赋值方法(可变与不可变)

    2021-02-14 08:51:55
  • 如何解决MySQL的客户端不支持鉴定协议

    2008-11-27 17:10:00
  • Go标准容器之Ring的使用说明

    2023-09-21 02:18:14
  • php比较两个指定的日期的实例讲解

    2023-06-13 12:11:29
  • Python asyncio异步编程常见问题小结

    2023-10-04 23:13:56
  • 如何使用表格来储存数据库的记录?

    2010-05-16 15:14:00
  • python代码实现猜拳小游戏

    2023-10-16 19:00:46
  • 网站中文字的视觉设计

    2008-04-16 13:35:00
  • 如何取得刚添加的记录自动增加的ID?

    2010-01-18 20:55:00
  • 在ASP中使用SQL语句之11:记录统计

    2007-08-11 13:27:00
  • 天极产品设计流程

    2007-10-11 18:47:00
  • Python操作sqlite3快速、安全插入数据(防注入)的实例

    2022-04-22 16:38:14
  • python虚拟环境的安装和配置(virtualenv,virtualenvwrapper)

    2021-05-13 17:40:35
  • javascript修正12个浏览器兼容问题[译]

    2009-04-23 12:19:00
  • 实现文字放大效果Javascript源码

    2010-03-17 20:46:00
  • 网马解密大讲堂——网马解密中级篇(Eval篇)

    2009-09-16 16:04:00
  • asp之家 网络编程 m.aspxhome.com