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('.')#可传参去掉字符串前 ...
随机推荐
- CentOS7.5最小化安装之后的配置
我是最小化安装的,安装了之后很多基本使用配置没有,接下来要做一些配置,如网络之类的,使系统可用. 1.使命令分页显示(1页显示不不下,又不能上翻页) xxx | more 2.查看系统安装了哪些软件包 ...
- generate failed: Cannot resolve classpath entry: mysql-connector-java-5.1.38.jar
详细错误及处理方法如下: [ERROR] Failed to execute goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3 ...
- 留言板(初学者使用js实现)
代码如下: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...
- vue数组赋值
在使用vue开发移动端项目过程中,统一数组在对多个变量赋值时:希望一个数组的改变不影响另外一个数组,此时可以使用如下方式实现: let arr = [] let a1 = JSON.parse(JSO ...
- 【python 虚拟环境 virtualenv的配置】
该目录内生成一个虚目录: #运行activcate下的shell脚本,激活虚拟环境 #pip python包管理器
- PAT (Basic Level) Practice (中文)1001
1001 害死人不偿命的(3n+1)猜想 (15 分) 卡拉兹(Callatz)猜想: 对任何一个正整数 n,如果它是偶数,那么把它砍掉一半:如果它是奇数,那么把 (3n+1) 砍掉一半.这样一直反复 ...
- C语言/C++对编程学习的重要性!
C语言是面向过程的,而C++是面向对象的 C和C++的区别: C是一个结构化语言,它的重点在于算法和数据结构.C程序的设计首要考虑的是如何通过一个过程,对输入(或环境条件)进行运算处理得到输出(或实现 ...
- Gulp的安装配置过程和一些小坑
谈谈gulp. 项目尾声,老师叫我去熟悉一下grunt前端自动化工具,第一次知道这种东西,我就查各种资料啊,发现grunt已经‘过时’了,大家都用gulp和webpack.我当然选择了配置最简单的gu ...
- React with webpack
//entry.js require("!style!css!./style.css"); require("./hello.jsx"); // documen ...
- Oracle入门第五天(上)——数据库对象之视图
一.概述 1.什么是视图(VIEW) 视图 从表中抽出的逻辑上相关的数据集合(是一张虚表). 2.为什么使用视图 1.控制访问 2.简化查询 3.视图的分类 二.视图管理 1.创建视图 CREATE ...