美文网首页
2018-12-13 版本号比较函数,format, split

2018-12-13 版本号比较函数,format, split

作者: 七月那个阿瓜呀 | 来源:发表于2018-12-13 20:48 被阅读3次

1. Python版本号比较函数LooseVersion和StrictVersion

2. Python format 格式化函数

3. Python split()方法

split() 方法语法:

str.split(str="", num=string.count(str))

str -- 分隔符,默认为所有的空字符,包括空格、换行(\n)、制表符(\t)等。
num -- 分割次数
返回 分割后的字符串列表

应用:

#1.按照换行符'\n'来分割
#!/usr/bin/python

str = "Line1-abcdef       Line2-abc \nLine4-abcd"
print (str.split('\n'))
print (str.split(' ', 1 ))

返回:
['Line1-abcdef Line2-abc ', 'Line4-abcd']
['Line1-abcdef', ' Line2-abc \nLine4-abcd']

#2. 按照空格' '来分割
#!/usr/bin/python

str = "Line1-abcdef       Line2-abc \nLine4-abcd"
print (str.split(' '))
print (str.split(' ', 1 ))

返回:
['Line1-abcdef', '', '', '', '', '', '', 'Line2-abc', '\nLine4-abcd']
['Line1-abcdef', ' Line2-abc \nLine4-abcd']

相关文章

  • 2018-12-13 版本号比较函数,format, split

    1. Python版本号比较函数LooseVersion和StrictVersion 2. Python form...

  • split()函数的用法

    函数:split() Python中有split()和os.path.split()两个函数,具体作用如下:spl...

  • Python中的split()函数的用法

    函数:split() Python中有split()和os.path.split()两个函数,具体作用如下: sp...

  • 老刘教你学python

    05 如何将多个值分割后转为整型? 使用map函数结合split()函数 split 函数 是指分割函数的意思,...

  • MySQL: 日期相关处理

    MySQL 日期、时间转换函数: 1. date_format(date,format), time_format...

  • format函数

    自python2.6开始,新增了一种格式化字符串的函数str.format(),可谓威力十足。那么,他跟之前的%型...

  • format()函数

    python中format函数用于字符串的格式化 通过关键字 通过位置 format()方法格式控制 format...

  • format函数

    Python2.6 开始,新增了一种格式化字符串的函数 str.format(),它增强了字符串格式化的功能。 基...

  • format 函数

    题目为 解题思路 运行结果

  • php chunk_split函数怎么用?

    chunk_split()函数在PHP中的一个内置函数,语法为string chunk_split($string...

网友评论

      本文标题:2018-12-13 版本号比较函数,format, split

      本文链接:https://www.haomeiwen.com/subject/btcihqtx.html