一.字符串方法总结:

1.查找:

find(rfind)、index(rindex)、count

2.变换:

capitalize、expandtabs、swapcase、title、lower、upper、strip(rstrip/lstrip)(析取)、zfill

3.分行和折行:

join、split(rsplit)、splitlines、partion(rpartion)

4.替换和高级替换:

replace、translate、format

5.位置:

center、rjust(ljust)、zfill(左边0填充)

5.is测试:

startswith(endswith)、isalnum、isalpha、isdigit、islower、isupper、isspace、istitle

二.字典方法总结:

字典的键值只能是不可变对象。

1.获取:

get、setdefault(获取或创建)、items、keys、values、

2.创建:

copy(浅复制)、fromkeys、update(更新)

3.删除:

clear、pop、popitem

三. 列表方法总结:

1.增加:

append、extend、insert、、

2.删除:

pop、remove、

3.排序VS查找VS统计:

sort、reverse、index、count、

四.可变集合set方法总结:

1.标准操作:

difference(差)、intersection(交)、union(并)、symmetric_difference(对称差)、isdisjoint、issubset、issuperset、

2.增加:

add

3.更新:

update(t) t可以是任意的可迭代类型 ,还有一些差更新difference_update,对称差symmetric_difference更新,intersection_difference交更新

4.删除:

clear、discard、pop、remove(若无返回KeyError)

str = 'hello aaron'

strA = 'hello agu AARON'

str.capitalize()  # 字符串首字母大写。 输出 'Hello aaron'

str.title()  # 每个单词的首字母都大写。 输出 'Hello Aaron'

str.upper()  # 每个字符都大写。 输出 'HELLO AARON'

strA.lower()  # 每个字符都小写。 输出 'hello agu aaron'

strA.swapcase()  #大小写转换。 输出 'HELLO AGU aaron'

str.center(14)  #字符串居中不够14个字符的前后补空格(先后再前)。输出 ' hello aaron '

str.ljust(12)  #左对齐不够12个字符的右补空格。 输出 'hello aaron '

str.rjust(12)  #右对齐不够12个字符的左补空格。 输出 ' hello aaron'

str.ljust(20).rstrip()  #rstrip 剥除字符串右边所有空格。 输出 'hello aaron'

str.rjust(20).lstrip()  #左剥除

str.center(20).strip()  #前后都剥

strN = ' '

strN.isspace()  #是否所有字符为空格。 输出 True

strTab = 'HELLO\tworld'

python字符串实例_python 字符串内置方法实例相关推荐

  1. Python基础总结之常用内置方法总结

    文章目录 前言 1.str 1.1.内置方法: 1.2.常用的内置方法 1.3.String模块的一些方法 2.list 2.1.内置方法 2.2.常用内置方法 3.tupple 3.1.内置方法 3 ...

  2. python常用内置模块-Python之OS模块常用内置方法汇总

    OS模块的常用内置方法 chdir修改当前工作目录到指定目录 Change the current working directory to the specified path. chmod修改一个 ...

  3. python反射和高阶内置方法

    1.isinstance:判断对象和类的关系 #判断结果返回bool类型 class A:pass class B(A):pass a = A() print(isinstance(a,A)) #Tr ...

  4. python 面向对象_多态、内置方法、反射

    内容: 1.接口思想 2.抽象类思想 3.多态 4.内置方法 5.反射 1.接口思想 建立关联的桥梁,方便管理代码 接口类:用来定义功能的类,位继承它的子类提供功能 该类的功能方法一般不需要实现体,实 ...

  5. python discuz搜索api_Django用内置方法实现简单搜索功能的方法

    Model中分别提供了filter方法和icontains方法实现简单的搜索功能. html页面中实现搜索框 模板api_test_manage.html中增加以下内容 {% csrf_token % ...

  6. 18.Python字符串类型及常用内置方法

    文章目录 1.字符串 2.字符串的定义 3.打印引号 4.类型转换 5.索引取值 6.遍历 7.长度统计 8.字符串复制与拼接 8.1字符串的复制 8.2加号拼接 8.3join拼接 8.4字符截取拼 ...

  7. python max函数_Python max内置函数详细介绍

    Python max内置函数 max(iterable, *[, key, default]) max(arg1, arg2, *args[, key]) Return the largest ite ...

  8. python bool类型_Python 的内置数值类型

    Python 是一种敏捷的.动态类型化的.极富表现力的开源编程语言,可以被自由地安装到多种平台上.Python 代码是被解释的.如果您对编辑.构建和执行循环较为熟悉,则 Python 代码对您来说更简 ...

  9. 调用外部程序处理文件_Python使用内置方法、模块调用外部命令

    导读 Python内置调用外部命令: os.system os.popen os.popen2 os.popen3 os.popen4 commands模块 subprocess模块 在Python3 ...

  10. python迭代器使用_python迭代器的使用方法实例

    什么是迭代器?迭代器是带有next方法的简单对象,当然也要实现__iter__函数.迭代器能在一序列的值上进行迭代,当没有可供迭代时,next方法就会引发StopIteration 的异常.pytho ...

最新文章

  1. R 语言爬虫 之 cnblog博文爬取
  2. 140个Google面试问题
  3. Knative 基本功能深入剖析:Knative Eventing 之 Sequence 介绍
  4. PIE SDK影像坏线修复
  5. 2.6 mailx邮件
  6. kafka突然无法消费topic
  7. SAP CRM的IOITF框架:Individual Object Integration Framework
  8. java 文件下载漏洞,文件上传和下载漏洞
  9. 腾讯和阿里巴巴考虑互相开放生态,是真开放还是新的垄断?
  10. 字符串,数组,定时器,form
  11. ie11浏览器可以下载java吗_如何卸载IE11? 如何安装低版本的IE浏览器?
  12. 算法与数据结构10.1
  13. 【Oracle】数据库热备
  14. Android 最常用的设计模式十 安卓源码分析——策略模式(Strategy)
  15. 如何使用hMailServer+云服务器搭建个人邮箱
  16. 500元大洋学习SEO
  17. Linux应该怎么快速学习?首推这份全网爆火的“Linux速成笔记”,阿里架构师都在用它!
  18. Android 音视频深入 十八 FFmpeg播放视频,有声音(附源码下载)
  19. 计算机桌面整理,电脑桌面太乱了怎么整理?
  20. 数据库系统概论(王珊,萨师煊版)范式之前要点一览(简略)

热门文章

  1. Redis由分布式锁造成的重大事故
  2. mongoTemplate.aggregate() 聚合查询,关联查询
  3. Go Slice 高级实践
  4. Spring Session
  5. 如何去掉word中的回车符??
  6. android第一行代码-6.自定义控件的实现
  7. SQL Server 2012 自动增长列,值跳跃问题
  8. makefile--编译出现,未定义的字符
  9. 新建SVN Repository
  10. 获取微信公众平台的access_token