giao_857 2021-07-08 20:45 采纳率: 66.7%
浏览 38
已采纳

python删除列表的remove方法错误

源:


#coding:utf-8                   
a=['春季','夏季','秋季','日食','冬季']    
for e in a:                     
    e.remove('日食')              
print(e)                        

图:

img

控件PyCharm社区版
这咋了???

Python 3.10.0b3 (tags/v3.10.0b3:865714a, Jun 17 2021, 20:39:25) [MSC v.1929 64 bit (AMD64)] on win32
runfile('C:/Users/Admin/PycharmProjects/pythonProject1/main.py', wdir='C:/Users/Admin/PycharmProjects/pythonProject1')
Traceback (most recent call last):
File "", line 1, in
File "D:\BaiduNetdiskDownload\PyCharm Community Edition 2021.1.2\plugins\python-ce\helpers\pydev_pydev_bundle\pydev_umd.py", line 197, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "D:\BaiduNetdiskDownload\PyCharm Community Edition 2021.1.2\plugins\python-ce\helpers\pydev_pydev_imps_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"n", file, 'exec'), glob, loc)
File "C:/Users/Admin/PycharmProjects/pythonProject1/main.py", line 4, in
e.remove('日食')
AttributeError: 'str' object has no attribute 'remove'

带湿们解释解释
求了!!
python3.10,不是3.6!!!
这是导入AST的结果:

C:\Users\Admin>pip install --user AST
Fatal error in launcher: Unable to create process using '"c:\users\tarena\desktop\python-3.6.4-embed-win32\python.exe" "C:\Users\Admin\AppData\Roaming\tc\python-3.6.4\Scripts\pip.exe" install --user AST'

C:\Users\Admin>pip /?
Fatal error in launcher: Unable to create process using '"c:\users\tarena\desktop\python-3.6.4-embed-win32\python.exe" "C:\Users\Admin\AppData\Roaming\tc\python-3.6.4\Scripts\pip.exe" /?'

C:\Users\Admin>pip?
'pip?' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

C:\Users\Admin>pip ?
Fatal error in launcher: Unable to create process using '"c:\users\tarena\desktop\python-3.6.4-embed-win32\python.exe" "C:\Users\Admin\AppData\Roaming\tc\python-3.6.4\Scripts\pip.exe" ?'

C:\Users\Admin>
C:\Users\Admin>
C:\Users\Admin>
C:\Users\Admin>
C:\Users\Admin>
C:\Users\Admin>
C:\Users\Admin>
C:\Users\Admin>
C:\Users\Admin>
C:\Users\Admin>
C:\Users\Admin>cd C:\Windows\system32

C:\Windows\System32>pip /?
Fatal error in launcher: Unable to create process using '"c:\users\tarena\desktop\python-3.6.4-embed-win32\python.exe" "C:\Users\Admin\AppData\Roaming\tc\python-3.6.4\Scripts\pip.exe" /?'

C:\Windows\System32>python -m pip install -user AST

Usage:
C:\Users\Admin\AppData\Roaming\tc\python-3.6.4\python.exe -m pip install [options] [package-index-options] ...
C:\Users\Admin\AppData\Roaming\tc\python-3.6.4\python.exe -m pip install [options] -r [package-index-options] ...
C:\Users\Admin\AppData\Roaming\tc\python-3.6.4\python.exe -m pip install [options] [-e] ...
C:\Users\Admin\AppData\Roaming\tc\python-3.6.4\python.exe -m pip install [options] [-e] ...
C:\Users\Admin\AppData\Roaming\tc\python-3.6.4\python.exe -m pip install [options] <archive url/path> ...

no such option: -u

C:\Windows\System32>python -m -u pip install -user AST
C:\Users\Admin\AppData\Roaming\tc\python-3.6.4\python.exe: No module named -u

C:\Windows\System32>

```
小白在线求解啊!!!!!!!

  • 写回答

2条回答 默认 最新

  • 奋斗的小小鱼 2021-07-08 21:11
    关注

    列表自带去除元素的方法remove,直接a.remove("日食")就可以了

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 7-1 jmu-java-m02-使用二维数组存储多元线性方程组
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 CMFCPropertyPage
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题