• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
PythonForBeginners.com

PythonForBeginners.com

Learn By Example

  • Home
  • Learn Python
    • Python Tutorial
  • Categories
    • Basics
    • Lists
    • Dictionary
    • Code Snippets
    • Comments
    • Modules
    • API
    • Beautiful Soup
    • Cheatsheet
    • Games
    • Loops
  • Python Courses
    • Python 3 For Beginners
You are here: Home / Basics / Python : List Methods

Python : List Methods

Author: PFB Staff Writer
Last Updated: August 27, 2020

Just like string methods, list methods are working on the list it’s being called from, if you for example have a list called: list1 = [“Movies”, “Music”, “Pictures”], then the list method is called such this: list1.list_method() Let’s demonstrate this by typing in some list method into the python interpreter.

>>> list1 = ["Movies", "Music", "Pictures"]

#list1.append(x) will add an element to the end of the list
>>> list1.append("Files")
>>> list1
['Movies', 'Music', 'Pictures', 'Files']

#list1.insert(x, y) will add element y on the place before x
>>> list1.insert(2,"Documents")
>>> list1
['Movies', 'Music', 'Documents', 'Pictures', 'Files']

#list1.remove(x) will remove the element x from the list
>>> list1.remove("Files")
>>> list1
['Movies', 'Music', 'Documents', 'Pictures']

#list1.extend(x) will join the list with list x
>>> list2 = ["Music2", "Movies2"]
>>> list1.extend(list2)
>>> list1
['Movies', 'Music', 'Documents', 'Pictures', 'Music2', 'Movies2']

Please take a look on this List Methods post, which describes more List methods

Related

Recommended Python Training

Course: Python 3 For Beginners

Over 15 hours of video content with guided instruction for beginners. Learn how to create real world applications and master the basics.

Enroll Now

Filed Under: Basics, Lists Author: PFB Staff Writer

More Python Topics

API Argv Basics Beautiful Soup bitly Cheatsheet Code Code Snippets Command Line Comments Concatenation crawler Data Structures Data Types deque Development Dictionary Dictionary Data Structure In Python Error Handling Exceptions Filehandling Files Functions Games GUI Json Lists Loops Mechanzie Modules Modules In Python Mysql OS pip Python Python On The Web Python Strings Queue Requests Scraping Scripts Split Strings System & OS urllib2

Primary Sidebar

Menu

  • Basics
  • Cheatsheet
  • Code Snippets
  • Development
  • Dictionary
  • Error Handling
  • Lists
  • Loops
  • Modules
  • Scripts
  • Strings
  • System & OS
  • Web

Get Our Free Guide To Learning Python

Most Popular Content

  • Reading and Writing Files in Python
  • Python Dictionary – How To Create Dictionaries In Python
  • How to use Split in Python
  • Python String Concatenation and Formatting
  • List Comprehensions in Python
  • How to Use sys.argv in Python?
  • How to use comments in Python
  • Try and Except in Python

Recent Posts

  • Pandas Append Row to DataFrame
  • Convert String to DataFrame in Python
  • Pandas DataFrame to List in Python
  • Solved: Dataframe Constructor Not Properly Called Error in Pandas
  • Overwrite a File in Python

Copyright © 2012–2023 · PythonForBeginners.com

  • Home
  • Contact Us
  • Privacy Policy
  • Write For Us