V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
HTTmio
V2EX  ›  Python

萌新提问: list 的参数带有 : 冒号是什么?

  •  1
     
  •   HTTmio · 2019-09-05 10:32:58 +08:00 · 1876 次点击
    这是一个创建于 1666 天前的主题,其中的信息可能已经有所发展或是发生改变。
    1. content = content[1:] + content[0]

      2. filename[index:]
      
      这是两个题的 不太明白 请大佬指点
      
    peanuts7660
        1
    peanuts7660  
       2019-09-05 10:49:49 +08:00   ❤️ 1
    切片。content[1:] 表示从下标为 1 开始截取列表
    slice[起始下标:截止下标:间隔]
    whusnoopy
        2
    whusnoopy  
       2019-09-05 10:51:31 +08:00   ❤️ 1
    list slice

    这个还是看看语言基础吧 https://docs.python.org/3/tutorial/introduction.html#lists
    672795574
        3
    672795574  
       2019-09-05 10:51:38 +08:00   ❤️ 1
    content[1:] 表示 content 下标 1 到末尾。
    content = content[1:] + content[0] 应该是想把第一个字符挪到末尾
    ``
    `>>> a = "String"
    >>> a[1:] + a[0]
    'tringS'
    ```
    Marinej
        4
    Marinej  
       2019-09-05 10:52:10 +08:00   ❤️ 1
    python 的切片
    Huelse
        5
    Huelse  
       2019-09-05 10:52:44 +08:00   ❤️ 1
    Python 基础-切片
    lmufc
        6
    lmufc  
       2019-09-05 10:57:28 +08:00   ❤️ 1
    这不是基础么。。而且是百度就有的东西
    jowan
        7
    jowan  
       2019-09-05 11:02:12 +08:00
    ![a15b4afegy1flxj9snk78j209m0drdgl.jpeg]( https://i.loli.net/2019/09/05/5NpdgjsI2ozekEi.jpg)
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3716 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 10:40 · PVG 18:40 · LAX 03:40 · JFK 06:40
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.