Python3基础 str split 用指定的字符将字符串分割
- 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 用指定的字符将字符串分割的更多相关文章
- Python3基础 str translate 将指定字符转换成另一种特定字符
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- Lua 用指定字符或字符串分割输入字符串,返回包含分割结果的数组
// 用指定字符或字符串分割输入字符串,返回包含分割结果的数组 // @function [parent=#string] split // @param string input 输入字符串 // ...
- python基础--str.split
string = 'This +is -a /string' process = string.split('-') process1 = string.split('-')[-1]#-1和-2可能存 ...
- Python使用split使用多个字符分隔字符串
Python的str类有split方法,但是这个split方法只能根据指定的某个字符分隔字符串,如果要同时指定多个字符来分隔字符串,该怎么办呢? 幸运的是python的re模块中提供的split方法可 ...
- Python3基础 使用 in notin 查询一个字符是否指定字典的键或者值
镇场诗: 诚听如来语,顿舍世间名与利.愿做地藏徒,广演是经阎浮提. 愿尽吾所学,成就一良心博客.愿诸后来人,重现智慧清净体.-------------------------------------- ...
- Python3基础 str for 输出字符串中的每个字符
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- Python3基础 str find+index 是否存在指定字符串,有则返回第一个索引值
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基础知识之日期时间与字符的转换
问题:“猿类”们都知道,编程中都会涉及到日期.时间类型与字符串类型的转换.不同场景,需要将字符串格式转换为日期类型:也需要将日期类型转换为字符串格式. 目标: 学习和积累python中time和dat ...
随机推荐
- Alpine Linux
Alpine Linux Docker镜像基于Alpine Linux操作系统,后者是一个面向安全的轻型Linux发行版.不同于通常Linux发行版,Alpine Linux采用了musl libc和 ...
- rank() over,dense_rank(),row_number() 的区别
转自:https://jingyan.baidu.com/article/597035521ff2ec8fc107404b.html rank() over是的作用是查出指定条件后进行一个排名,但是有 ...
- Ubuntu安装mysql及设置远程访问方法
ubuntu上安装mysql非常简单只需要几条命令就可以完成. 1. sudo apt-get install mysql-server 2. apt-get isntall mysql-clie ...
- vue.set的用法
Vue.set(this.food,'count',1) //就是给this.food里面添加一个count的属性,并且赋值为1
- 简单mysql常用命令
在命令行 输入 mysql -uroot -p123456 (-u账号 -p密码)登入mysql服务器 1.设置mysql密码set password for 'root'@'localhost' = ...
- POJ3009:Curling 2.0(dfs)
http://poj.org/problem?id=3009 Description On Planet MM-21, after their Olympic games this year, cur ...
- 查看项目中的laravel的版本
方法1: 使用php artisan --version 方法2: 在项目文件中找vendor\laravel\framework\src\Illuminate\Foundation\Applicat ...
- 蒙特卡洛模拟(Monte Carlo simulation)
1.蒙特卡罗模拟简介 蒙特卡罗模拟,也叫统计模拟,这个术语是二战时期美国物理学家Metropolis执行曼哈顿计划的过程中提出来的,其基本思想很早以前就被人们所发现和利用.早在17世纪,人们就知道用事 ...
- GNS3的使用2
IDE值没算好,巨卡.重新安装,重新算值.速度快了不少 IDE值:选出现次数多,并且数字大的 2960的选256M 另外加了2个模拟器:ASA防火墙.juniper路由器
- Hive学习笔记:基础语法
Hive基础语法 1.创建表 – 用户表 CREATE [EXTERNAL外部表] TABLE [IF NOT EXISTS 是否存在] HUserInfo ( userid int comment ...