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 ...
随机推荐
- django中admin的使用
转载网址:https://www.cnblogs.com/wumingxiaoyao/p/6928297.html Django自带的后台管理是Django明显特色之一,可以让我们快速便捷管理 ...
- BigDecimal精度与相等比较的坑
先想一下,创建BigDecimal对象的时候一般是怎么创建的? new一个,传进去值 BigDecimal.valueOf方法,传进去值 作为一个数字类型,经常有的操作是比较大小,有一种情况是比较是否 ...
- Rikka with Sequence---hdu5828(区间更新与查找 线段树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5828 给你n个数,m个操作,操作k,l,r, k=1时 区间[l,r]每个数加x: k=2时,区间[l ...
- mysql 权限管理 对所有库 所有表 授权 *.*
对miek这个账号localhost 授予了所有库,所表的select权限 mysql> grant select on *.* to 'mike'@'localhost'; Query OK, ...
- 网络密钥交换协议——Diffie-Hellman
Diffie-Hellman算法是一种交换密钥的算法. 它是眼下比較经常使用的密钥交换算法. 这样的算法的优点是能让两台计算机在不安全的网络环境中完毕密钥的交换. 下面是整个算法的过程.当中红色字体表 ...
- 浅析I/O处理过程与存储性能的关系
浅析I/O处理过程与存储性能的关系 https://community.emc.com/docs/DOC-28653 性能”这个词可以说伴随着整个IT行业的发展,每次新的技术出现,从硬件到软件大多数情 ...
- react.js 之 create-react-app 命令行工具系统讲解
react.js 教程之 create-react-app 命令行工具系统讲解 快速开始 npm install -g create-react-app create-react-app my-app ...
- python2与python3之间的主要区别
python2与python3之间的主要区别 print py2:print语句,语句就意味着可以直接跟要打印的东西,如果后面接的是一个元组对象,直接打印 py3:print函数,函数就以为这必须要加 ...
- poj2524(简单并查集)
#include <iostream>#include <stdio.h>#include <string.h>#include <stdlib.h>u ...
- SDUT2826:名字的价值
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2806 名字的价值 Time Limit: 10 ...