鱼C论坛

 找回密码
 立即注册
查看: 2230|回复: 3

python 第31课动动手0答案疑问

[复制链接]
发表于 2016-2-21 15:40:33 | 显示全部楼层 |阅读模式
1鱼币
(role, line_spoken) = each_line.split(':', 1)  中的 1 的含义是什么[index]

最佳答案

查看完整内容

help(str.split) Help on method_descriptor: split(...) S.split(sep=None, maxsplit=-1) -> list of strings Return a list of the words in S, using sep as the delimiter string. If maxsplit is given, at most maxsplit splits are done. If sep is not specified or is None, any whitespace string is a separator and empty strings are removed from the result. split是按 ...
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2016-2-21 15:40:34 | 显示全部楼层
help(str.split)
Help on method_descriptor:

split(...)
    S.split(sep=None, maxsplit=-1) -> list of strings
   
    Return a list of the words in S, using sep as the
    delimiter string.  If maxsplit is given, at most maxsplit
    splits are done. If sep is not specified or is None, any
    whitespace string is a separator and empty strings are
    removed from the result.
split是按第一个参数(你这是:)分割字符串  第2个参数是分割几次

  1. s="1:2:3"
  2. (a, b) = s.split(':',1)

  3. print(a)
  4. print(b)

  5. (a, b,c) = s.split(':',2)

  6. print(a)
  7. print(b)
  8. print(c)
复制代码

评分

参与人数 1荣誉 +1 鱼币 +1 收起 理由
伙夫和甲鱼 + 1 + 1 感谢楼主无私奉献!

查看全部评分

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2016-2-21 17:23:05 | 显示全部楼层
那个1 是分割的次数
如果each_line 里面有2个冒号
而split参数里写的是1 则只会切割一次(变成2段)
如果split参数里是2 则会切割两次(变成3段)

评分

参与人数 1荣誉 +1 鱼币 +1 收起 理由
伙夫和甲鱼 + 1 + 1 感谢楼主无私奉献!

查看全部评分

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2016-2-27 10:48:56 | 显示全部楼层
遇到同样的问题,看看
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2026-2-19 18:56

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表