gpt4 book ai didi

lua - Lua 的表长度运算符是如何工作的?

转载 作者:行者123 更新时间:2023-12-04 14:09:59 25 4
gpt4 key购买 nike

<分区>

有人可以解释这种明显的精神错乱吗?

> t = {1, 2, 3} -- Table length 3. Simple
> = #t
3 -- Yep

> t[3] = nil -- Remove the last element?
> = #t
2 -- Ok it realises it is the last one (since #t = 3) and decrements the length

> t[6] = 6 -- Add a separate element?
> = #t
2 -- Ok... I guess? Although surely it knew #t = 2, and so now #t should be 6?

> t[4] = 4 -- Add another separate element
> = #t
4 -- Errr... what.

> t[5] = 5 -- Append another element
> = #t
6 -- Ok now it remembers element 6? Wtf?

好的,让我再试一次......

> t = {1, 2, 3}
> = #t
3
> t[10] = 10
> = #t
3
> t[4] = 4
> = #t
4
> t[9] = 9
> = #t
4
> t[8] = 8
> = #t
10

什么。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com