zoukankan      html  css  js  c++  java
  • python 字符串,列表,元祖,字典的常用方法

    1 字符串
    2 1.strip()  去除字符串两端的空白符
    3 2.split()   对字符串进行分割,默认按照空格分隔
    4 3.join()   字符串连接
    5 4.startwith(),endwith()  判断是否以xx开头或者结尾
    6 5.replace()  字符串替换
    7 6.find()  查找字符串,存在返回第一个索引,不存在返回-1
    1 列表
    2 1.count()  统计在列表中出现的个数
    3 2.append()  在列表末尾添加值
    4 3.pop()  删除一个对象,默认最后一个
    5 4.remove()  删除指定的第一个匹配项
    6 5.insert()  插入对象
    7 6.index()  获取索引
    1 元组
    2 1.count()  统计在元组中出现的个数
    3 2.index()  获取索引
    1 字典
    2 1.keys()  获取所有的键
    3 2.pop()  删除指定的键的键值对
    4 3.popitem()  随机删除一个键值对
    5 4.update()  更新字典,参数为一个字典,如果键已存在,则更改,不存在则添加
    6 5.setdefault()  如果键存在,则返回键对应的值,如果不存在,设置该键为设置的默认值,然后返回该键对应的值
    7 6.get()  返回键对应的值
    8 7.fromkeys()  创建字典,第一个参数为可迭代对象,每个值变为字典的键,第二个参数为每个键的默认值
  • 相关阅读:
    Leetcode: Word Ladder II
    Leetcode: Triangle
    Leetcode: Best Time to Buy and Sell Stock II
    Leetcode: Best Time to Buy and Sell Stock
    Leetcode: Pascal's Triangle II
    Leetcode: Pascal's Triangle
    Leetcode: Path Sum II
    Leetcode: Convert Sorted Array to Binary Search Tree
    Leetcode: Merge Sorted Array
    Leetcode: Word Search
  • 原文地址:https://www.cnblogs.com/Yanss/p/13085135.html
Copyright © 2011-2022 走看看