python中split方法用法分析

yipeiwu_com6年前Python基础

本文实例讲述了python中split方法用法。分享给大家供大家参考。具体分析如下:

split 是非常重要的字符串方法,它是join的逆方法,用来将字符串分割成序列

>>> '1+2+3+4+5'.split('+')
['1', '2', '3', '4', '5']
>>> 'usr/bin/env'.split('/')
['usr', 'bin', 'env']
>>> 'usr/bin/env'.split('/')
['usr', 'bin', 'env']
>>> '/usr/bin/env'.split('/')
['', 'usr', 'bin', 'env']
>>> 'using the default'.split()
['using', 'the', 'default']

如果不提供任何分隔符,程序会把所有空格作为分隔符

希望本文所述对大家的Python程序设计有所帮助。

相关文章

Python计算三角函数之asin()方法的使用

 asin()方法返回x的反正弦,以弧度表示。 语法 以下是asin()方法语法: asin(x) 注意:此函数是无法直接访问的,所以我们需要导入math模块,然后需...

Django与遗留的数据库整合的方法指南

Django的数据库层从Python代码生成SQL schemas—但是对于遗留数据库,你已经拥有SQL schemas. 这种情况,你需要为已经存在的数据表创建model. 为此,Dj...

python实现的简单RPG游戏流程实例

本文实例讲述了python实现的简单RPG游戏流程。分享给大家供大家参考。具体如下: #RPG rpg = True whp = 100 mahp = 100 hhp = 100 M...

Python函数的周期性执行实现方法

本文实例讲述了Python函数的周期性执行实现方法。分享给大家供大家参考,具体如下: 需要用到python的sched模块: #coding=utf-8 import time,sc...

django使用django-apscheduler 实现定时任务的例子

下载: pip install apscheduler pip install django-apscheduler 将 django-apscheduler 加到项目中settings...