Python3基础 str find+index 是否存在指定字符串,有则返回第一个索引值
- Python : 3.7.0
- OS : Ubuntu 18.04.1 LTS
- IDE : PyCharm 2018.2.4
- Conda : 4.5.11
- typesetting : Markdown
code
coder@Ubuntu:~$ source activate py37
(py37) coder@Ubuntu:~$ ipython
Python 3.7.0 (default, Jun 28 2018, 13:15:42)
Type 'copyright', 'credits' or 'license' for more information
IPython 6.5.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: my_str = 'HELLOHELLO'
In [2]: # 存在,则返回首次出现的,第一个L的索引值
In [3]: my_str.find('LLO')
Out[3]: 2
In [4]: # 存在,则返回首次出现的,第一个L的索引值
In [5]: my_str.index('LLO')
Out[5]: 2
In [6]: # find找不到,则返回-1
In [7]: my_str.find('X')
Out[7]: -1
In [8]: # index找不到,则抛异常
In [9]: my_str.index('X')
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-9-03ca60cad0af> in <module>()
----> 1 my_str.index('X')
ValueError: substring not found
In [10]: exit
(py37) coder@Ubuntu:~$ source deactivate
coder@Ubuntu:~$
resource
- [文档] docs.python.org/3
- [规范] www.python.org/dev/peps/pep-0008
- [规范] zh-google-styleguide.readthedocs.io/en/latest/google-python-styleguide/python_language_rules
- [源码] www.python.org/downloads/source
- [ PEP ] www.python.org/dev/peps
- [平台] www.cnblogs.com
- [平台] gitee.com
Python具有开源、跨平台、解释型、交互式等特性,值得学习。
Python的设计哲学:优雅,明确,简单。提倡用一种方法,最好是只有一种方法来做一件事。
代码的书写要遵守规范,这样有助于沟通和理解。
每种语言都有独特的思想,初学者需要转变思维、踏实践行、坚持积累。
Python3基础 str find+index 是否存在指定字符串,有则返回第一个索引值的更多相关文章
- 指定字符串 s,返回 s 所有可能的子串,每个子串必须是一个回文(指顺读和倒读都一样的字符串)
Given a string s, partition s such that every substring of the partition is a palindrome Return all ...
- Python3基础 str translate 将指定字符转换成另一种特定字符
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- Python3基础 str split 用指定的字符将字符串分割
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- Python3基础 str endswith 是否以指定字符串结束
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- Python3基础 str 循环输出list中每个单词及其长度
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- Python3基础 str format 位置参数与关键字参数
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- Python3基础 str 通过拆分字符串与插入新的内容形成新的字符串
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- Python3基础 str while+iter+next 字符串的遍历
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- Python3基础 str swapcase 英文字母大小写反转
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
随机推荐
- Map集合遍历
Map<String,String> map = new HashMap<String, String>(); map.put("1","java ...
- 【Git 使用笔记】第二部分:基本命令 和 单分支开发
git 基本命令 git add . git commit -am "请填写你NB的备注" git fetch --all git fetch -p //如果远程分支删除了,本地 ...
- 2018/03/10 每日一个Linux命令 之 cksum
每日一个Linux命令 2018-03-10 Linux 命令 cksum cksum [文件] 今天楼下的一个大妈去世了,不仅感叹,现如今,真的和以前不一样了,楼上楼下都不知道住的是谁? cksu ...
- IDEA的快捷键和相关设置
快捷键 Shift + Shift: 查找一切 Alt + /: 代码提示(需要修改) Ctrl + Alt + F12: 打开文件所在磁盘位置 Alt + F12: 打开终端 Alt + Ins ...
- Git使用常见问题脚本
receive.denyCurrentBranch 这是由于git默认拒绝了push操作,需要进行设置,修改.git/config添加如下代码: [receive] denyCurrentBr ...
- android studio 布局
1) 可见(visible)XML文件:Android:visibility="visible"Java代码:view.setVisibility(View.VISIBLE); 2 ...
- 更新Newtonsoft.Json后报异常,未能加载文件或程序集“Newtonsoft.Json
未能加载文件或程序集“Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed”或它的某一个 ...
- vue-watch
<template> <div> <!-- 监听值的改变: --> <button class="th" @click="add ...
- 知道椭圆长轴,短轴长度,ab直线的长度知道且垂直于长轴。求ab的弧长。
1:知道椭圆长轴,短轴长度,ab直线的长度知道且垂直于长轴.求ab的弦长.: https://jingyan.baidu.com/article/a378c960a5af27b3282830e6.ht ...
- 使用idea maven开发spring boot 分布式开发入门
1:使用idea创建一个maven工程 bos2 2:删除bos2的src 文件夹,向pom.xml文件 中添加版本号 <packaging>pom</packaging> & ...