python中几种数据类型常用的方法

  • 列表
    • 增加:append,insert,extend
    • 删除:remove,pop,clear
    • 修改:
    • 查询:index,count
  • 元组
    • 查询:index,count
    • *:解包操作
  • 集合
    • 增加:add
    • 删除:pop(第一个),clear,remove
    • 交集:&
    • 并集:|
    • 差集:set1-set2
    • 对称差集:并集-交集
  • 字典
    • 增加:字典['键'] = 值
    • 删除:pop,popitem,clear
    • 修改:update(dict)
    • 查询:get,keys,items,values,setdefault:有对应的键则返回对应的值,没有则返回默认给定的值
  • 字符串:
    • 状态获取:islower,isupper,isdigit,isalpha,isalnum,istitle,startswith,endswith
    • 状态转换:lower,casefold,upper,swapcase,title(单词首字母大写),capitalize(字符串首字母大写)
    • 格式转换:strip(去掉左右两边参数字符串中的字符),ljust,rjust,center,zfill(左侧补零)
    • 拆分:partition,rpartiton,spilt,splitlines
    • 连接:join,+
    • 查询:index,find,count
    • 替换操作:replace,expandtabs
    • 基本操作:索引取值,len,max,min,in,not in

 

原文地址:https://www.cnblogs.com/ycg-blog/p/12178185.html