您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

python数据类型之内置方法

5b51 2022/1/14 8:24:24 python 字数 1403 阅读 677 来源 www.jb51.cc/python

python有六大数据类型,分别为整型、字符串、列表、字典、元祖和集合,这些基本数据类型都内置了很多方法,接下来一一探寻。 python中整型有两种:int和float 1 int 使用dir函数查看

概述

python有六大数据类型,分别为整型、字符串、列表、字典、元祖和集合,这些基本数据类型都内置了很多方法,接下来一一探寻。

python中整型有两种:int和float

使用dir函数查看有多少内置方法

<span style="color: #008000">#<span style="color: #008000"> python 2.x
<span style="color: #000000">dir(int)
<span style="color: #008000">#<span style="color: #008000"> ['abs','cmp','coerce','div','float','hash','hex','int','long','neg','nonzero','oct','pos','rdiv','repr','rlshift','rsub','setattr','xor','denominator','real']

因为是整型类型,所以有加减乘除、取绝对值的方法,像__abs__是取绝对值,__add__是加法等,其中重要的几个方法是:bit_length、conjugate、from_bytes、imag、numerator、real、to_bytes


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶