数据类型

可变数据类型

  set(集合)

  

所有方法
__and__', '__class__', '__contains__', '__delattr__', '__dir__',
'__doc__', '__eq__', '__format__', '__ge__', '__getattribute__',
'__gt__', '__hash__', '__iand__', '__init__', '__init_subclass__',
'__ior__', '__isub__', '__iter__', '__ixor__', '__le__', '__len__',
'__lt__', '__ne__', '__new__', '__or__', '__rand__', '__reduce__',
'__reduce_ex__', '__repr__', '__ror__', '__rsub__', '__rxor__',
'__setattr__', '__sizeof__', '__str__', '__sub__', '__subclasshook__',
'__xor__',




# 增删改查
setli1 = {1,2,3,4,5,6}
setli2 = {1,2,3,4,5,7}
xx = {5,6,7,8}
#
setli1.add(5)  # 增加单个
setli1.update(xx)  # 迭代添加
# 删除
setli1.pop() # 随机删除一个数值,如果为空则触发 KeyError 错误
setli1.remove(2) # 指定删除某个内容,如果没有则触发keyError 错误
setli1.clear()  # 清空
setli1.discard(9) # 删除指定内容,如果有就删除,没有就什么也不做
#
pass
#
pass
# 其他

# copy:浅拷贝
setl = setli1.copy()


#  差集
# difference:取两个集合的差集.这里是看setli2中有,而setli1没有的东西
xx = setli2.difference(setli1)

# difference_update:这里的的setli2变成了5
setli2.difference_update(setli1)

# 交集
# intersection:返回两个集合的交集
xx = setli1.intersection(setli2)

# intersection_update:返回两个集合的交集,setli1变成两个集合的交集
setli1.intersection_update(setli2)

# isdisjoint:两个集合的内容全部不相同,就返回True,只要有相同就返回False
xx = setli1.isdisjoint(setli2)


# issubset:查看setli2是否是setli1的子集,如果在返回True,如果不在返回False:报告另一个集合是否包含此集合
xx = setli2.issubset(setli1)

# issuperset 报告此集合是否包含另一个集合,求setli1是否是setli2的超集
xx = setli1.issuperset(setli2)

# 求反交集
#  symmetric_difference  返回两个集合的对称差作为一个新集合。1里面有而2里面没有,2里面有,而1里面没有的
xx = setli2.symmetric_difference(setli1)

# setli1这会变成了两个集合的差集
setli1.symmetric_difference_update(setli2)

# 并集
# union:返回两个集合或多个集合所有内容,里面的内容不会重复
xx = setli1.union(setli2)

  list(列表)

全部方法
'__add__', '__class__', '__contains__', '__delattr__', '__delitem__',
'__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__',
'__getitem__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__',
'__init_subclass__', '__iter__', '__le__', '__len__', '__lt__',
'__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__',
'__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__',
'__sizeof__', '__str__', '__subclasshook__', '', ', '',



list1 = [1,2,3,4,5,6,7,8,9,9]
list2 = [11,12,4,5,7]
#
list1.append(10) # 向最后添加
list1.insert(1,5) # 指定位置插入内容
list1.extend(list2) # 将list2迭代插入到list1中
#
xx = list1.pop(1) #可以指定位置删除,返回值是删除的那一个,默认删除最后一个
list1.remove(10) # 指定删除内容,没有报错ValueError
list1.clear() # 清空列表
# 改:指定索引修改
# 查:指定查看内容

# 其他操作
xx = list1.copy() # 浅拷贝
xx = list1.count(9) # 查看9在list1列表中有的个数
xx = list1.index(5) # 查看索引
list1.reverse() # 将列表翻转,没有返回值
list1.sort(reverse=True) # 排序,reverse=True反序

  dict(字典)

全部方法

'__class__', '__contains__', '__delattr__', '__delitem__',
'__dir__', '__doc__', '__eq__', '__format__', '__ge__',
'__getattribute__', '__getitem__', '__gt__', '__hash__',
'__init__', '__init_subclass__', '__iter__', '__le__',
'__len__', '__lt__', '__ne__', '__new__', '__reduce__',
'__reduce_ex__', '__repr__', '__setattr__', '__setitem__',
'__sizeof__', '__str__', '__subclasshook__',


#   dict(字典)
dic = {'1':1,"2":[1,2,3],"3":(1,2,3),'4':{2,3,6,8},"5":{'k1':"v1"}}
#
dic['xx']=111 第一种
dic.setdefault('xxx',111) 如果没有就添加,有就过

#
dic.pop('5')  # 删除指定内容
xx = dic.popitem() # 删除最后一个
dic.clear() # 清空字典

#
dic['key'] = 'Value'
dic.update({'9':111}) # 有就修改,没有就添加
#
dic.get('1') # 查看指定内容

# 其他操作
xx = dic.items() # 返回一个dict_items类型的列表,里面是一个个的元祖
xx = dic.keys()  # 返回这个字典所有的key
xx = dic.values()  # 返回这个字典所有的value
xx = dic.fromkeys([1,2,3,4],'1z2') # 返回一个字典,第一个参数必须是一个可迭代对象,后面是value
dic.copy()  # 浅拷贝

不可变数据类型

  int(整数)

所有方法
'__abs__', '__add__', '__and__',
'__bool__', '__ceil__', '__class__',
'__delattr__', '__dir__', '__divmod__',
'__doc__', '__eq__', '__float__',
'__floor__', '__floordiv__', '__format__',
'__ge__', '__getattribute__', '__getnewargs__', 
'__gt__', '__hash__', '__index__', '__init__', 
'__init_subclass__', '__int__', '__invert__', 
'__le__', '__lshift__', '__lt__', '__mod__', 
'__mul__', '__ne__', '__neg__', '__new__', 
'__or__', '__pos__', '__pow__', '__radd__',
'__rand__', '__rdivmod__', '__reduce__', 
'__reduce_ex__', '__repr__', '__rfloordiv__',
'__rlshift__', '__rmod__', '__rmul__', 
'__ror__', '__round__', '__rpow__', '__rrshift__', 
'__rshift__', '__rsub__', '__rtruediv__',
'__rxor__', '__setattr__', '__sizeof__', 
'__str__', '__sub__', '__subclasshook__', 
'__truediv__', '__trunc__', '__xor__', 
'bit_length', 'conjugate', 'denominator',
'from_bytes', 'imag', 'numerator', 'real', 'to_bytes'
i = 12
i.bit_length() # 返回一个数字的bit类型的长度

  float(浮点型)

__abs__', '__add__', '__bool__', '__class__',
'__delattr__', '__dir__', '__divmod__',
'__doc__', '__eq__', '__float__',
'__floordiv__', '__format__', '__ge__',
'__getattribute__', '__getformat__', 
'__getnewargs__', '__gt__', '__hash__', 
'__init__', '__init_subclass__', '__int__',
'__le__', '__lt__', '__mod__', '__mul__',
'__ne__', '__neg__', '__new__', '__pos__',
'__pow__', '__radd__', '__rdivmod__',
'__reduce__', '__reduce_ex__', '__repr__',
'__rfloordiv__', '__rmod__', '__rmul__',
'__round__', '__rpow__', '__rsub__',
'__rtruediv__', '__setattr__', '__setformat__',
'__sizeof__', '__str__', '__sub__', 
'__subclasshook__', '__truediv__', 
'__trunc__', '', 'conjugate',
'fromhex', '', 'imag', 'is_integer', 'real'


fl = 1.1
print(fl.hex()) # 返回这个这个浮点数的十六进制
print(fl.as_integer_ratio()) # 返回一对整数,其值正好是比值
print(fl.fromhex('1.9'))  # 不知
print(fl.is_integer()) # 如果浮点数是整数,就返回True

  str(字符串)

'__add__', '__class__', '__contains__',
'__delattr__', '__dir__', '__doc__',
'__eq__', '__format__', '__ge__',
'__getattribute__', '__getitem__', 
'__getnewargs__', '__gt__', '__hash__',
'__init__', '__init_subclass__',
'__iter__', '__le__', '__len__', '__lt__', 
'__mod__', '__mul__', '__ne__', '__new__',
'__reduce__', '__reduce_ex__', '__repr__',
'__rmod__', '__rmul__', '__setattr__',
'__sizeof__', '__str__', '__subclasshook__',

st = 'abcDE {}F'
# 其他
# print(st.zfill(9)) # 指定长度,当字符串不满足该长度的时候,用0填充
# print(st.splitlines()) # 返回一个列表在\n处进行分割
# print(st.rjust(9)) # 给出指定长度,不满足长度用空格填充
# print(st.encode())  # 将字符串装换为bytes类型
# print(st.format('11')) # 对{}进行替换,格式化输出
# print(st.isdecimal()) # 如果字符串只有十进制字符串,就返回True,没有返回False
# print(st.islower()) # 如果都是小写,就返回True
# print(st.isspace())  # 如果字符全是空格返回True
# print(st.istitle()) # 如果是一个带标题的字符串,返回True
# print(st.isupper()) # 如果字符全是大写就返回True
# print(st.join([]))  # 将一个可迭代对象变成一个字符串
# print(st.ljust(20),'xxxxx')  # 设定一个长度,不够用空格补充,还可以加一个追加到最后的值

# print(st.translate({'9':"9","1":"4"})) # 不知,官方解释:这是一个翻译表
# print(st.maketrans()) # 不知如何使用
# print(st.isprintable())  # 不知如何使用
# print(st.isidentifier()) # 不知如何使用
# print(st.format_map()) # 不知如何使用


# print(st.capitalize()) # 首字母大写,其他字母小写
# print(st.title()) # 特殊字符后首字母大写
# print(st.upper()) # 全部转换为大写
# print(st.lower()) # 全部转换为小写
# print(st.casefold()) # 全部转换为小写
# print(st.swapcase())  # 大小写互换

# print(st.center(20,'*'))  # 参数1:是指定长度,参数2是指定填充内容
# print(st.expandtabs(),11) # 默认将一个table变成8个空格
# print(st.strip('a')) # 去除两边指定内容,默认空格
# st.lstrip()  #去除左边的空格或指定内容
# st.rstrip()  #去除右边的空格或指定内容

# 字符串替换和切割
# print(st.replace('a','zsss',1))  # 指定替换,也可以指定次数
# print(st.split()) # 将内容切割,默认是空格,不限空格大小 左边
# print(st.rsplit()) # 将内容切割,默认是空格,不限空格大小 右边

# print(st.partition(' '))  # 指定内容进行切割, ('abc', ' ', '   DEF') 左边
# print(st.rpartition(' '))  # 指定内容进行切割, ('abc', ' ', '   DEF') 右边


# 字符串的查找
# print(st.count('',1,5)) # 返回参数在字符串存在的个数,也可以指定位置
# print(st.find('a')) # 返回指定字符串的下标,没有返回-1 左边
# print(st.rfind('a')) #  右边
# print(st.index('9')) # 返回指定字符串的下标,没有报错ValueError 左边
# print(st.index('9')) # 返回指定字符串的下标,没有报错ValueError 右边

# 字符串的条件判断
# print(st.startswith('a')) 判断字符串是否以xxx开头
# print(st.endswith('a')) 判断字符串是否以xxx结尾
# print(st.isalnum()) #判断是否由数字和字母组成
# print(st.isdigit()) # 判断是否由数字组成
# print(st.isnumeric()) # 判断是否以数字组成(支持全部数字,包括中文数字)
# print(st.isalpha()) # 判断是否全是字母

  tuple(元祖)

__add__', '__class__', '__contains__',
'__delattr__', '__dir__', '__doc__',
'__eq__', '__format__', '__ge__',
'__getattribute__', '__getitem__',
'__getnewargs__', '__gt__',
'__hash__', '__init__', 
'__init_subclass__', '__iter__', 
'__le__', '__len__', '__lt__', '__mul__', 
'__ne__', '__new__', '__reduce__', 
'__reduce_ex__', '__repr__', '__rmul__',
'__setattr__', '__sizeof__', '__str__',
'__subclasshook__', 'count', 'index']


count:查看内容个数
index:查看下标

 

  bool(布尔值)

__abs__', '__add__', '__and__', '__bool__',
'__ceil__', '__class__', '__delattr__',
'__dir__', '__divmod__', '__doc__',
'__eq__', '__float__', '__floor__',
'__floordiv__', '__format__', '__ge__',
'__getattribute__', '__getnewargs__',
'__gt__', '__hash__', '__index__', '__init__',
'__init_subclass__', '__int__', '__invert__',
'__le__', '__lshift__', '__lt__', '__mod__', 
'__mul__', '__ne__', '__neg__', '__new__', 
'__or__', '__pos__', '__pow__', '__radd__',
'__rand__', '__rdivmod__', '__reduce__',
'__reduce_ex__', '__repr__', '__rfloordiv__',
'__rlshift__', '__rmod__', '__rmul__', 
'__ror__', '__round__', '__rpow__', 
'__rrshift__', '__rshift__', '__rsub__', 
'__rtruediv__', '__rxor__', '__setattr__', 
'__sizeof__', '__str__', '__sub__', 
'__subclasshook__', '__truediv__', '__trunc__',
'__xor__', 'bit_length', 'conjugate', 
'denominator', 'from_bytes', 'imag', 
'numerator', 'real', 'to_bytes

print(False.bit_length())  # True返回1,False返回0

 

posted @ 2018-11-08 14:40  春秋羽  阅读(154)  评论(0编辑  收藏  举报