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
原文地址:https://www.cnblogs.com/yjw9520/p/4898018.html