•        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. RuntimeError: Object: Could not open SDE workspace

    客户环境,linux 终端里,使用arcpy.ListUsers() 报错:RuntimeError: Object: Could not open SDE workspace 经检查,问题在于 该机 ...

  2. SVN版本控制系统搭建(结合http服务)

    SVN版本控制服务器搭建 Svn(subversion)是一个开源代码管理的控制系统,用来管理和存储开发的源代码,基于C/S模式.可以单独提供服务,也可以结合http服务来实现. 运行方式  运行端口 ...

  3. Java List <T> T[] toArray(T[] a) implementation

    Like the toArray() method, this method acts as bridge between array-based and collection-based APIs. ...

  4. MySQL check table/optimize table/analyze table/REPAIR TABLE

    MySQL check table/optimize table/analyze table/REPAIR TABLE 转自:https://www.cnblogs.com/datastack/p/3 ...

  5. 12 jmeter性能测试实战--web程序

    项目背景 项目:XX网站环境:Windows需求:并发登录的性能测试场景:1s增加2个线程,运行2000次(线程数20,Ramp-Up seconds 10,循环次数100).分别看20.40.60并 ...

  6. 12.预处理数据的方法总结(使用sklearn-preprocessing)

    https://blog.csdn.net/sinat_33761963/article/details/53433799

  7. Y2K Accounting Bug(poj2586)

    题意: 有一个公司由于某个病毒使公司赢亏数据丢失,但该公司每月的 赢亏是一个定数,要么一个月赢利s,要么一月亏d.现在ACM只知道该公司每五个月有一个赢亏报表,而且每次报表赢利情况都为亏.在一年中这样 ...

  8. [LeetCode] 589. N-ary Tree Preorder Traversal_Easy

    Given an n-ary tree, return the preorder traversal of its nodes' values. For example, given a 3-ary  ...

  9. [LeetCode] 176. Second Highest Salary_Easy tag: SQL

    Write a SQL query to get the second highest salary from the Employee table. +----+--------+ | Id | S ...

  10. Oracal 11 g 数据库安装

    一:下载安装包 http://www.oracle.com/technetwork/cn/database/enterprise-edition/downloads/112010-win64soft- ...