• python字符串处理


    字符串处理绝对是任何一门语言的重点。

    str.partition(sep)

    Split the string at the first occurrence of sep, and return a 3-tuple containing the part before the separator, the separator itself, and the part after the separator. If the separator is not found, return a 3-tuple containing the string itself, followed by two empty strings.

    mystr = 'hello,!!!world'
    print(mystr.partition(','))
    # output
    ('hello', ',', '!!!world')

    str.split(sep=Nonemaxsplit=-1)

    Return a list of the words in the string, using sep as the delimiter string. If maxsplit is given, at most maxsplit splits are done (thus, the list will have at most maxsplit+1 elements). If maxsplit is not specified or -1, then there is no limit on the number of splits (all possible splits are made).

    str.join(iterable)

    Return a string which is the concatenation of the strings in iterable. A TypeError will be raised if there are any non-string values in iterable, including bytes objects. The separator between elements is the string providing this method.

    mylist = ['first', 'second', 'third']
    mystr = '#'.join(mylist)
    print(mystr)
    # output: first#second#third

    str.startswith(prefix, start, end)

    Return True if string starts with the prefix, otherwise return Falseprefix can also be a tuple of prefixes to look for. With optional start, test string beginning at that position. With optional end, stop comparing string at that position.

    mystr = "this is string example....wow!!!"
    print(mystr.startswith('this'))
    print(mystr.startswith('is', 2, 4))
    print(mystr.startswith('this', 2, 4))

    输出如下:

    True
    True
    False

    str.strip([chars])

    Return a copy of the string with the leading and trailing characters removed. The chars argument is a string specifying the set of characters to be removed. If omitted or None, the chars argument defaults to removing whitespace. The charsargument is not a prefix or suffix; rather, all combinations of its values are stripped:

  • 相关阅读:
    poi生成excel整理(设置边框/字体/颜色/加粗/居中/)
    java里poi操作Excel工具类【我改】
    java里poi操作excel的工具类(兼容各版本)
    在java poi导入Excel通用工具类示例详解
    layui给select下拉框赋值
    Unity3d开发wp8问题汇总
    Unity3D WP8发布解决方案名 DefaultPackageName 修改问题
    微软发布WP SDK8.0 新增语音、应用内支付等原生API
    unity3d android互调
    解决unity3d发布的网页游戏放到服务器上无法使用的问题
  • 原文地址:https://www.cnblogs.com/gattaca/p/7294357.html
Copyright © 2020-2023  润新知