[python] Built-in Types

Built-in Types

    1. Boolean

假值:None, False, 零(0,0.0,0j),空值('',(),[],{})

真值:除去假的,剩下的就是真的了,这是去伪存真

科学中很多事情都是除去假的,剩下的就是真的了,但是在现实生活中如果将这么一套非真就假,非假就真的想法拿来运用,很明显会产生各种的不如意.而现实中应该将没有真假,没有对错,有的仅仅是让内心存有一份安宁

产生布尔值的操作

      • or(x or y), and(x and y), not(not x)
      • &lt,&lt=,&gt,&gt=,=,!=,is,is not
    1. Numeric Types

integer

      • int.bit_length()

(-27).bit_length()

      • int.to_bytes(length,byteorder,*,signed=False)

num = 1024; num.to_bytes(10,byteorder='big'); num.to_bytes(10,byteorder='little')

      • int.from_bytes(length,byteorder,*,signed=False

float

      • float.as_integer_ratio()
      • float.is_integer
      • float.hex();float.fromhex() 与十六进制之间的转换
    1. Sequence Types

序列型的通用操作
可变序列型(list,string)的通用操作

      • list

list 是能够被更改,list的构造方式有:1. [], 2. [a],[a,b,c], 3. [x for x in iterable] 4. list() or list(iterable).
list的另一个操作:排序,sort(*,key=None,reverse=None)

          • tuple

tuple 是不能够更改的序列型,能够实现所有通用操作

          • string(摘录)

str.center(width[,fillchar])


可以用来划分不同的区域:
区域1
****str.center****
区域2

str.expandtabs([tabsize]): 用一定数量的空格取代序列中的tab
str.find(sub[,start[,end]])
str.ljust(width[,fillchar])
str.lstrip([chars])

      1. Mapping Types (dict)
        • del d[key]
        • iterms()
        • keys()
        • pop(key[,default])y
        • popitem()
        • values()

更多信息详见 python doc 4.built-in types 内置数据类型

posted @ 2013-06-10 11:02  grassofsky  阅读(272)  评论(0编辑  收藏  举报