字符串一个最重要的特性就是不可修改。

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【基础】-字符串 常用的方法的更多相关文章

  1. Python语言学习:字符串常用的方法

    python字符串常用的方法 1. find( ):在字符串中搜索指定的值并返回它被找到的位置,如果没有找到,则返回-1 string.find(value,start,end) #value:必需, ...

  2. python字符串常用的方法解析

    这是本人在学习python过程中总结的一些关于字符串的常用的方法. 文中引用了python3.5版本内置的帮助文档,大致进行翻译,并添加了几个小实验. isalnum S.isalnum() -> ...

  3. python 基础———— 字符串常用的调用 (图)

    Python 常用的 字符串调用方法 这里用到了pycharm ( 使用Python  有力的工具) 下载地址https://www.jetbrains.com/pycharm/download/#s ...

  4. js基础-字符串常用属性合集

    /*   *   * 实例方法---->必须要通过new的方式创建的对象(实例对象)来调用的方法   * 静态方法---->直接通过大写的构造函数的名字调用的方法(直接通过大写的对象名字调 ...

  5. Python3基础笔记--常用模块

    目录: 参考博客:Python 之路 Day5 - 常用模块学习 Py西游攻关之模块 一.time模块 二.random模块 三.os模块 四.sys模块 五.hashlib模块 六.logging模 ...

  6. js入门之字符串常用的方法

    一. 概念理解基本包装类型 1. 基本包装类型 三种基本包装类型 String var s = new String('123dddd'); Number Boolean 简单类型没有方法和属性 之所 ...

  7. js字符串常用判断方法

    转自:http://blog.sina.com.cn/s/blog_6819fa800100j5t6.html 一.方法介绍 function obj$(id)                     ...

  8. JS操作字符串常用的方法

    JS操作String对象的方法 charAt(index):返回指定索引处的字符串charCodeAt(index):返回指定索引处的字符的Unicode的值concat(str1,str2,...) ...

  9. python之字符串常用的方法

    1. 去掉空格或换行符 s='. hello .world .\n' new_s = s.strip()#默认去掉字符串前后的空格和换行符 new_s = s.strip('.')#可传参去掉字符串前 ...

随机推荐

  1. Ionic3项目实践记录

    Ionic3首次项目实践记录 标签(空格分隔): Angular Ionic Ionic3踩坑 1. 路由懒加载(lazy load) 如果设置了懒加载,就必须全部懒加载(包括TabsPage),否则 ...

  2. MySql 5.7.21免安装版本win10下的配置

    1.解压到想要安装的位置,创建my.ini文件 my.ini的内容如下 [mysql] # 设置mysql客户端默认字符集 default-character-set=utf8 [mysqld] #设 ...

  3. 15JavaScript switch语句

    1.JavaScript switch 语句 使用 switch 语句来选择要执行的多个代码块之一. 语法: switch(n) { case 1: 执行代码块 1 break; case 2: 执行 ...

  4. Python - 入门基础(一)

    1.解释器路径 #!/usr/bin/env python 2.编码 # -*- coding:utf8 -*- 1.ascill ---00000000  (8个位表示) 缺点:表示不了英文 2.u ...

  5. 深入了解Linux(一)

    Linux的各个文件夹 每次当我使用linux的时候我都被一个个文件夹整懵逼,那么多文件夹到底是怎么分类的呢.今天终于有时间好好整理一下 /boot: 引导文件存放目录,内核文件(vmlinuz),引 ...

  6. HxUtils: 批量转换换行符,print2to3

    在 windows 和 linux 系统,换行符有时需要转换,其代码文件 HxUntils.py 如下: ''' HxUtils.py 2018 by x01 ''' import os, sys d ...

  7. Linux下C语言编译的问题

    在Linux下编程发现一个诡异的现象,就是在链接一个静态库的时候总是报错,类似下面这样的错误: (.text+0x13): undefined reference to `func' 关于undefi ...

  8. C语言用一级指针处理字符串的反思

    1.一级指针处理字符串的常见方式 如果使用单个指针,不方便对字符串本身进行操作,只适合遍历. 使用两个指针, 两个指针和字符串大致有两个常见处理方式: (1)两个指针从字符串首部开始向后移动,同时处理 ...

  9. js判断两个日期是否相等的方法

    今天优化代码的时候,发现一个问题,js比较日期是否相等时,我用==去比较,发现两个时间不相等但是运行结果却是true,然后去百度了下发现oldStartTime, startTime都是对象,类型为引 ...

  10. Creating Isomorphic Apps with Node.js, React, and Express

    In this article, we’re going to use following software: React: the UI framework that can rendered on ...