一、
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. Linux安装redis,启动配置不生效(指定启动加载配置文件)

    一.今天有个同学问我,为什么明明安装了redis,修改了配置,启动的时候,配置还是不生效.如下图是安装后的redis文件图. 二.想加载上图中的redis.conf,进入到src中寻找到启动文件red ...

  2. Vue原理解析——自己写个Vue

    Vue由于其高效的性能和灵活入门简单.轻量的特点下变得火热.在当今前端越来越普遍的使用,今天来剖析一下Vue的深入响应式原理. tips:转自我的博客唐益达博客,此为原创.转载请注明出处,原文链接 一 ...

  3. sevlet

    https://blog.csdn.net/Mithrandir_One/article/details/52900425 大家现在做的比较多的基本上就是 web 应用.所以一定要把 sevlet 及 ...

  4. DRF介绍,DRF项目开发,DRF项目的视图类的dispatch源码解析

    目录 一.DRF介绍 1. 什么是DRF 2. 为什么要用DRF (1)使用DRF的原因 (2)站在开发者的角度来说用DRF的好处(暂时列举这么多) 二.用DRF开发后端项目 三.APIView请求生 ...

  5. MySQL——Alias

    查询时,当表名很长或者执行一些特殊查询的时候,为了方便操作或者需要多次使用相同的表时,可以为表指定别名,用这个别名代替表原来的名称. 设置别名为表设置别名 <表名> [AS] <别名 ...

  6. 【NOIP2016提高A组五校联考2】running

    题目 小胡同学是个热爱运动的好孩子. 每天晚上,小胡都会去操场上跑步,学校的操场可以看成一个由n个格子排成的一个环形,格子按照顺时针顺序从0 到n- 1 标号. 小胡观察到有m 个同学在跑步,最开始每 ...

  7. 【NOIP2016提高A组模拟8.15】Password

    题目 分析 首先我们知道,原A序列其实表示一个矩阵,而这个矩阵的对角线上的数字就是答案B序列. 接着\(a.b>=gcd(a,b)\),所以序列A中的最大的数就是ans[1],第二大的数就是an ...

  8. vs2017 制作winfrom 安装包!

    https://www.cnblogs.com/GuZhenYin/p/8176981.html 转载 前言 项目中有用到winfrom做配套的打印程序,直接给客户一个debug文件夹,当然不是很好. ...

  9. Java 集合基础详细介绍

    一.Java集合框架概述 集合.数组都是对多个数据进行存储操作的结构,简称Java容器.此时的存储,主要指的是内存层面的存储,不涉及到持久化的存储(.txt, .jpg, .avi,数据库中).Jav ...

  10. React native 之 async/await

    参考资料 :https://www.jianshu.com/p/1e75bd387aa0 要点: 1. async function(){} 将普通函数转换成Promise 2. await 表达式/ ...