def capitalize(self): # 第一个字符变大写

def center(self, width, fillchar=None): # 内容居中,两端可指定内容填充

def count(self, sub, start=None, end=None): # 返回字符出现次数

def endswith(self, suffix, start=None, end=None): # 判断以什么结尾是否为真

def expandtabs(self, tabsize=8): # 把字符串中tab换成n个空格

def find(self, sub, start=None, end=None): #查找子序列的位置,没有返回-1
def format(self, *args, **kwargs): #字符串的格式化,动态参数   
example:
  test = 'hello {0},age{1}'

  res = test.format('chenyan','19')

  print(res)

    hello chenyan,age19    #返回结果
def index(self, sub, start=None, end=None): #字符串子序列位置,没找到会报错
def isalnum(self): #判断是否所有字符都是字母数字
def isalpha(self): #判断字符串是否全部为字母
def isdecimal(self): #判断字符串没有小数点为true
def isdigit(self): #判断字符串是否都是数字    
def isidentifier(self): # 判断字符串是否有效的标识符,不是为真

def islower(self): # 判断字符串是否全部为小写

def isnumeric(self): # 判断字符串是否全部为数字

def isspace(self): # 字符串全部为空格为真

def istitle(self): #判断是否为标题(单词首字母大写)
def isupper(self): #判断是否全部为大写
def join(self, iterable): #返回一个字符串,它是字符串的连接
example:
  i = ['hehe','haha']
  res = '-'.join(i)
  print(res)
    hehe-haha  #返回结果
def ljust(self, width, fillchar=None): #返回的是字符串长度宽度的左对齐。右侧填充(默认是空格)
example:
  i = 'hehe'

  res = i.ljust(20,'*')

  print(res)

    hehe****************   #返回
def lower(self): #可以让字符串变小写
def lstrip(self, chars=None): #移除字符串左边的空格
def partition(self, sep): #sep为指定分隔符

example:
   i = 'hehe&haha'

    res = i.partition('&')

    print(res)

      ('hehe', '&', 'haha') 返回元组

def replace(self, old, new, count=None): # 替换,可指定替换个数
example:
    i = 'hehe&haha'

    res = i.replace('he','He',1)

      print(res)
def rjust(self, width, fillchar=None): # 右边对齐,左边填充
def rpartition(self, sep): #指定字符串分隔符后,分前中后三部分
def rsplit(self, sep=None, maxsplit=-1): #返回一个单词列表,使用sep作为分隔符字符串
def rstrip(self, chars=None): # 去除右边的空格

def split(self, sep=None, maxsplit=-1): # 指定分隔符分割

def splitlines(self, keepends=None): #根据换行符分割
def startswith(self, prefix, start=None, end=None): # 判断前缀

def strip(self, chars=None): # 去除首尾的空格

def swapcase(self): # 可以把字符串大小写反向转换

def title(self): # 可以把字符串的单词首字符变大写,其他变小写

def upper(self): # 转换大写

def zfill(self, width): #在左侧填充一个数字字符串,右边对齐
example:
  i = 'my love'

  res = i.zfill(12)

  print(res)

    00000my love  #返回结果
 

Python之字符串方法的更多相关文章

  1. python learning 字符串方法

    一.重点掌握的6种字符串方法: 1.join命令 功能:用于合并,将字符串中的每一个元素按照指定分隔符进行拼接 程序举例: seq = ['1','2','3','4'] sep = '+' v = ...

  2. python拼接字符串方法汇总

    python拼接字符串一般有以下几种方法: 1.直接通过(+)操作符拼接 s = 'Hello'+' '+'World'+'!' print(s) 输出结果:Hello World! 这种方式最常用. ...

  3. Python常见字符串方法函数

    1.大小写转换 S.lower() S.upper() 前者将S字符串中所有大写字母转为小写,后者相反 S.title() S.capitalize() 前者返回S字符串中所有单词首字母大写且其他字母 ...

  4. python之字符串方法upper/lower

    1.描述: upper():用于将字符串全部转换为大写字母 lower():用于将字符串全部转换为小写字母 2.语法 str.upper() str.lower() 3.返回值 upper()或low ...

  5. python,字符串方法

    1.capitalize() 首字母大写 text = "hello word" text2 = text.capitalize() print(text2) 2.1.casefo ...

  6. python中字符串方法总结

    定义一个空字符串: a=' '; s.strip() #去空格 s.upper()#全部转换成大写: s.lower()# 全部转换成小写: s.isdigit()#判断字符串是否只有数字组成:返回t ...

  7. python字符串方法的简单使用

    学习python字符串方法的使用,对书中列举的每种方法都做一个试用,将结果记录,方便以后查询. (1) s.capitalize() ;功能:返回字符串的的副本,并将首字母大写.使用如下: >& ...

  8. Python 字符串方法详解

    Python 字符串方法详解 本文最初发表于赖勇浩(恋花蝶)的博客(http://blog.csdn.net/lanphaday),如蒙转载,敬请保留全文完整,切勿去除本声明和作者信息.        ...

  9. python反转字符串(简单方法)及简单的文件操作示例

    Python反转字符串的最简单方法是用切片: >>> a=' >>> print a[::-1] 654321 切片介绍:切片操作符中的第一个数(冒号之前)表示切片 ...

随机推荐

  1. html2canvas文字重叠(手机端)

    发现情况: 1.设置文字居中,文字自动换行后文字有重叠   text-align: center; 解决办法: text-align: left; text-align: justify;等 2.使用 ...

  2. Mac下文件的编码及修改编码

    brew install enca # Enca语法 Usage: enca [-L LANGUAGE] [OPTION]... [FILE]... enconv [-L LANGUAGE] [OPT ...

  3. 20165306 Exp3 免杀原理与实践

    Exp3 免杀原理与实践 一.实践内容概述 1.正确使用msf编码器,msfvenom生成如jar之类的其他文件,veil-evasion,加壳工具,使用shellcode编程 2.通过组合应用各种技 ...

  4. pronaunciation

    5 strong  weak s            d n            t l             th you and I  -> you an dai -> you ...

  5. Java基础知识盘点(二)- 集合篇

    List和Set区别 List和Set都是继承Collection接口 List特点:元素有放入顺序,元素可重复 Set特点:元素无放入顺序,元素不可重复 Set和List对比: Set:检索元素效率 ...

  6. Windows安装zookeeper 单机版

    首先需要安装JdK,从Oracle的Java网站下载,安装很简单,就不再详述. 1.下载zookeeper, https://mirrors.tuna.tsinghua.edu.cn/apache/z ...

  7. redis -memcahe

    tomcat自动化集成 https://blog.51cto.com/ellenv/1932817 Redis与Memcache对比:1.Memcache是一个分布式的内存对象缓存系统而redis是可 ...

  8. zookeeper和kafka的使用

    zookeeper使用和原理探究(一) http://www.blogjava.net/BucketLi/archive/2010/12/21/341268.html zookeeper的作用和原理讲 ...

  9. Phonics 自然拼读法 ai, oa,ie, ee,or,j Teacher:Lamb

    课上内容(Lesson) 1. “L” 的介绍 Light L      e.g.   Love Like Life Dark L      e.g.   Apple  world  call 2. ...

  10. Lab 10-1

    This lab includes both a driver and an executable. You can run the executable from anywhere, but in ...