Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

第八课中代码解释存在部分问题 #48

Open
lia-505 opened this issue Apr 28, 2023 · 0 comments
Open

第八课中代码解释存在部分问题 #48

lia-505 opened this issue Apr 28, 2023 · 0 comments

Comments

@lia-505
Copy link

lia-505 commented Apr 28, 2023

image
即“items = ['Python', 'Java', 'Go', 'Kotlin']
items.pop(0)
items.pop(len(items) - 1)
print(items)”
这段代码的作用是从一个包含四个字符串元素的列表中删除第一个和最后一个元素,然后输出剩下的两个元素。

具体来说,代码首先定义了一个名为“items”的列表,其中包含四个字符串元素。接着,调用列表的pop()方法,通过指定索引0或(len(items) - 1)来删除列表的第一个或最后一个元素。这里的值为0代表列表的第一个元素,而(len(items) - 1)代表列表的最后一个元素(因为列表的索引从零开始)。

最后,使用print()函数输出经过删除操作之后的列表“items”,也就是['Java', 'Go']这个列表。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant