Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • CreatiCode
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

CreatiCode Scratch Forum

  1. CreatiCode Forum
  2. 知识库
  3. 二维积木
  4. 读取列表

读取列表

Scheduled Pinned Locked Moved 二维积木
1 Posts 1 Posters 897 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    creaticodeteacher2-mail
    wrote on last edited by admin
    #1

    先修科目

    • 用积木编辑列表

    介绍

    列表就像是很多个按顺序排列的变量。你可以通过列表项的位置读取其值,还可以获取列表的信息。

     

    获取列表的长度

    这个报表积木告诉你列表中有多少项。

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/f527e9f9-38d5-45e6-acbc-962f1dea89fb.png" width="245" style="filter: drop-shadow(0.35rem 0.35rem 0.4rem rgba(0, 0, 0, 0.5));">

     

    示例

    注意,列表项的位置索引号从1至列表长度。例如,如果你要在列表最后一项前插入项,就可以用列表长度作为位置索引。

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/b5d40cf4-0f7c-40fe-be32-e6ea18033527.gif" width="970" style="border-radius: 5px; border: 1px solid #29622d;">

     

    读取指定位置的列表项的值

    如果你知道某一项的位置,就可以用这个积木读取其值:

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/7ca30390-b392-468f-85db-a179cddc5df8.png" width="297" style="">

    位置索引最小为1,最大为列表长度。例如,获取最后一项的值,方法如下:

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/391bc0da-5256-4c14-8234-728b3eb15d41.gif" width="970" style="border-radius: 5px; border: 1px solid #29622d;">

     

    按照值搜索列表项

    你不仅可以按照位置获取列表项,如果你知道某一项的值,还可以找到该项的位置。

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/afad1c14-83df-46fe-b1da-4cc74c90eb50.png" width="300" style="">

     
    如果找不到该值,报告的值就为0:

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/b9b22c2c-8616-403b-a3bc-b5011dd71b32.gif" width="970" style="border-radius: 5px; border: 1px solid #29622d;">

     

    列表是否包含某个值

    利用这个积木可以判断列表是否包含某个值,报告结果为“true(真)”或者“false(假)”。

     
    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/5c640266-5498-489d-b79d-d1e1870de4d5.gif" width="970" style="border-radius: 5px; border: 1px solid #29622d;">

     

    搜索某一项的一部分

    有时候你想找到包含某个值的项。换句话说,你要搜索某一项的一部分。可以用这个积木:

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/7e584e21-bb68-40a4-a5b7-1cf884984955.png" width="400" style="">

    例如,在学生姓名列表中,你想找到第一个姓“王”的学生的索引号,方法如下:

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/cdc17dd5-6f88-4909-9ba1-3bec2c84b2c2.gif" width="970" style="border-radius: 5px; border: 1px solid #29622d;">

    1 Reply Last reply
    0

    Hello! It looks like you're interested in this conversation, but you don't have an account yet.

    Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

    With your input, this post could be even better 💗

    Register Login
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • CreatiCode