字符串列表元组字典集合对比

Posted WXiujie123456

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了字符串列表元组字典集合对比相关的知识,希望对你有一定的参考价值。

我整理了一下这几种数据结构的特点,做了一下简单整理 (*^▽^*)

 所属数据结构是否可以更改是否可切片内建函数特有类型函数内建函数特性
字符串‘’序列len() max() min() enumerate() zip()input() str() unicode() chr() ord()大小写转化:lower() upper() swapcase()  title() capitalize()字符串不变性
去空格和特殊符号:strip()  strip(str1) lstrip() rstrip()
字符串对齐,填充:ljust(width) rjust(width)  center(width) zfill(width)
字符串搜索、统计功能:find(string,beg=0,end=len(str))  index(string,beg=0,end=len(str))  rfind(string,beg=0,end=len(str))  count(string,beg=0,end=len(str))  index(string,beg=0,end=len(str))  rindex(string,beg=0,end=len(str))
字符串检测函数:isalnum()  isalpha()  isdigit()  isspace()  islower() istitle() startswith(prefix[,start[,end]]) endswith(suffix[,start[,end]])  replace(str1,str2,num=str.count(str1))   split(str1=”“,num=str.count(str1))            rsplit(str1=”“,num=str.count(str1)) splitlines(num=str.count(“\\n”’))
字符串接连:str.join(seq)
列表[]序列len() max() min() sorted() reversed() enumerate() zip() sum() list()range()append(x) extend(iterable) insert(i, x) remove(x) pop([i]) clear() index(x[, start[, end]]) count(x) sort(key=None, reverse=False) reverse() copy() 容器和可变,灵活
元组()序列len() max() min() sorted() reversed() enumerate() zip() sum()tuple()range()无(因为不可变)不可变性
字典{}映射type()str() sorted(iterable,key,reverse)dict() len() hash()类型转换 dict()和fromkeys() 清空clear() 得到一个键对应的值 get(key)  弹出给定键的值pop()   检查字典中是否存在某键setdefault(key,default)  字典连接update() 复制字典 copy()键值对视图 items() 键视图 keys()值视图 values()  不允许一个键对应多个值 键必须是可哈希的
集合 set和frozenset映射set可改 frozenset不可改type()len() set()和 frozenset()对于所有集合的方法:issubset() issuperset () union intersection difference symmetric_difference copy   disdisjoint  仅适用于可变集合:update intersection_update symmetric_difference_update add  remove  discard  pop 具有唯一性的可哈希对象所组成的无序多项集

更多Python框架梳理,请参考: 【Python学习】Python最全总结

 有问题请下方评论,转载请注明出处,并附有原文链接,谢谢!如有侵权,请及时联系。

以上是关于字符串列表元组字典集合对比的主要内容,如果未能解决你的问题,请参考以下文章

Python列表,元组,字典,集合的比较总结【表格对比】

python--列表字典元组集合对比

python数据类型——列表元组字典集合

小菜鸡进阶之路_Second week之元组列表集合字典对比.

py3 字符串 字典 列表 元组 集合

Python 基础入门笔记———— 字符串列表元组集合字典