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

In [17]: spam
Out[17]: 'hello,world' In [18]: print(spam.upper())
HELLO,WORLD

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

In [19]: spam = spam.upper()

In [20]: spam
Out[20]: 'HELLO,WORLD' In [21]: print(spam.lower())
hello,world

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

In [22]: spam
Out[22]: 'HELLO,WORLD' In [23]: spam.isupper()
Out[23]: True

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

In [24]: spam
Out[24]: 'HELLO,WORLD' In [25]: spam.islower()
Out[25]: False

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

In [27]: spam
Out[27]: 'HELLO,WORLD' In [28]: spam.isalpha()
Out[28]: False

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

In [39]: mystring01 = '123hello'

In [40]: mystring01.isalnum()
Out[40]: True

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

In [46]: mystring01 = ''

In [47]: mystring01.isdecimal()
Out[47]: True

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

In [53]: mystring01 = '\n '

In [54]: mystring01.isspace()
Out[54]: True

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

In [62]: mystring01 = 'Helloworld'

In [63]: mystring01.istitle()
Out[63]: True

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

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

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

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

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

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

13.split()
分解字符串

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

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

In [86]: print(mystring01)
hel lo , w o r ld In [87]: print(mystring01.strip())
hel lo , w o r ld

(2)删除指定字符串

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

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

In [89]: print(mystring01)
hel lo , w o r ld In [90]: print(mystring01.lstrip())
hel lo , w o r ld

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

In [92]: print(mystring01)
hel lo , w o r ld In [93]: print(mystring01.rstrip())
hel lo , w o r ld

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

import pyperclip
pyperclip.copy('Hello world!')
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. 在win32中使用SetWindowSubclass阻止Enter键

    使用阻止Enter键的编辑控件的简单子类来完成此操作: LRESULT CALLBACK EditSubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam, L ...

  2. Berlekamp-Massey algorithm

    https://www.cnblogs.com/zzqsblog/p/6877339.html https://blog.csdn.net/qq_39972971/article/details/80 ...

  3. Python开发WebService--使用soaplib库

    Python开发WebService--使用soaplib库   使用soaplib开发基于Python语言的WebService主要有以下四个步骤:一.准备环境    S1:下载插件Python.s ...

  4. Collections 工具类和 Arrays 工具类常见方法

    Collections Collections 工具类常用方法: 排序 查找,替换操作 同步控制(不推荐,需要线程安全的集合类型时请考虑使用 JUC 包下的并发集合) 排序操作 void revers ...

  5. [洛谷P3322] SDOI2015 排序

    问题描述 小A有一个1-2^N的排列A[1..2^N],他希望将A数组从小到大排序,小A可以执行的操作有N种,每种操作最多可以执行一次,对于所有的 i(1<=i<=N),第i中操作为将序列 ...

  6. python 操作符**与*的用法

  7. vue - 登录验证与权限控制

    描述具体问题 需求 业务系统通常需要登录才能访问受限资源,在用户未登录情况下访问受限资源需要重定向到登录页面: 多个业务系统之间要实现单点登录,即在一个系统或应用已登录的情况下,再访问另一个系统时不需 ...

  8. 17. ClustrixDB 日志管理

    ClustrixDB记录关于重要和有问题的查询的详细信息.这些日志有助于确定以下事项: 慢速查询 资源争用 SQL错误 读取意外数量行的查询 模式变化 全局变量的修改 集群的改变 默认情况下,查询日志 ...

  9. linux-ntp-10

    Unix/linux类:ntp.aliyun.com,ntp1-7.aliyun.com windows类: time.pool.aliyun.com s1a.time.edu.cn 北京邮电大学 s ...

  10. 通过web传大文件

    上传文件的jsp中的部分 通过form表单向后端发送请求 <form id="postForm" action="${pageContext.request.con ...