如何删除索引?python

如何删除索引?python,python,Python,我在上计算机课程,我得学python。 我被某个问题困住了。上面写着 “编写一个程序,要求用户键入10项列表。 然后要求用户提供需要删除的项目的索引 然后从列表中删除该项目。 需要在删除之前和之后打印列表。” 这是我到目前为止唯一的代码 letters = ["a","b","c","d","e","f","g","h","i","j"] print (letters) del letters input()[] print (letters) 你几乎说对了。你应该读一读这本书 您只需将inp

我在上计算机课程,我得学python。 我被某个问题困住了。上面写着

“编写一个程序,要求用户键入10项列表。 然后要求用户提供需要删除的项目的索引 然后从列表中删除该项目。 需要在删除之前和之后打印列表。”

这是我到目前为止唯一的代码

letters = ["a","b","c","d","e","f","g","h","i","j"]
print (letters)
del letters input()[]
print (letters)

你几乎说对了。你应该读一读这本书


您只需将
input()
放在括号内即可。

您几乎完全正确。你应该读一读这本书


您只需将
input()
放在括号内即可。

您几乎完全正确。你应该读一读这本书


您只需将
input()
放在括号内即可。

您几乎完全正确。你应该读一读这本书


您只需将
input()
放在括号内。

有以下步骤:

从用户处获取输入。使用raw_input()获取值

注意在Python 3.x中使用input()

e、 g

从用户处获取删除索引编号。索引从0开始。执行键入casting以将字符串转换为int e、 g

使用pop()从列表中删除项目。

>>> imput_list.pop(33)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: pop index out of range


>>> try: imput_list.pop(33)
... except IndexError:
...     print "Index out of range."
... 
Index out of range.
e、 g

处理边界的异常。

>>> imput_list.pop(33)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: pop index out of range


>>> try: imput_list.pop(33)
... except IndexError:
...     print "Index out of range."
... 
Index out of range.
>输入列表.pop(33)
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
索引器:弹出索引超出范围
>>>try:input_list.pop(33)
... 除索引器外:
...     打印“索引超出范围”
... 
索引超出范围。

有以下步骤:

从用户处获取输入。使用raw_input()获取值

注意在Python 3.x中使用input()

e、 g

从用户处获取删除索引编号。索引从0开始。执行键入casting以将字符串转换为int e、 g

使用pop()从列表中删除项目。

>>> imput_list.pop(33)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: pop index out of range


>>> try: imput_list.pop(33)
... except IndexError:
...     print "Index out of range."
... 
Index out of range.
e、 g

处理边界的异常。

>>> imput_list.pop(33)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: pop index out of range


>>> try: imput_list.pop(33)
... except IndexError:
...     print "Index out of range."
... 
Index out of range.
>输入列表.pop(33)
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
索引器:弹出索引超出范围
>>>try:input_list.pop(33)
... 除索引器外:
...     打印“索引超出范围”
... 
索引超出范围。

有以下步骤:

从用户处获取输入。使用raw_input()获取值

注意在Python 3.x中使用input()

e、 g

从用户处获取删除索引编号。索引从0开始。执行键入casting以将字符串转换为int e、 g

使用pop()从列表中删除项目。

>>> imput_list.pop(33)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: pop index out of range


>>> try: imput_list.pop(33)
... except IndexError:
...     print "Index out of range."
... 
Index out of range.
e、 g

处理边界的异常。

>>> imput_list.pop(33)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: pop index out of range


>>> try: imput_list.pop(33)
... except IndexError:
...     print "Index out of range."
... 
Index out of range.
>输入列表.pop(33)
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
索引器:弹出索引超出范围
>>>try:input_list.pop(33)
... 除索引器外:
...     打印“索引超出范围”
... 
索引超出范围。

有以下步骤:

从用户处获取输入。使用raw_input()获取值

注意在Python 3.x中使用input()

e、 g

从用户处获取删除索引编号。索引从0开始。执行键入casting以将字符串转换为int e、 g

使用pop()从列表中删除项目。

>>> imput_list.pop(33)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: pop index out of range


>>> try: imput_list.pop(33)
... except IndexError:
...     print "Index out of range."
... 
Index out of range.
e、 g

处理边界的异常。

>>> imput_list.pop(33)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: pop index out of range


>>> try: imput_list.pop(33)
... except IndexError:
...     print "Index out of range."
... 
Index out of range.
>输入列表.pop(33)
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
索引器:弹出索引超出范围
>>>try:input_list.pop(33)
... 除索引器外:
...     打印“索引超出范围”
... 
索引超出范围。


看起来您需要花一些时间与。教程中介绍了大多数可能的解决方案。教程中介绍了大多数可能的解决方案。教程中介绍了大多数可能的解决方案。教程中介绍了大多数可能的解决方案。教程中介绍了大多数可能的解决方案。教程中介绍了大多数可能的解决方案教程“的可能重复项”看起来您需要花一些时间学习。大多数可能的解决方案都包含在教程“的可能重复项<代码>类型错误:列表索引必须是整数,而不是str”,有什么想法吗?@vaultah在Python 3中,input()返回字符串。您必须将其转换为整数。@vaultah已经为python3更新了它给了我这个错误。列出超出范围的分配索引,这将是您的输入,而不是我的解决方案。如错误所述,您输入的索引超出了列表
TypeError的范围:列表索引必须是整数,而不是str
,有什么想法吗?@vaultah在Python 3中,input()返回字符串。您必须将其转换为整数。@vaultah已经为python3更新了它给了我这个错误。列出超出范围的分配索引,这将是您的输入,而不是我的解决方案。如错误所述,您输入的索引超出了列表
TypeError的范围:列表索引必须是整数,而不是str
,有什么想法吗?@vaultah在Python 3中,input()返回字符串。您必须将其转换为整数。@vaultah已经为python3更新了它给了我这个错误。列出超出范围的分配索引,这将是您的输入,而不是我的解决方案。如错误所述,您输入的索引超出了列表
TypeError的范围:列表索引必须是整数,而不是str
,有什么想法吗?@vaultah在Python 3中,input()返回字符串。您必须将其转换为整数。@vaultah已经为python3更新了它给了我这个错误。列出超出范围的分配索引,这将是您的输入,而不是我的解决方案。如错误所述,您输入的索引超出列表的范围