•        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 是否存在指定字符串,有则返回第一个索引值的更多相关文章

  1. 指定字符串 s,返回 s 所有可能的子串,每个子串必须是一个回文(指顺读和倒读都一样的字符串)

    Given a string s, partition s such that every substring of the partition is a palindrome Return all ...

  2. Python3基础 str translate 将指定字符转换成另一种特定字符

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  3. Python3基础 str split 用指定的字符将字符串分割

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  4. Python3基础 str endswith 是否以指定字符串结束

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  5. Python3基础 str 循环输出list中每个单词及其长度

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  6. Python3基础 str format 位置参数与关键字参数

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  7. Python3基础 str 通过拆分字符串与插入新的内容形成新的字符串

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  8. Python3基础 str while+iter+next 字符串的遍历

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  9. Python3基础 str swapcase 英文字母大小写反转

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

随机推荐

  1. 使用代理*** and kubeadm init错误

    没有代理 可申请AWS免费账户,创建EC2实例,搭建Shadowsocks服务器. 配置代理客户端 参考链接:https://www.zybuluo.com/ncepuwanghui/note/954 ...

  2. IOS UIView圆角,阴影,边框,渐增光泽

    圆角 sampleView.layer.cornerRadius = 2.5; // 圓角的弧度sampleView.layer.masksToBounds = YES; 阴影 sampleView. ...

  3. -bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory

    本人使用mac系统,命令行工具使用的iterm2,登录自己的云主机的时候 每次都要提示如下错误 -bash: warning: setlocale: LC_CTYPE: cannot change l ...

  4. curl获取公网IP地址

    curl ip.cn curl cip.cc https://blog.csdn.net/orangleliu/article/details/51994513 https://blog.csdn.n ...

  5. Closest Common Ancestors---poj1470(LCA+离线算法)

    题目链接:http://poj.org/problem?id=1470 题意是给出一颗树,q个查询,每个查询都是求出u和v的LCA:    以下是寻找LCA的预处理过程: void LCA(u){ f ...

  6. 洛谷P4437 排列 [HNOI/AHOI2018] 贪心

    正解:贪心 解题报告: 传送门! 发现做题龟速,,,所以懒得写题目大意辣自己get一下QAQ 首先看到ai<=n,又当ai=j时j在i的前面,所以就变成对于每个点i有一个约束,即要求第ai个节点 ...

  7. 【代码备份】ZJ10086测试环境成功代码备份

    vuser_init(){        lr_start_transaction("login"); web_url("101.132.17.138",   ...

  8. 16 jmeter中的监听器以及测试结果分析

    常用监听器 断言结果.查看结果树.聚合报告.Summary Report.用表格查看结果.图形结果.aggregate graph等 指标分析 -Samples:本次场景中一共完成了多少请求-Aver ...

  9. 【剑指offer】跳台阶

    一.题目: 一只青蛙一次可以跳上1级台阶,也可以跳上2级.求该青蛙跳上一个n级的台阶总共有多少种跳法(先后次序不同算不同的结果). 二.思路: 同斐波那契数列. 三.代码:    

  10. CMSPRESS-PHP无限级分类2

    原文章地址:http://www.thinkphp.cn/code/170.html 超级无限分类 使用简单 效率极高 核心代码10行不到 另外 求这个分类的不足,和更高效简单的无限分类方法 ^_^ ...