前言计算机能处理各种类型的数据包括数值、文本不同的数据属于不同的数据类型支持不同的运算操作Python语言提供了丰富的内置数据类型。用于有效的处理各种类型的数据。在Python语言中一切皆为对象。每一个对象都属于某种数据类型的下的产物。一、数值数据类型1.整数类型(用于表示整数)整型对象支持关系运算、算术运算、位运算、内置函数,math模块等。与其他语言不同的是Python中的整数可以是任意长度(只受限于计算机内存)。整型对象是不可变对象。①整型对象直接赋值直接创建对象使用int()内置函数直接创建对象,还可以指定进制数不过被创建的对象要是一个符合数字格式的字符串。二进制位数②支持的运算符在Python3中有几处运算符比较特殊,接下来将会对特殊的运算符进行一一列举表达式结果说明5/41.25单除号会进行取小数5//41整除可以认为是强制除2**2**216具有右结合性,两个乘号代表指数,后面数值是指数2.布尔类型(用于表示布尔逻辑值)只包含两个值True、False①bool对象非零非空即True③支持的运算符运算符说明优先级not逻辑非操作数为True则结果为Falseand逻辑与两个操作数同为True结果才为Trueor逻辑或有一个操作数为True,则结果为True值得注意的是and与or操作数都有短路机制,如果通过第一个数可以判断出结果则就不会进行第二个数的判断。3.浮点类型浮点数是表示实数的数据类型,与其他计算机语言中的单、双精度类型对应。Python浮点类型的精度与系统相关。如图所示,浮点类型如果小数点左右两侧没有东西,就可以将0省略。Infinity对于Python而言代表无穷大。nan代表非数值。浮点数与整数一样,被Python中的math等包支持。4.复数类型(用于表示复数)复数具有实部与虚部是Python的内置数据类型之一用户可以创建complex类型的对象实例。如图所示,复数的数据类型为complex,包括实部与虚部,可以使用real获取其实部使用imag获取其虚部,使用conjugate获取其共轭复数。当然了复数与整型一样也支持算术运算,还被cmath包支持。二、序列数据类型序列数据类型表示若干有序数据。1.不可变序列名称关键字举例字符串str“Hello world”元组类型tuple(1,“3”),(1,)字节序列bytesb’abc’2.可变序列名称关键字举例列表类型list[“hello”,“world”]字节数组bytearray可以修改的字节数组三、集合数据类型集合数据类型表示若干数据的集合,数据项目没有顺序,且不重复。集(set)不可变集(frozenset)四、字典数据类型字典数据类型用于表示键值对的字典。Python内置的字典数据类型为dict五、NoneType、NotImplementedType、EllipsisType1.NoneTypeNoneType数据类型包含唯一值None,主要用于表示空值,如没有返回值的函数的结果2.NotImplementedTypeNotImplementedType数据类型包含唯一值NotImplemented。在进行数值运算和比较运算的时候如果对象不支持则可能返回这个值。3.EllipsisTypeEllipsisType数据类型包含唯一值Ellipsis表示省略字符串符号...六、其他数据类型对于Python而言一切皆对象,但是每一个对象都有一个数据类型模块、类、对象、函数都属于某种数据类型。Python解释器包含内置类型例如代码对象、框架对象、跟踪对象、切片对象、静态方法对象、类方法对象。总结本次主要讲述了Python内置数据类型中的数值数据类型,字符串、元组等数据类型会分期进行介绍。https://my.oschina.net/u/7213639/blog/19725313https://my.oschina.net/u/3101035/blog/19725312https://my.oschina.net/u/4570288/blog/19725311https://my.oschina.net/u/4066430/blog/19725310https://my.oschina.net/u/7213639/blog/19725309https://my.oschina.net/u/4570288/blog/19725308https://my.oschina.net/u/3101035/blog/19725307https://my.oschina.net/u/4066430/blog/19725306https://my.oschina.net/u/4570288/blog/19725305https://my.oschina.net/u/7213639/blog/19725304https://my.oschina.net/u/4066430/blog/19725303https://my.oschina.net/u/3101035/blog/19725302https://my.oschina.net/u/4570288/blog/19725301https://my.oschina.net/u/7213639/blog/19725300https://my.oschina.net/u/4066430/blog/19725299https://my.oschina.net/u/3101035/blog/19725298https://my.oschina.net/u/4570288/blog/19725297https://my.oschina.net/u/4066430/blog/19725296https://my.oschina.net/u/3101035/blog/19725295https://my.oschina.net/u/7213639/blog/19725294https://my.oschina.net/u/4066430/blog/19725292https://my.oschina.net/u/3101035/blog/19725291https://my.oschina.net/u/7213639/blog/19725289https://my.oschina.net/u/4570288/blog/19725290https://my.oschina.net/u/4066430/blog/19725286https://my.oschina.net/u/3101035/blog/19725285https://my.oschina.net/u/7213639/blog/19725284https://my.oschina.net/u/4570288/blog/19725283https://my.oschina.net/u/4066430/blog/19725281https://my.oschina.net/u/4570288/blog/19725280https://my.oschina.net/u/3101035/blog/19725278https://my.oschina.net/u/7213639/blog/19725279https://my.oschina.net/u/4570288/blog/19725275https://my.oschina.net/u/4066430/blog/19725274https://my.oschina.net/u/3101035/blog/19725273https://my.oschina.net/u/7213639/blog/19725272https://my.oschina.net/u/4570288/blog/19725270https://my.oschina.net/u/4066430/blog/19725269https://my.oschina.net/u/3101035/blog/19725268https://my.oschina.net/u/7213639/blog/19725267https://my.oschina.net/u/3101035/blog/19725264https://my.oschina.net/u/4570288/blog/19725263https://my.oschina.net/u/4066430/blog/19725262https://my.oschina.net/u/7213639/blog/19725261https://my.oschina.net/u/3101035/blog/19725259https://my.oschina.net/u/4066430/blog/19725258https://my.oschina.net/u/4570288/blog/19725257https://my.oschina.net/u/7213639/blog/19725256https://my.oschina.net/u/4066430/blog/19725254https://my.oschina.net/u/7213639/blog/19725253https://my.oschina.net/u/4570288/blog/19725252https://my.oschina.net/u/3101035/blog/19725251
郑州网站建设
网页设计
企业官网