zoukankan      html  css  js  c++  java
  • 【python】string functions

    1、str.replace(word0,word1)  ##用word1替换str中所有的word0

    >>> 'tea for too'.replace('too', 'two')
    输出:'tea for two'

    2、str.lower() ##字符串str中的字母全部转换成小写

      str.upper() ##字符串str中的字母全部转换成大写

      str.capitalize() ##字符串str中的第一个字母转换成大写

    >>> 'df dfs ds'.upper()
    'DF DFS DS'
    >>> 'SDF SF OMP DFS'.lower()
    'sdf sf omp dfs'
    >>> 'df dfs ds'.capitalize()
    'Df dfs ds'

     3. str.split(sep) ## 把str按照sep进行切分,sep缺省时按照whilespace(space, tab, newline, return, formfeed)切分

    >>> 'df dfs ds'.split()
    ['df', 'dfs', 'ds']
    >>> 'df,dfs,ds'.split(',')
    ['df', 'dfs', 'ds']
    

    ----<未完待续>---------

    正则表达式通配处理

    >>> import re
    >>> re.findall(r'f[a-z]*', 'which foot or hand fell fastest')
    输出: ['foot', 'fell', 'fastest']
    >>> re.sub(r'([a-z]+) 1', r'1', 'cat in the the hat')
    输出:'cat in the hat'



  • 相关阅读:
    Vim使用
    软件测试基础知识
    数字成像系统
    linux操作系统运行学习总结
    python算法学习总结
    Django Rest Framework框架
    mysql学习笔记一
    学习方法
    算法模板汇总
    习题练习1
  • 原文地址:https://www.cnblogs.com/wxiaoli/p/6795273.html
Copyright © 2011-2022 走看看