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” ...
随机推荐
- DevExpress WPF v19.1新版亮点:Ribbon等控件新功能
行业领先的.NET界面控件DevExpress 日前正式发布v19.1版本,本站将以连载的形式介绍各版本新增内容.在本系列文章中将为大家介绍DevExpress WPF v19.1中新增的一些控件及部 ...
- hashmap分解大法--tableSizeFor方法
tableSizeFor方法 /** * 根据容量参数,返回一个2的n次幂的table长度. */ private static final int tableSizeFor(int c) { int ...
- Oracal数据库安装配置教程
官网注册账号登录 https://www.oracle.com/technetwork/database/enterprise-edition/downloads/oracle12c-windows- ...
- 常用cmd命令总结
1.常用操作 cls #清屏set #查看环境变量cd #切换工作目录 (换盘:直接输入 C: 或 D:)cd.. #返回上级目录exit #关闭cmd窗口 2.有关Python pip instal ...
- JVM基础——面试、笔试
1.java内存与内存溢出 1.1 JVM分为哪些区,每一个区干嘛的?(见java虚拟机38页) (1)程序计数器(线程私有) 当前线程执行字节码的信号指示器.(每个线程都会在程序计数器中存储其指令, ...
- js-点击tab按钮,同一页面显示不同的内容
效果: html: JS: css: .tabs-two{ .two{ display: inline-block; font-size:14px; height: 17px; font-weight ...
- [CF1093G]Multidimensional Queries 题解
前言 DennyQi太巨了! 定义一个点\(a\),\(a_x\)表示\(a\)在第\(x\)维空间上的坐标值 题解 这题的思路珂以说非常巧妙(原谅我又用了这个"珂"), 我们知道 ...
- Java虚拟机之JVM调节参数
-XX:+PrintGC 使用这个参数,虚拟机启动后,每次GC就会打印日志. -XX:+UseSerialGC 使用串行垃圾回收器. -XX:+PrintGCDetails 打印详细信息.包括各个区的 ...
- python3学习笔记(二):Python初识
一.算法 在开始认真地编程之前,首先来解释下什么是计算机程序设计.简单地说,它就是告诉计算机要做什么.计算机可以做很多事情,但是它不会自己思考,需要我们告诉它具体细节,并且使用计算机能够理解的语言把算 ...
- Java并发编程的艺术笔记(三)——Thread.join()
t.join()方法只会使主线程进入等待池并等待t线程执行完毕后才会被唤醒.并不影响同一时刻处在运行状态的其他线程.它能够使得t.join()中的t优先执行,当t执行完后才会执行其他线程.能够使得线程 ...