Advertisement
Sabbir-bin

insert,pop,append,remove

Jun 17th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.58 KB | None | 0 0
  1. motorcycle=['honda','yamaha','suzuki']
  2. motorcycle.insert(0, 'ducati')
  3. #using append insert last element
  4. motorcycle.append('hero')
  5. print(motorcycle)
  6. #delete index 2
  7. del motorcycle[2]
  8. print(motorcycle)
  9. #insert index 2
  10. motorcycle.insert(2, 'yamaha')
  11. print(motorcycle)
  12. #pop the last element
  13. last_v = motorcycle.pop()
  14. print("\nThe last motorcycle I owned was a " +last_v.title() +".")
  15.  
  16. new = motorcycle.pop(2)
  17. print("\nThe last motorcycle I owned was a " +new.title() +".")
  18.  
  19. n='honda'
  20. #remove value
  21. motorcycle.remove(n)
  22. print("\nA "+ n.title() +" is too expensive for me.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement