一、
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. STL sort实现可迭代容器中对象的多重标准排序

    #include <iostream> #include <string> #include <vector> #include <algorithm> ...

  2. Python修炼之路-函数

    Python编程之函数 程序的三种方式 面向对象:类------->class 面向过程:过程------>def 函数式编程:函数------>def 定义函数 函数:逻辑结构化与 ...

  3. Linux网络性能优化方法简析

    Linux网络性能优化方法简析 2010-12-20 10:56 赵军 IBMDW 字号:T | T 性能问题永远是永恒的主题之一,而Linux在网络性能方面的优势则显而易见,这篇文章是对于Linux ...

  4. python类库26[sqlite]

    一 sqlite 与 python 的类型对应 二 实例 import sqlite3 def sqlite_basic():     # Connect to db     conn = sqlit ...

  5. python接口自动化五(参数关联)

    前言 我们用自动化发帖之后,要想接着对这篇帖子操作,那就需要用参数关联了,发帖之后会有一个帖子的id,获取到这个id,继续操作传这个帖子id就可以了 (博客园的登录机制已经变了,不能用账号和密码登录了 ...

  6. 【GDOI2017模拟12.9】最近公共祖先

    题目 分析 首先,将这些节点按dfs序建一棵线段树. 因为按dfs序,所以在同一子树上的节点会放在线段树相邻的位置. 发现,对于一个位置x,它的权值只会对以x为根的子树造成影响. 当修改x时,用w[x ...

  7. [转] Linux多线程编程之pthread

    转载出处:https://blog.csdn.net/skyroben/article/details/72793409 1.背景知识 Linux没有真正意义上的线程,它的实现是由进程来模拟,所以属于 ...

  8. Linux基础教程 linux下查询history操作时间的方法

    要在linux操作系统中查看history记录的操作时间,可以按如下步骤实现: 学习linux 1,修改/etc/profile文件,在末尾添加:exporthisttimeformat=”%f %t ...

  9. window.location.hash(hash应用)---跳转到hash值制定的具体页面

    location是javascript里边管理地址栏的内置对象,比如location.href就管理页面的url,用location.href=url就可以直接将页面重定向url.而location. ...

  10. maven 私服的setting.xml配置

    <?xml version="1.0" encoding="UTF-8"?> 2 <settings xmlns="http://m ...