python中int函数

Python int()函数 (Python int() function)

int() function is used to convert a string (that should contain a number/integer), number (integer, float) into an integer value.

int()函数用于将字符串(应包含数字/整数),数字(整数,浮点数)转换为整数值。

Syntax:

句法:

    int(value, [base=10])

Parameter:

参数:

  • value – source value (string, number(integer/float)) to be converted in an integer value.

    value –要转换为整数值的源值(字符串,数字(整数/浮点数))。

  • base – it’s an optional parameter with default 10, it is used to define the base of source value, for example: if source string contains a binary value then we need to use base 2 to convert it into an integer.

    base –这是一个可选参数,默认值为10,用于定义源值的基数,例如:如果源字符串包含二进制值,则需要使用基数2将其转换为整数。

Return value: int – returns an integer value.

返回值: int –返回一个整数值。

Example:

例:

    Input:
a = "1001"
print(int(a))
Output:
1001
Input:
a = 10.23
print(int(a))
Output:
10
Input:
a = "1110111"
print(int(a,2))
Output:
119

Python code to convert values to an integer

Python代码将值转换为整数

# python code to demonstrate example
# of int() function
a = 10.20
b = "1001"
c = "000"
print("a: ", a)
print("int(a): ", int(a))
print("b: ", b)
print("int(b): ", int(b))
print("c: ", c)
print("int(c): ", int(c))

Output

输出量

a:  10.2
int(a):  10
b:  1001
int(b):  1001
c:  000
int(c):  0

Python code to convert different numbers systems (binary, octal and hexadecimal) to integer value (decimal)

Python代码可将不同的数字系统(二进制,八进制和十六进制)转换为整数值(十进制)

# python code to demonstrate example
# of int() function
a = "10101010"
print("a: ", int(a,2))
a = "1234567"
print("a: ", int(a,8))
a = "5ABC12"
print("a: ", int(a,16))

Output

输出量

a:  170
a:  342391
a:  5946386

翻译自: https://www.includehelp.com/python/int-function-with-example.aspx

python中int函数

python中int函数_int()函数以及Python中的示例相关推荐

  1. python中int是什么的缩写_python中int是什么类型

    python中的基本数据类型 1:虽然python中的变量不需要声明,但使用时必须赋值 整形变量 浮点型变量 字符型 2:可以一个给多个变量赋值,也可以多个给多个变量赋值 3:python3中有6个标 ...

  2. python中int input_两分钟了解python中的input函数

    两分钟了解python中的input函数 input函数在python中是一个内建函数,其从标准输入中读入一个字符串,并自动忽略换行符.下面我们就来看看input函数的具体用法吧. #函数inputm ...

  3. python中int表示的数据类型是_python中的基本数据类型之 int bool str

    一.基本数据类型 1. int  ==>  整数.主要用来进行数学运算. 2.str  ==>  字符串.可以保存少量的数据,并进行相应的操作. 3.bool  =>  布尔值.判断 ...

  4. python中int和eval的区别_python中eval与int的区别浅析

    python中eval和int的区别是什么?下面给大家介绍一下: 1.eval()函数 eval()能够以Python表达式的方式解析并执行字符串,并将返回结果输出.eval()函数将去掉字符串的两个 ...

  5. python中int和input的区别_python中input()与raw_input()的区别分析

    使用input和raw_input都可以读取控制台的输入,但是input和raw_input在处理数字时是有区别的 纯数字输入 当输入为纯数字时 input返回的是数值类型,如int,float ra ...

  6. python中int占几个字节_Python中的整型占多少个字节?

    说到计算机中的整型,相信很多人都会联想到32位整型(或者int),是程序员日常生活中用的最多的一种类型.32位整型顾名思义,占用32个位也就是4个字节,取值范围−2,147,483,648~ 2,14 ...

  7. python中int占几个字节_Python中int占几个字节

    Python中int占几个字节 以python3版本为例说明, int 类型在python中是动态长度的.因为python3中int类型是长整型,理论支持无限大的数字,但它的结构其实也很简单, 在 l ...

  8. VB中INT和FIX函数的区别

    Int.Fix 函数 返回数字的整数部分. Int(number) Fix(number) number 参数可以是任意有效的数值表达式.如果 number 参数包含 Null,则返回 Null. 说 ...

  9. 数据库中int类型存在空数据开发过程中model和dal层处理方法

    model层 public Int32? IsFullAttendance { get; set; } dal层  if (dr["IsFullAttendance"] + &qu ...

  10. python中split的用法取第二个分片_python中split()函数的用法

    函数:split() Python中有split()和os.path.split()两个函数,具体作用如下: split():拆分字符串.通过指定分隔符对字符串进行切片,并返回分割后的字符串列表(li ...

最新文章

  1. 【leetcode】二叉树与经典问题
  2. ReactNative环境配置的坑
  3. 林正刚本地化中摸索前进 称中国未来无可比拟
  4. [Unity 游戏设计的元素]
  5. 怎样创建两个菜单JAVA_java – 如何创建一个菜单的JButton?
  6. 一加6html查看程序,一加6T评测:极速屏下指纹,解锁你想要的轻快顺滑
  7. 刀剑神域服务器维护到什么时候,刀剑神域黑衣剑士王牌维护结束时间 服务器维护进不去怎么办...
  8. Unity插件学习记录 -- SW Actions
  9. 计算机发展的新技术,计算机新技术发展的有关论文
  10. RSA加密算法中的数学原理
  11. 算法总结与学习心得体会
  12. 数学基础之列联表分析2——独立性检验(卡方检验)
  13. 戴德金--连续性和无理数--我自己做的中文翻译第1页
  14. ribbon实现负载均衡
  15. openjudge 1.4.3 奇偶数判断
  16. Scrapy爬取贝壳网并存入csv
  17. 能够PING通同网段的节点, 但却PING不通其他网段的所有节点的最可能的原因是
  18. 史上最详细的小程序测试用例模板,以后再也不怕测试用例不会写了
  19. 华为OD面试——机试算法
  20. C#为窗体控件设置透明色问题

热门文章

  1. HTML简介及转义字符大全
  2. 原子操作、锁、同步实现原理
  3. ZigBee组网流程
  4. html语言闪烁特效代码,css3 实现文字闪烁效果的三种方式示例代码
  5. ROS之velodyne
  6. 商业智能BI全解析,探寻BI本质与发展趋势
  7. Linux内核常见分配函数
  8. web前端学习基础教程,简单的图片旋转木马自动轮播js代码
  9. 图片预览(原生js实现)
  10. 【基础入门题031】三色球问题