今天在复习基本数据类型——字符串的时候,有一点想法,总结一下:

字符串的定义:字符串是一个有序的字符集合,用于存储和表示基本的文字信息,用‘,“,‘’‘括起来的称之为字符串。

字符串的操作有很多种,比如索引.index(),去除.strip(),替换.replace(),切片等等。

这其中,特地取出.index()和.find()出来说明,以表区别:

首先,来官方解释:

    S.index(sub[, start[, end]]) -> int

    Like S.find() but raise ValueError when the substring is not found.
    S.index(sub[, start[, end]]) -> int

    Like S.find() but raise ValueError when the substring is not found.
S.find(sub[, start[, end]]) -> int

Return the lowest index in S where substring sub is found,
such that sub is contained within S[start:end]. Optional
arguments start and end are interpreted as in slice notation.

Return - on failure.

可以看到S.index()与S.find()类似,不过索引字符串中的子串没找到会报错。

而S.find()在找不到substring时,不会报错,而会返回-1

总结:

s.index(x):返回字符串中出现x的最左端的索引值,如果不在则抛出valueError异常

s.find(x) :返回字符串中出现x的最左端字符的索引值,如果不在则返回-1

最新文章

  1. openresty 前端开发入门六之调试篇
  2. LSMW批处理工具操作手册
  3. C# final project
  4. JS添加MD5,JS提示框
  5. 那些Android中的性能优化
  6. iOS设计模式之观察者模式
  7. oracle数据库常用SQL语句
  8. Git (2)
  9. kissy小记
  10. red hat 6.5 红帽企业Linux.6.5 yum This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. 解决办法
  11. vim的tab键设定
  12. shell 学习四十五天---xargs
  13. C#while死循环时候cpu占用比例大
  14. 每天一套题打卡|河南省第十一届ACM/ICPC
  15. maven 在clean package时,出现:找不到符号 [ERROR] 符号: 方法 sqlDdlFilter(java.lang.String) 解决办法
  16. 关于surface gradient
  17. nginx反向代理中proxy_set_header 运维笔记
  18. HashMap 和 HashTable 的区别
  19. Android-WebView加载网页(new WebView(this)方式)
  20. 堪称最好的A*算法(转)

热门文章

  1. windows下Perl如何读取大文件的最后一行(总结)
  2. 移动元素时,translate要比margin好
  3. js 函数里的 this
  4. I.MX6 support eMMC 5.0
  5. HDU - 6098:Inversion(暴力均摊)
  6. hibernate的级联(hibernate注解的CascadeType属性)
  7. 使用OpenCV对图像进行缩放
  8. Doxygen详细介绍
  9. sqlalchemy的缓存和刷新
  10. hadoop复合键排序使用方法