python split函数

Python split()通过指定分隔符对字符串进行切片,如果参数num 有指定值,则仅分隔 num 个子字符串

current_month = "2013-01-02"
years = current_month.split("-", 1)
month = current_month.split("-")[1]
print(years)
print(month)

输出结果
['2013', '01-02']
01

 

posted on 2015-10-21 15:47  红豆·绿豆  阅读(178)  评论(0编辑  收藏  举报

导航