f = open("Information.txt","w+",encoding="utf8")
Information = [["1","alex","IT"],["2","bob","IT"]]
User_Choice = int(input("Your choice is:"))
for i in Information:
    if User_Choice == int(i[0]):
       Information.remove(Information[User_Choice])
       for j in Information:
           f.write(','.join(j).strip()) #关键是这一步,把列表通过join方法转换成字符串,然后再写入文件
           f.close()

该程序的作用是用户输入数字后,会删掉列表中对应的元素,然后再把列表中剩余的元素写入文件中

相关文章:

  • 2022-01-02
  • 2022-12-23
  • 2022-01-19
  • 2021-08-05
  • 2021-11-14
  • 2021-10-22
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-05-27
  • 2021-06-11
  • 2022-12-23
  • 2022-02-07
  • 2022-12-23
  • 2021-05-08
  • 2021-09-03
相关资源
相似解决方案