Skip to content
  • Facebook
GeekCer Logo

GeekCer

The geek's Coding education and Review centre

  • Home
  • Tutorials
    • Java
    • Servlet
    • JSP
    • Python
    • C Tutorial
    • Spring
    • Spring Boot
    • MongoDB
    • Hibernate
    • Data Structure
  • General Knowledge
  • Biography
  • Grammar
  • Festival (त्योहार)
  • Interview
  • Differences
  • Important
  • Toggle search form

Home » Python » Python List

  • What is Noun
    What is Noun? | Types of Nouns With Examples Grammar
  • How to become a Chief Financial Officer (CFO)
    How to become a Chief Financial Officer (CFO)? Important
  • JDBC Driver in Java
    JDBC Driver in Java Java
  • How to create Database and Collection in MongoDB
    How to create Database and Collection in MongoDB? MongoDB
  • Operational Qualification
    Operational Qualification (OQ) Important
  • Python Tutorial for Beginners
    Python Tutorial for Beginners Python
  • World Red Cross Day and Red Crescent Day | विश्व रेडक्रॉस दिवस
    World Red Cross Day and Red Crescent Day | विश्व रेडक्रॉस दिवस General Knowledge
  • Servlet API
    Servlet API Servlet

Python List

Posted on September 29, 2021October 4, 2021 By admin No Comments on Python List
Python List

Python List is a composite data type in which we store many objects and it is the most versatile and most widely used data type of Python. We can write comma separated items in the list and put all the items between square brackets[].

List can store different types of items, it is not necessary to have same type of items. List can store the duplicate items, it is changeable and ordered in nature.

Click here to know the basics of Python

Table of Contents

  • Syntax of List
  • Accessing item from List
  • Slicing of the List
  • Concatenation of Python List
  • Update List item
  • Append List item
  • Assignment to Python List Slices
  • List length
  • Remove item from List
  • Functions of Python List

Syntax of List

The syntax of python list is simple. Just we have to put the item inside the square brackets[].

                  geekList = []
          
                  squares = [1, 4, 9, 16, 25]
print(squares)
                  
Output:
[1, 4, 9, 16, 25]

Accessing item from List

We can access item from the list by using index. [0] is the index of the first item, [1] is the index of the second item.

                  squares = [1, 4, 9, 16, 25]
print(squares[0])
print(squares[-5])
print(squares[3])

Output:
1
1
16

Slicing of the List

Slicing operations return a new list from the existing list. In other words, we can say that we find the subset of the list by using slicing. We use :(colon) to shorten the list.

                  squares = [1, 4, 9, 16, 25]
print(squares[:])
print(squares[2:])
print(squares[:3])

Output:
[1, 4, 9, 16, 25]
[9, 16, 25]
[1, 4, 9]

Concatenation of Python List

This is the way to append one list to another list. Suppose we have two list L1 and L2 then we will find new list by L3 = L1 + L2.

                  squares = [1, 4, 9, 16, 25]
squares = squares + [36, 49, 64, 81, 100]
print(squares)

Output:
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]

Update List item

We can update the list item of the given index.

                  squares = [1, 4, 9, 16, 25]
squares[3] = 100
print(squares)

Output:
[1, 4, 9, 100, 25]

Append List item

We use append() method to append item in the list.

                  squares = [1, 4, 9, 16, 25]
squares.append(36)
print(squares)

Output:
[1, 4, 9, 16, 25, 36]

Assignment to Python List Slices

Here we assign a second list to the list between the given slices.

                  list = [1, 4, 9, 16, 25]
list[2:3] = ['C', 'D', 'E']
print(list)

Output:
[1, 4, 'C', 'D', 'E', 16, 25]

List length

We use len() method to find the length of the List

                  list = [1, 4, 9, 16, 25]
print(len(list))

Output:
5

Remove item from List

We use remove() method to remove item from the List.

                  list = ["apple", "banana", "mango"]
list.remove("apple");
print(list)

Output:
['banana', 'mango']

Functions of Python List

#FunctionsDescription
1min(list)The min method returns the minimum value from the list.
2max(list)The max method returns the maximum value from the list.
3len(list)Returns the total number of items from the list.
4cmp(list1, list2) This method compares two list items.
5list(sequence) Converts another sequence to list.
6insert(index, value) Insert element at given position.
7append(list) Adds another list at last position.
8extend(seq) Appends the contents of seq to the list.
9remove(item)Removes element from list.
10clear()This method clears list.
11index(item) Finds the index of given item.
12count(item) Counts how many times items are available in the list.
13sort()Sorts element in ascending order.
14reverse()We reverses items of the list in place.
15copy()Makes the copy of the list.

Share this:

  • Click to share on Facebook (Opens in new window)
  • Click to share on WhatsApp (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • More
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Pinterest (Opens in new window)

Also Read

Python Tags:Append Method, List, Software Development

Post navigation

Previous Post: Python Variable and Python Datatype
Next Post: Python Tuple and Basic Tuple Operations with Examples

More Related Articles

Python Variable and Python Datatype Python Variable and Python Datatype Python
Python Tutorial for Beginners Python Tutorial for Beginners Python
Python Tuple and Basic Tuple Operations with Examples Python Tuple and Basic Tuple Operations with Examples Python

Related Posts

  • Python Variable and Python Datatype
    Python Variable and Python Datatype Python
  • Python Tutorial for Beginners
    Python Tutorial for Beginners Python
  • Python Tuple and Basic Tuple Operations with Examples
    Python Tuple and Basic Tuple Operations with Examples Python

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • Python Home
  • Python Variable and Datatype
  • Python List
  • Python Tuple

Recent Posts

  • Structured Vs Unstructured Data in Hindi | Key Difference
  • Jhansi Ki Rani Lakshmi Bai History, Story, Information in Hindi
  • Elon musk Hindi : एलन मस्क हिंदी में, Autobiography,  Net Worth
  • World Environment Day in Hindi : Objective, Importance, Theme
  • Thomas Edison Biography in Hindi – थॉमस एडिसन जीवनी
  • International Nurses Day in Hindi | नर्स दिवस क्यों मनाते हैं?
  • Fork/Join Framework in Java | RecursiveTask, RecursiveAction
  • DBMS in Hindi | DBMS क्या है? | DBMS की विशेषताएं और प्रकार
  • What is Noun
    What is Noun? | Types of Nouns With Examples Grammar
  • How to become a Chief Financial Officer (CFO)
    How to become a Chief Financial Officer (CFO)? Important
  • JDBC Driver in Java
    JDBC Driver in Java Java
  • How to create Database and Collection in MongoDB
    How to create Database and Collection in MongoDB? MongoDB
  • Operational Qualification
    Operational Qualification (OQ) Important
  • Python Tutorial for Beginners
    Python Tutorial for Beginners Python
  • World Red Cross Day and Red Crescent Day | विश्व रेडक्रॉस दिवस
    World Red Cross Day and Red Crescent Day | विश्व रेडक्रॉस दिवस General Knowledge
  • Servlet API
    Servlet API Servlet
  • Java Tutorial
  • Servlet Tutorial
  • JSP Tutorial
  • Maven Tutorial
  • HTML Tutorial
  • Programs
  • Hindi/English Grammar
  • Difference Between ... and ...
  • HR Interview
  • Important Articles

Write to Us:
geekcer.code@gmail.com

  • About Us
  • Privacy and Policy
  • Disclaimer
  • Contact Us
  • Sitemap

Copyright © GeekCer 2022 All Rights reserved