zoukankan      html  css  js  c++  java
  • python字符串Str方法

    <1>find

      检测 str 是否包含在 mystr中,如果是返回开始的索引值,否则返回-1

      使用方法:str.find("xx",0,len(str))

    <2>index

      跟find()方法一样,只不过如果str不在 mystr中会报一个异常.

      使用方法:str.index("xx")

    <3>count

      返回 str在start和end之间 在 mystr里面出现的次数

      使用方法:str.count("xx",0,len(str))

    <4>replace

      把 mystr 中的 str1 替换成 str2,如果 count 指定,则替换不超过 count 次.

      使用方法:str.replace(str1, str2, str.count(str1))

    <5>split

      以 str 为分隔符切片 mystr,如果 maxsplit有指定值,则仅分隔 maxsplit 个子字符串

      使用方法:str.split(" ", 2)

    <6>capitalize

      把字符串的第一个字符大写

      使用方法:str.capitalize()

    <7>title

      把字符串的每个单词首字母大写

      使用方法:str.title()

    <8>startswith

      检查字符串是否是以 obj 开头, 是则返回 True,否则返回 False

      使用方法:str.starswith("obj")

    <9>endswith

      检查字符串是否以obj结束,如果是返回True,否则返回 False.

      使用方法:str.endswith("obj")

    <10>lower

      转换 mystr 中所有大写字符为小写

      使用方法:str.lower()

    <11>upper

      转换 mystr 中的小写字母为大写

      使用方法:str.upper()

    <12>ljust

      返回一个原字符串左对齐,并使用空格填充至长度 width 的新字符串

      使用方法:str.ljust(5)

    <13>rjust

      返回一个原字符串右对齐,并使用空格填充至长度 width 的新字符串

      使用方法:str.rjust(width)

    <14>center

      返回一个原字符串居中,并使用空格填充至长度 width 的新字符串

      使用方法:str.center(width)

    <15>lstrip

      删除 str 左边的空白字符

      使用方法:str.lstrip()

    <16>rstrip

      删除 str 字符串末尾的空白字符

      使用方法:str.rstrip()

    <17>strip

      删除str字符串两端的空白字符

      使用方法:str.strip()

    <18>rfind

      类似于 find()函数,不过是从右边开始查找.

      使用方法:str.rfind("xx")

    <19>rindex

      类似于 index(),不过是从右边开始.

      使用方法:str.rindex("xx")

    <20>partition

      把mystr以str分割成三部分,str前,str和str后

      使用方法:mystr.partition(str)

    <21>rpartition

      类似于 partition()函数,不过是从右边开始.

      使用方法:mystr.rpartition(str)

    <22>splitlines

      按照行分隔,返回一个包含各行作为元素的列表

      使用方法:mystr.splitlines()

    <23>isalpha

      如果 mystr 所有字符都是字母 则返回 True,否则返回 False

      使用方法:str.isalpha()

    <24>isdigit

      如果 mystr 只包含数字则返回 True 否则返回 False.

      使用方法:str.isdigit()

    <25>isalnum

      如果 mystr 所有字符都是字母或数字则返回 True,否则返回 False

      使用方法:str.isalnum()

    <26>isspace

      如果 mystr 中只包含空格,则返回 True,否则返回 False.

      使用方法:str.isspace()

    <27>join

      mystr 中每个字符后面插入str,构造出一个新的字符串

      使用方法:str.join(str)

  • 相关阅读:
    洛谷 4035 [JSOI2008]球形空间产生器
    洛谷 2216 [HAOI2007]理想的正方形
    洛谷2704 [NOI2001]炮兵阵地
    洛谷2783 有机化学之神偶尔会做作弊
    洛谷 2233 [HNOI2002]公交车路线
    洛谷2300 合并神犇
    洛谷 1641 [SCOI2010]生成字符串
    Vue history模式支持ie9
    VUE实现登录然后跳转到原来的页面
    vue history模式 apache配置
  • 原文地址:https://www.cnblogs.com/wilson-wu/p/8063941.html
Copyright © 2011-2022 走看看