zoukankan      html  css  js  c++  java
  • 字符串处理.<方法>()

    str.lower()、str.upper():返回字符串的副本,全部字符小写、大写

    str.split(sep=None):返回一个列表,由str根据sep被分隔的部分组成

    如:“A,B,C”.split(",")结果为:['A', 'B', 'C']

    str.count(sub):返回子串sub在str中出现的次数

    如:“an apple a day”.count(“a”)结果为:4

    str.replace(old,new):返回字符串str副本,所有old子串被替换为new

    如:“python”.replace(“n”,“n123.io”)结果为:“python123.io”

    str.center(width[,fillchar]):字符串str根据宽度width居中,fillchar可选

    如:“python”.center(20,“=”)结果为:‘=======python=======’

    str.strip(chars):从str中去掉在其左侧和右侧chars中列出的字符

    如:“= python”.strip(“ =np”)结果为:“ytho”

    str.join(iter):在iter变量除最后元素外每个元素后增加一个str

    如:“,”.join(“12345”)结果为:“1,2,3,4,5”

    此方法主要用于字符串分隔

  • 相关阅读:
    Mybatis中的like模糊查询
    Cookie
    架构师的自我修养
    微服务要面临的问题
    为啥要去IOE——分布式架构的由来
    分层架构设计
    如何选开源协议
    中国互联网20年简史
    2018第27周总结
    保住本金,安全第一
  • 原文地址:https://www.cnblogs.com/p36606jp/p/15113913.html
Copyright © 2011-2022 走看看