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
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