一、
1. upper()
作用:将字符串中字符转换为大写

  1. In [17]: spam
  2. Out[17]: 'hello,world'
  3.  
  4. In [18]: print(spam.upper())
  5. HELLO,WORLD

2.lower()
作用:将字符串中字符转换为小写

  1. In [19]: spam = spam.upper()
  2.  
  3. In [20]: spam
  4. Out[20]: 'HELLO,WORLD'
  5.  
  6. In [21]: print(spam.lower())
  7. hello,world

3.isupper()
作用:判断字符串中是否有大写字符

  1. In [22]: spam
  2. Out[22]: 'HELLO,WORLD'
  3.  
  4. In [23]: spam.isupper()
  5. Out[23]: True

4.islower()
作用:判断字符串中是否有小写字符

  1. In [24]: spam
  2. Out[24]: 'HELLO,WORLD'
  3.  
  4. In [25]: spam.islower()
  5. Out[25]: False

5.isalpha()
isalpha()返回 True,如果字符串只包含字母,并且非空

  1. In [27]: spam
  2. Out[27]: 'HELLO,WORLD'
  3.  
  4. In [28]: spam.isalpha()
  5. Out[28]: False

6.isalnum()
isalnum()返回 True,如果字符串只包含字母和数字,并且非空

  1. In [39]: mystring01 = '123hello'
  2.  
  3. In [40]: mystring01.isalnum()
  4. Out[40]: True

7.isdecimal()
isdecimal()返回 True,如果字符串只包含数字字符,并且非空

  1. In [46]: mystring01 = ''
  2.  
  3. In [47]: mystring01.isdecimal()
  4. Out[47]: True

8.isspace()
isspace()返回 True,如果字符串只包含空格、制表符和换行,并且非空

  1. In [53]: mystring01 = '\n '
  2.  
  3. In [54]: mystring01.isspace()
  4. Out[54]: True

9.istitle()
istitle()返回True,如果字符串仅包含以大写字母开后面都是小写字母的单词

  1. In [62]: mystring01 = 'Helloworld'
  2.  
  3. In [63]: mystring01.istitle()
  4. Out[63]: True

10.startswith()
startswith()方法返回 True,如果它们所调用的字符串以该方法传入 的字符串开始

  1. In [71]: 'hello world'.startswith('hello')
  2. Out[71]: True

11.endswith()
endswith()方法返回 True,如果它们所调用的字符串以该方法传入 的字符串开结束

  1. In [72]: 'hello world'.endswith('ld')
  2. Out[72]: True

12.join()
拼接字符串列表

  1. In [76]: '-'.join(['aaa','bbb','ccc'])
  2. Out[76]: 'aaa-bbb-ccc'

13.split()
分解字符串

  1. In [79]: 'aaa-bbb-ccc'.split("-")
  2. Out[79]: ['aaa', 'bbb', 'ccc']

14.strip()
(1)删除两侧空白字符

  1. In [86]: print(mystring01)
  2. hel lo , w o r ld
  3.  
  4. In [87]: print(mystring01.strip())
  5. hel lo , w o r ld

(2)删除指定字符串

  1. In [108]: print(mystring01)
  2. hel lo , w o r ld
  3.  
  4. In [109]: print(mystring01.strip(' hel lo'))
  5. , w o r ld

15.lstrip()
删除左边空白字符

  1. In [89]: print(mystring01)
  2. hel lo , w o r ld
  3.  
  4. In [90]: print(mystring01.lstrip())
  5. hel lo , w o r ld

16.rstrip()
删除右边空白字符

  1. In [92]: print(mystring01)
  2. hel lo , w o r ld
  3.  
  4. In [93]: print(mystring01.rstrip())
  5. hel lo , w o r ld

17.pyperclip模块
使用pyperclip模块总的copy和paste参数

  1. import pyperclip
  2. pyperclip.copy('Hello world!')
  3. pyperclip.paste()

python字符串-方法的更多相关文章

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

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

  2. Python 字符串方法详解

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

  3. python 字符串方法整理

    Python字符串方法 1.大小写转换 1.1 lower.upper lower():小写 upper():大写 1.2 title.capitalize S.title():字符串中所有单词首字母 ...

  4. python 字符串方法isdigit()

    python isdigit() 方法检测字符串是否只有数字组成. 语法: isdigit()方法语法: str.isdigit() 参数:无 返回值: 如果字符串中只含有数字则返回True,否则返回 ...

  5. python字符串方法以及注释

    转自fishC论坛:http://bbs.fishc.com/forum.php?mod=viewthread&tid=38992&extra=page%3D1%26filter%3D ...

  6. python字符串方法replace()简介

    今天写replace方法的时候的代码如下: message = "I really like dogs" message.replace('dog','cat') print(me ...

  7. [python]字符串方法

    字符串的方法及注释 字符串的方法及注释             capitalize()   把字符串的第一个字符改为大写   casefold()   把整个字符串的所有字符改为小写   cente ...

  8. Python字符串方法

    capitalize() 把字符串的第一个字符改为大写 casefold() 把整个字符串的所有字符改为小写 center(width) 将字符串居中,并使用空格填充至长度 width 的新字符串 c ...

  9. Python字符串方法总结(一)

    1.find 在一个较长的字符串中查找子串.它返回子串所在位置的最左端索引.如果没有找到则返回-1 2.split 将字符串用给定的分隔符分割成序列,当没有提供分隔符时,默认把所有空格作为分隔符 3. ...

  10. python 字符串方法及列表,元组,字典(一)

    字符串 str 注: 若想要保持单引号和双引号为字符串的一部分 1)单双引号交替使用, 2)使用转义字符\ 3)成对三个引号被存在变量里 二.字符串详细用法 字符串的单个取值例 p_1=”hello” ...

随机推荐

  1. Python服务器开发三:Socket

    Python服务器开发三:Socket   socket是操作系统中I/O的延续,它可以使进程和机器之间的通信成为可能.socket可以看成一个标准的文件描述符.不同的是文件需要用open()函数打开 ...

  2. swiper保存

    //初始化swiper var index=0; if(sessionStorage.getItem("index")){ index=sessionStorage.getItem ...

  3. 【知识】定时器setTimeout/setInterval执行时this指针指向问题

    [问题描述] setTimetout/setInterval中this指针指向window,以下是一个小demo: var demoChange = { key: true, changeFun() ...

  4. python-opencv中的cv2.inRange函数

    本次目标是将一副图像从rgb颜色空间转换到hsv颜色空间,颜色去除白色背景部分 具体就调用了cv2的两个函数,一个是rgb转hsv的函数 具体用法 hsv = cv2.cvtColor(rgb_ima ...

  5. [BZOJ1697][USACO2007 FEB]Cow Sorting牛排序:贪心+置换

    分析 一个月前做的一道题补一下题解,就简单写一写吧. 单独考虑每一个循环节,如果只进行内部的调整,最优方案显然是把最小的绕这个循环交换一圈. 但是借助全局最小值可能使答案更优,两种情况取个\(\max ...

  6. 根据linux自带的JDK,配置JAVA_HOME目录

    在配置hadoop是,进行格式化hadoop的时候,出现找不到jdk 我用centos6.5是64位的, 发现本机有java ,就找了一下其位置 找到了jdk-1.7.0_75 which java ...

  7. 2018-2019-2 20165235《网络对抗技术》Exp7 网络欺诈防范

    2018-2019-2 20165235<网络对抗技术>Exp7 网络欺诈防范 实验目的 本实践的目标理解常用网络欺诈背后的原理,以提高防范意识,并提出具体防范方法 实验内容 (1)简单应 ...

  8. mysql 5.7 安装配置及无法启动的问题解决

    (用这篇配置就能正常配置成功) mysql 免安装版配置方法: https://www.jb51.net/article/134452.htm 参考:https://blog.csdn.net/qq_ ...

  9. 配置OpenLDAP,Java操作LDAP,DBC-LDAP进访问

    LDAP快速入门 1. LDAP简介 LDAP(轻量级目录访问协议,Lightweight Directory Access Protocol)是实现提供被称为目录服务的信息服务.目录服务是一种特殊的 ...

  10. 各种sort排序总结

    冒泡排序 选择排序 插入排序