<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[列表的使用]]></title><description><![CDATA[<h2><a class="anchor-offset" name="介绍"></a>介绍</h2>
<p dir="auto">大家已经学过了<a href="/topic/285/%E5%88%97%E8%A1%A8%E7%AE%80%E4%BB%8B">列表简介</a>、<a href="/topic/625/%E7%94%A8%E7%A7%AF%E6%9C%A8%E7%BC%96%E8%BE%91%E5%88%97%E8%A1%A8">用积木编辑列表</a>以及<a href="/topic/628/%E8%AF%BB%E5%8F%96%E5%88%97%E8%A1%A8">读取列表</a>。本文将介绍其他一些有关列表使用的高级积木。</p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="列表排序"></a>列表排序</h2>
<p dir="auto">可以用以下积木使列表项按顺序排列：</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/0d150214-74fb-4cae-af3a-695f411b0e39.gif" alt="Animation1.gif" class=" img-responsive img-markdown" width="612" height="300" /></p>
<p dir="auto"> <br />
提醒一下，这个积木也可以用于文本组成的列表。对每个列表项的第1个字符进行比较并确定大小。而中文字符的大小是根据Unicode编码确定的。例如，“秋高气爽”要小于“风和日丽”，因为在Unicode编码中，“秋”排在“风”前面。</p>
<p dir="auto">如果两个列表项的第1个字符相同，则比较第2个字符，以此类推。例如，“冰天雪地”要小于“冰清玉洁”，因为两者都以“冰”开头，第2个字符“天”在Unicode编码中排在“清”前面。</p>
<p dir="auto">注意，英文字母不区分大小写。</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/2f4409a5-e795-4391-8894-cea6f29f9a30.gif" alt="Animation2.gif" class=" img-responsive img-markdown" width="612" height="300" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="随机打乱列表"></a>随机打乱列表</h2>
<p dir="auto">积木“随机打乱( )中各项的顺序”，为每一个列表项随机分配一个位置，类似于洗牌。</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/1668a0c2-4649-4107-b8e4-c01b301dffe1.gif" alt="Animation3.gif" class=" img-responsive img-markdown" width="565" height="300" /></p>
<p dir="auto"> <br />
举个例子，比方说你需要打印全班学生的姓名，但你想让名单随机排序，这样的话别人就猜不出下一个是谁。你只需要随机打乱姓名列表。</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/43efdcdb-ec2e-4c07-87bf-bf41b4aec599.gif" alt="Animation4.gif" class=" img-responsive img-markdown" width="565" height="300" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="反转列表"></a>反转列表</h2>
<p dir="auto">可以用积木“反转列表( )”使列表顺序反转。第一项变为最后一项，第二项变为倒数第二项，以此类推。如果你反转2次，就得到和原来一样的列表。</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/cb29a672-f7e4-4534-ad35-63a163ef9e9b.gif" alt="Animation5.gif" class=" img-responsive img-markdown" width="565" height="300" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="把列表项连接成字符串"></a>把列表项连接成字符串</h2>
<p dir="auto">可以把列表的所有项连接成一个长字符串，并且可以指定一个分隔符放在相邻项之间。</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/9949b8cd-e0a2-4258-8381-b855aa613f60.gif" alt="Animation6.gif" class=" img-responsive img-markdown" width="565" height="300" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="把字符串分割成列表项"></a>把字符串分割成列表项</h2>
<p dir="auto">与“连接”相反的就是“分割”。你可以把一个长字符串分割成若干个列表项，并且可以指定分隔符。</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/c98d9821-748e-42f2-8563-5825e8640283.gif" alt="Animation7.gif" class=" img-responsive img-markdown" width="570" height="300" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="将一个列表附加到另一个列表"></a>将一个列表附加到另一个列表</h2>
<p dir="auto">可以把一个列表附加到另一个列表，也就是说把一个列表的全部项附加到另一个列表的底部。例如，当你把“数字2”附加到“数字1”，列表“数字2”不变，只是它的3个列表项会被附加到列表“数字1”底部。</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/51cb5e67-3bfe-4d97-b9f4-557074c0709e.gif" alt="Animation8.gif" class=" img-responsive img-markdown" width="754" height="300" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="把一个列表复制到另一个列表"></a>把一个列表复制到另一个列表</h2>
<p dir="auto">还可以把一个列表复制到另一个列表。首先会把目标列表的原有项全部删除，复制之后，两个列表完全相同。</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/62fef871-2a19-4a74-88d7-9e197f4de58c.gif" alt="Animation8.5.gif" class=" img-responsive img-markdown" width="687" height="336" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="生成随机数列表"></a>生成随机数列表</h2>
<p dir="auto">“运算”类别的积木“在( )和( )之间取随机数”会生成某一范围内的随机数。如果你想生成一系列随机数，就可以用如下积木。</p>
<p dir="auto">注意：如果允许重复，就有可能出现相同的数。如果不允许重复，生成的列表就没有相同的项。</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/ad55d195-2cf6-49e9-8f7c-352111021a1a.gif" alt="Animation9.gif" class=" img-responsive img-markdown" width="754" height="300" /></p>
<p dir="auto"> <br />
 </p>
<h2><a class="anchor-offset" name="遍历一个列表"></a>遍历一个列表</h2>
<p dir="auto">你可以遍历一个列表并查看列表中的所有项。</p>
<p dir="auto">首先，你可以用积木“对于每个项目( ) 在( )”，把列表中的每一项的值赋给变量：</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/33b26628-e6c8-4c50-9828-ef351ada1db7.gif" alt="Animation10.gif" class=" img-responsive img-markdown" width="524" height="610" /></p>
<p dir="auto"> <br />
还可以用一个索引变量访问列表中的所有项。索引变量从1一直涨到等于列表的长度。可以在这个循环中用变量读取列表。</p>
<p dir="auto"><img src="https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/82b59404-c95d-4873-ab05-449dad43ac71.gif" alt="Animation11.gif" class=" img-responsive img-markdown" width="524" height="610" /></p>
]]></description><link>https://forum.creaticode.com/topic/727/列表的使用</link><generator>RSS for Node</generator><lastBuildDate>Sun, 07 Jun 2026 05:03:34 GMT</lastBuildDate><atom:link href="https://forum.creaticode.com/topic/727.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 02 Nov 2022 13:53:15 GMT</pubDate><ttl>60</ttl></channel></rss>