•        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]: content = "hello,world" In [2]: hello_str = content.split(",") In [3]: hello_str
Out[3]: ['hello', 'world'] In [4]: hello_str,world_str = content.split(',', 1) In [5]: hello_str
Out[5]: 'hello' In [6]: world_str
Out[6]: 'world' In [7]: exit
(py37) coder@Ubuntu:~$ source deactivate
coder@Ubuntu:~$

more knowledge

split(self, /, sep=None, maxsplit=-1)
Return a list of the words in the string, using sep as the delimiter string. sep
The delimiter according which to split the string.
None (the default value) means split according to any whitespace,
and discard empty strings from the result.
maxsplit
Maximum number of splits to do.
-1 (the default value) means no limit.

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 = "hello,world,hello,world" In [2]: my_str.split(',', 1)
Out[2]: ['hello', 'world,hello,world'] In [3]: my_str.split(',', 2)
Out[3]: ['hello', 'world', 'hello,world'] In [4]: my_str.split(',', 3)
Out[4]: ['hello', 'world', 'hello', 'world'] In [5]: my_str.split(',', 4)
Out[5]: ['hello', 'world', 'hello', 'world'] In [6]: 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 split 用指定的字符将字符串分割的更多相关文章

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

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

  2. Lua 用指定字符或字符串分割输入字符串,返回包含分割结果的数组

    // 用指定字符或字符串分割输入字符串,返回包含分割结果的数组 // @function [parent=#string] split // @param string input 输入字符串 // ...

  3. python基础--str.split

    string = 'This +is -a /string' process = string.split('-') process1 = string.split('-')[-1]#-1和-2可能存 ...

  4. Python使用split使用多个字符分隔字符串

    Python的str类有split方法,但是这个split方法只能根据指定的某个字符分隔字符串,如果要同时指定多个字符来分隔字符串,该怎么办呢? 幸运的是python的re模块中提供的split方法可 ...

  5. Python3基础 使用 in notin 查询一个字符是否指定字典的键或者值

    镇场诗: 诚听如来语,顿舍世间名与利.愿做地藏徒,广演是经阎浮提. 愿尽吾所学,成就一良心博客.愿诸后来人,重现智慧清净体.-------------------------------------- ...

  6. Python3基础 str for 输出字符串中的每个字符

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

  7. Python3基础 str find+index 是否存在指定字符串,有则返回第一个索引值

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

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

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

  9. Python3基础知识之日期时间与字符的转换

    问题:“猿类”们都知道,编程中都会涉及到日期.时间类型与字符串类型的转换.不同场景,需要将字符串格式转换为日期类型:也需要将日期类型转换为字符串格式. 目标: 学习和积累python中time和dat ...

随机推荐

  1. HTML 标签大全及属性

    基本结构标签: <HTML>,表示该文件为HTML文件 <HEAD>,包含文件的标题,使用的脚本,样式定义等 <TITLE>---</TITLE>,包含 ...

  2. Cable master---poj1064(二分|卡精度)

    题目链接:http://poj.org/problem?id=1064 题意:有n条绳子,长度为Li,现在从这n条绳子中切割出K条相等的绳子,问切割出来的这k条绳子的最大长度为多少: 二分判断即可: ...

  3. CentOS网卡配置大全

    持续更新中... 1.配置机器名 2.配置网卡属性 3.问题解决 3.1解决网卡经常需要手动重连问题 vi /etc/sysconfig/network-scripts/ifcfg-ens33 把ON ...

  4. python 全局变量引用与修改

    一.引用 使用到的全局变量只是作为引用,不在函数中修改它的值的话,不需要加global关键字.如: #! /usr/bin/python a = 1 b = [2, 3] def func(): if ...

  5. sql server 2005 使用Log Explorer查看和恢复数据

    使用Log Explorer查看和恢复数据    Log Explorer 4.1.可用于SQL Server2005的日志查看工具   下载地址: http://download.csdn.net/ ...

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

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

  7. 万恶之源 - Python初识函数

    什么是函数 我们目前为止,已经可以完成一些软件的基本功能了,那么我们来完成这样一个功能:约x pint("拿出手机") print("打开陌陌") print( ...

  8. 人活着系列之开会(Floy)

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2930 题意:所有点到Z点的最短距离.因为岛名由 ...

  9. pod 的warning一定要注意消除,要不然你的pod配置有问题无法导入

    and the CHANGELOG for this version http://git.io/BaH8pQ. Downloading dependencies Using BlocksKit (2 ...

  10. jmeter Bean Shell的使用(二)

    BeanShell的用法 在此介绍下BeanShell PreProcessor的用法,其它的beahshell可以类推.在此我们使用beahshell调用自己写的工具类,工具类实现了密码的加.解密功 ...