python3【基础】-字符串 常用的方法
字符串一个最重要的特性就是不可修改。
name.capitalize() 首字母大写
name.casefold() 大写全部变小写
name.center(50,"-") 输出 '---------------------Alex Li----------------------'
name.count('lex') 统计 lex出现次数
name.encode() 将字符串编码成bytes格式
name.endswith("Li") 判断字符串是否以 Li结尾
"Alex\tLi".expandtabs(10) 输出'Alex Li', 将\t转换成多长的空格
name.find('A') 查找A,找到返回其索引, 找不到返回-1 format :
>>> msg = "my name is {}, and age is {}"
>>> msg.format("alex",22)
'my name is alex, and age is 22'
>>> msg = "my name is {1}, and age is {0}"
>>> msg.format("alex",22)
'my name is 22, and age is alex'
>>> msg = "my name is {name}, and age is {age}"
>>> msg.format(age=22,name="ale")
'my name is ale, and age is 22'
format_map
>>> msg.format_map({'name':'alex','age':22})
'my name is alex, and age is 22' msg.index('a') 返回a所在字符串的索引
'9aA'.isalnum() True ''.isdigit() 是否整数
name.isnumeric
name.isprintable
name.isspace
name.istitle
name.isupper
"|".join(['alex','jack','rain'])
'alex|jack|rain' maketrans
>>> intab = "aeiou" #This is the string having actual characters.
>>> outtab = "" #This is the string having corresponding mapping character
>>> trantab = str.maketrans(intab, outtab)
>>>
>>> str = "this is string example....wow!!!"
>>> str.translate(trantab)
'th3s 3s str3ng 2x1mpl2....w4w!!!' msg.partition('is') 输出 ('my name ', 'is', ' {name}, and age is {age}') >>> "alex li, chinese name is lijie".replace("li","LI",1)
'alex LI, chinese name is lijie' msg.swapcase 大小写互换 >>> msg.zfill(40)
'00000my name is {name}, and age is {age}' >>> n4.ljust(40,"-")
'Hello 2orld-----------------------------'
>>> n4.rjust(40,"-")
'-----------------------------Hello 2orld' >>> b="ddefdsdff_哈哈"
>>> b.isidentifier() #检测一段字符串可否被当作标志符,即是否符合变量命名规则
True
关于字符串常用的方法:
python3【基础】-字符串 常用的方法的更多相关文章
- Python语言学习:字符串常用的方法
python字符串常用的方法 1. find( ):在字符串中搜索指定的值并返回它被找到的位置,如果没有找到,则返回-1 string.find(value,start,end) #value:必需, ...
- python字符串常用的方法解析
这是本人在学习python过程中总结的一些关于字符串的常用的方法. 文中引用了python3.5版本内置的帮助文档,大致进行翻译,并添加了几个小实验. isalnum S.isalnum() -> ...
- python 基础———— 字符串常用的调用 (图)
Python 常用的 字符串调用方法 这里用到了pycharm ( 使用Python 有力的工具) 下载地址https://www.jetbrains.com/pycharm/download/#s ...
- js基础-字符串常用属性合集
/* * * 实例方法---->必须要通过new的方式创建的对象(实例对象)来调用的方法 * 静态方法---->直接通过大写的构造函数的名字调用的方法(直接通过大写的对象名字调 ...
- Python3基础笔记--常用模块
目录: 参考博客:Python 之路 Day5 - 常用模块学习 Py西游攻关之模块 一.time模块 二.random模块 三.os模块 四.sys模块 五.hashlib模块 六.logging模 ...
- js入门之字符串常用的方法
一. 概念理解基本包装类型 1. 基本包装类型 三种基本包装类型 String var s = new String('123dddd'); Number Boolean 简单类型没有方法和属性 之所 ...
- js字符串常用判断方法
转自:http://blog.sina.com.cn/s/blog_6819fa800100j5t6.html 一.方法介绍 function obj$(id) ...
- JS操作字符串常用的方法
JS操作String对象的方法 charAt(index):返回指定索引处的字符串charCodeAt(index):返回指定索引处的字符的Unicode的值concat(str1,str2,...) ...
- python之字符串常用的方法
1. 去掉空格或换行符 s='. hello .world .\n' new_s = s.strip()#默认去掉字符串前后的空格和换行符 new_s = s.strip('.')#可传参去掉字符串前 ...
随机推荐
- vim8配置python3补全
安装Python3 卸载编译安装的python3 rm -rf /usr/local/lib/python3.7/ rm -rf /usr/local/bin/2to3* rm -rf /usr/lo ...
- 【oracle的安装和基本配置】
/*----------------------------登录和安装--------------------------------------*/ #从官网上选择安装的版本,任何一个版本都可以,目 ...
- Redis高可用详解:持久化技术及方案选择 (推荐)--转载自编程迷思博客www.cnblogs.com/kismetv/p/8654978.html
一.Redis高可用概述 在介绍Redis高可用之前,先说明一下在Redis的语境中高可用的含义. 我们知道,在web服务器中,高可用是指服务器可以正常访问的时间,衡量的标准是在多长时间内可以提供正常 ...
- Delphi主线程重入而导致程序卡死的解决方案
Delphi的线程可以通过调用AThread.Synchronize(AProc),可以将Proc放入主线程中同步运行,此时AThread将挂起,直到主线程执行完AProc. 如果有BThread,调 ...
- spark+phoenix
phoenix作为查询引擎,为了提高查询效率,为phoenix表创建了二级索引,而数据是sparkstreaming通过hbase api直接向hbase插数据.那么问题来了,对于phoenix的二级 ...
- CDH升级 5.7.5 --> 5.13.3(tar包方式)
博客园首发,转载请注明出处:https://www.cnblogs.com/tzxxh/p/9123231.html 一.准备 1.关闭cdh中的服务 hdfs.yarn等所有服务:关闭 cm-ser ...
- STM32 HAL库学习系列第4篇 定时器TIM----- 开始定时器与PWM输出配置
基本流程: 1.配置定时器 2.开启定时器 3.动态改变pwm输出,改变值 HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_1); 函数总结: __HAL_TIM ...
- 树莓派安装OSMC打造家庭影院,还可以看优酷和CCTV
1.OSMC是什么? OSMC是树莓派官方推荐的影音系统,是一款开源的操作系统,是Openelec的升级版,同样是基于Kodi的开源项目.OSMC,使用它可以将树莓派打造成一款全功能的家庭影院系统,它 ...
- STL的六大容器之iterator----自定义范式
STL的iterator组件,分离了容器和算法. 一.规定 在STL体系下定义iterator,要满足规定的一些规范: 1.iterator_category 有5中分类,决定胃具体的操作,如:++, ...
- STM32F103C8T6、STM32F103ZET6工程模板
STM32F103C8T6工程模板,推荐使用以下最新版本 最终版 2018 7 16 https://pan.baidu.com/s/1lIdZ2awus_quVu332RvJ6Q https:// ...