python字符串-方法
一、
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字符串-方法的更多相关文章
- python字符串方法的简单使用
学习python字符串方法的使用,对书中列举的每种方法都做一个试用,将结果记录,方便以后查询. (1) s.capitalize() ;功能:返回字符串的的副本,并将首字母大写.使用如下: >& ...
- Python 字符串方法详解
Python 字符串方法详解 本文最初发表于赖勇浩(恋花蝶)的博客(http://blog.csdn.net/lanphaday),如蒙转载,敬请保留全文完整,切勿去除本声明和作者信息. ...
- python 字符串方法整理
Python字符串方法 1.大小写转换 1.1 lower.upper lower():小写 upper():大写 1.2 title.capitalize S.title():字符串中所有单词首字母 ...
- python 字符串方法isdigit()
python isdigit() 方法检测字符串是否只有数字组成. 语法: isdigit()方法语法: str.isdigit() 参数:无 返回值: 如果字符串中只含有数字则返回True,否则返回 ...
- python字符串方法以及注释
转自fishC论坛:http://bbs.fishc.com/forum.php?mod=viewthread&tid=38992&extra=page%3D1%26filter%3D ...
- python字符串方法replace()简介
今天写replace方法的时候的代码如下: message = "I really like dogs" message.replace('dog','cat') print(me ...
- [python]字符串方法
字符串的方法及注释 字符串的方法及注释 capitalize() 把字符串的第一个字符改为大写 casefold() 把整个字符串的所有字符改为小写 cente ...
- Python字符串方法
capitalize() 把字符串的第一个字符改为大写 casefold() 把整个字符串的所有字符改为小写 center(width) 将字符串居中,并使用空格填充至长度 width 的新字符串 c ...
- Python字符串方法总结(一)
1.find 在一个较长的字符串中查找子串.它返回子串所在位置的最左端索引.如果没有找到则返回-1 2.split 将字符串用给定的分隔符分割成序列,当没有提供分隔符时,默认把所有空格作为分隔符 3. ...
- python 字符串方法及列表,元组,字典(一)
字符串 str 注: 若想要保持单引号和双引号为字符串的一部分 1)单双引号交替使用, 2)使用转义字符\ 3)成对三个引号被存在变量里 二.字符串详细用法 字符串的单个取值例 p_1=”hello” ...
随机推荐
- 【HDU2089】不要62
题目大意:求区间 [n,m] 中数位不包含 4 和 62 的数字的个数. 题解:数位dp. 预处理出 \(f[i][j]\) 表示 i 位数字中以 j 为第一位的满足条件的数字个数. 对于统计答案来说 ...
- easygui _1
GUI---图形用户界面 什么是GUI? GUI是Graphical User Interface(图形用户界面)的缩写.在GUI中,并不是键入文本和返回值,用户可以看到文本框,窗口,按钮等图形 ...
- 【leetcode】1214.Two Sum BSTs
题目如下: Given two binary search trees, return True if and only if there is a node in the first tree an ...
- 【leetcode】1210. Minimum Moves to Reach Target with Rotations
题目如下: In an n*n grid, there is a snake that spans 2 cells and starts moving from the top left corner ...
- jdk java 环境变量配置
下载 下载JDK 64 位 wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fw ...
- 大文件的分片传,断点续传,md5校验
一.概述 所谓断点续传,其实只是指下载,也就是要从文件已经下载的地方开始继续下载.在以前版本的HTTP协议是不支持断点的,HTTP/1.1开始就支持了.一般断点下载时才用到Range和Content- ...
- Tensorflow在win10下的安装(CPU版本)
环境:win10,64位 1.卸载python3.7,安装python3.6 由于之前已经安装了python,到tensorflow网站查看tensorflow的支持环境,https://tensor ...
- 目标检测Object Detection概述(Tensorflow&Pytorch实现)
1999:SIFT 2001:Cascades 2003:Bag of Words 2005:HOG 2006:SPM/SURF/Region Covariance 2007:PASCAL VOC 2 ...
- SQL简介及分类
SQL (Structured Query Language) 结构化查询语言,定义了所有操作关系型数据库的规则,只要是关系型数据库都需要用SQL语句: 语法: 一行可以有多个SQL语句,以分号结尾: ...
- DVWA--XSS(反射型)
0X01爱之初介绍 虽然XSS已经做了两节了 但是还是还是简单解释一下 前言:跨站脚本(Cross-Site Scripting,XSS)是一种经常出现在Web应用程序中的计算机安全漏洞,是由于Web ...