#-*- coding:utf-8 -*-

strword = "i will fly with you , fly on the sky ."

#find
print(strword.find("fly")) #打印7 #find返回找到第一个字符串的下标,找不到返回-1 print("==rfind==") #rfind
print(strword.rfind("fly"))
#rfind 从后向前查找,找到返回下标,找不到返回-1 print("==index==") #index
print(strword.index("fly"))
#index 找到返回首字符的下标,找不到报错ValueError: substring not found print("==rindex==")
#rindex
print(strword.rindex("fly"))
#功能与rfind类似,返回值不同 print("==count==")
#count
print(strword.count("fly"))
#count 返回找到字符串的个数,找不到返回0 print("==replace==")
#replace
print(strword.replace("fly","xxx"))
#全文替换指定字符串,由于字符串属于不可变类型,所以replace()函数不会修改strword的值
#replace扩展 可以指定替换多少个,但是替换的顺序还是从前向后的
print(strword.replace("fly","xxx",1)) print("===split==")
#split
print(strword.split(" "))
#split 切割函数,按照指定字符切割字符串 word = "hello world" print("==capitalize==")
#capitalize
print(word.capitalize())
#字符串首单词的第一个字符大写 print("==title==")
print(word.title())
#title 字符串中每个单词首字母大写 print("==startswith==")
print(word.startswith("he"))
#startswith 是否以某字符串开头,是返回true,不是返回flase print("==endswith==")
print(word.endswith("ld"))
#endswith 判断以某字符串结尾,是返回true,不是返回flase nword = "A B C a b c"
print("==lower==")
print(nword.lower())
#lower 将所有英文字符转化成小写 print("==upper==")
#upper
print(nword.upper())
#upper 将所有的英文字符转化成大写

Python 字符串操作函数一的更多相关文章

  1. python——字符串操作函数

    字符串 join() map() split() rsplit() splitlines() partiton() rpartition() upper() lower() swapcase() ca ...

  2. Python 字符串操作函数二

    #-*- coding:utf-8 -*- line = "l want watch movie with you ." print(line.center(50)) print( ...

  3. Python中字符串操作函数string.split('str1')和string.join(ls)

    Python中的字符串操作函数split 和 join能够实现字符串和列表之间的简单转换, 使用 .split()可以将字符串中特定部分以多个字符的形式,存储成列表 def split(self, * ...

  4. python字符串操作实方法大合集

    python字符串操作实方法大合集,包括了几乎所有常用的python字符串操作,如字符串的替换.删除.截取.复制.连接.比较.查找.分割等,需要的朋友可以参考下:   #1.去空格及特殊符号 s.st ...

  5. Lesson12——NumPy 字符串函数之 Part1:字符串操作函数

    NumPy 教程目录 1 NumPy 字符串函数 以下函数用于对 dtype 为 numpy.string_ 或 numpy.unicode_ 的数组执行向量化字符串操作. 它们基于 Python 内 ...

  6. JavaScript中常见的字符串操作函数及用法

    JavaScript中常见的字符串操作函数及用法 最近几次参加前端实习生招聘的笔试,发现很多笔试题都会考到字符串的处理,比方说去哪儿网笔试题.淘宝的笔试题等.如果你经常参加笔试或者也是一个过来人,相信 ...

  7. Python 字符串操作

    Python 字符串操作(string替换.删除.截取.复制.连接.比较.查找.包含.大小写转换.分割等) 去空格及特殊符号 s.strip() .lstrip() .rstrip(',') 复制字符 ...

  8. 转:C语言字符串操作函数 - strcpy、strcmp、strcat、反转、回文

    转自:C语言字符串操作函数 - strcpy.strcmp.strcat.反转.回文 C++常用库函数atoi,itoa,strcpy,strcmp的实现 作者:jcsu C语言字符串操作函数 1. ...

  9. C语言的常用字符串操作函数(一)

    一直做的是单片机相关的程序设计,所以程序设计上更偏向底层,对于字符串的操作也仅限于液晶屏幕上的显示等工作,想提高下字符串操作的水平,而不是笨拙的数组替换等方式,翻看帖子发现C语言的字符串操作函数竟然这 ...

随机推荐

  1. 呃,如何使 .NET 程序,在 64位 系统 中,以 32位 模式运行。

    其实最简单的方法就是在解决方案中,把平台设为 x86 就好了哈~   但是今天遇到一个第三方的软件,它调用的一个 dll 是 32位 的,可能它没有测试过在 64位 系统下运行的情况,它在编译时是按默 ...

  2. apache-tomcat-7.0.53-windows-x86或者x64:出现错误提示:(Unable to open the service 'tomcat7)或者(Failed installing 'Tomcat7' service) tomcat7 %1 不是有效的 Win32 应用程序。

    具体 安装行动 :打开下令 行提醒 符窗口 => 进入Tomcat安装目次 ==> 进入bin目次 下==> 输入:service.bat install 即可而且tomcat_ho ...

  3. 【Android】1.2 创建Android模拟器

    分类:C#.Android.VS2015:  创建日期:2016-01-20 调试手机应用程序一般先用模拟器来实现,只是因为每次都发布到手机上调试太麻烦了.当应用程序在模拟器上调试没错后,再发布到手机 ...

  4. golang 解决 TCP 粘包问题

    什么是 TCP 粘包问题以及为什么会产生 TCP 粘包,本文不加讨论.本文使用 golang 的 bufio.Scanner 来实现自定义协议解包. 协议数据包定义 本文模拟一个日志服务器,该服务器接 ...

  5. what-is-a-closure

    https://stackoverflow.com/questions/36636/what-is-a-closure https://www.quora.com/What-are-upvalues- ...

  6. Cloud Resource

    Cloud Public Cloud Aliyun AWS Azure Cloud Stack SDN指南 DNS:Band Private Cloud DC/OS OpenStack Hybrid ...

  7. redhat7.2 安装docker

    # wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo # sed -i  ' ...

  8. [Windows Azure] Windows Azure Execution Models

    Windows Azure Execution Models Windows Azure provides different execution models for running applica ...

  9. Vue.js使用-http请求

    Vue.js使用-ajax使用 1.为什么要使用ajax 前面的例子,使用的是本地模拟数据,通过ajax请求服务器数据. 2.使用jquery的ajax库示例 new Vue({ el: '#app' ...

  10. mysql--Ubuntu下设置MySQL字符集为utf8

    1.mysql配置文件地址/etc/mysql/my.cnf 2.在[mysqld]在下方添加以下代码[mysqld]init_connect='SET collation_connection = ...