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

  • Amitabh Bachchan biography in hindi | Family, wife, awards
    Amitabh Bachchan biography in hindi | Family, wife, awards Biography
  • Unicef day
    Unicef day is celebrated on December 11 | Speech on unicef day General Knowledge
  • Prithviraj Chauhan Biography in Hindi | पृथ्वीराज चौहान जीवनी हिंदी
    Prithviraj Chauhan Biography in Hindi | पृथ्वीराज चौहान जीवनी हिंदी Biography
  • Thomas Edison Biography in Hindi - थॉमस एडिसन जीवनी
    Thomas Edison Biography in Hindi – थॉमस एडिसन जीवनी Biography
  • Republic day गणतंत्र दिवस | Happy Republic Day
    Republic day गणतंत्र दिवस कब और क्यों मनाया जाता है? Festival
  • Chemical Properties of Matter (Element, Compound and Mixture)
    Chemical Properties of Matter examples (Element, Compound and Mixture) Science
  • P V Sindhu Biography in Hindi
    P V Sindhu Biography in Hindi, Badminton, State, Caste पी. वी. सिंधु जीवन परिचय, कहानी, राज्य, जाति Biography
  • Sunder Kand in Hindi | Hanuman Kand | हनुमान जी का सुंदरकांड
    Sunder Kand in Hindi | Hanuman Kand | हनुमान जी का सुंदरकांड Spiritual

Python List

Posted on September 29, 2021October 4, 2021 By GeekCer Education 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 Tutorial for Beginners Python Tutorial for Beginners Python
Python Variable and Python Datatype Python Variable and Python Datatype 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
  • National Farmers Day in Hindi | राष्ट्रीय किसान दिवस पर निबंध | चौधरी चरण सिंह जयंती
  • Human rights day in Hindi: 10 दिसंबर ह्यूमन राइट्स डे
  • Unicef day is celebrated on December 11 | Speech on unicef day
  • Indian Navy Day: जल सेना दिवस कब और क्यों मनाया जाता है?
  • P V Sindhu Biography in Hindi, Badminton, State, Caste पी. वी. सिंधु जीवन परिचय, कहानी, राज्य, जाति
  • Draupadi Murmu Biography In Hindi | द्रौपदी मुर्मू की जीवनी
  • Difference between TCP and UDP
    Difference between TCP and UDP | TCP vs UDP examples Differences
  • Similarities and difference between OSI and TCP/IP model
    OSI vs TCP/IP Model, Similarities and difference between OSI and TCP/IP model Networking
  • Network kya hai (नेटवर्क क्या है)
    Network kya hai (नेटवर्क क्या है) Networking
  • TCP/IP Model, Full Form, Layers and their Functions
    TCP/IP Model, Full Form, Layers and their Functions Networking
  • OSI Model | 7 Layers of OSI Model in Computer network
    OSI Model | 7 Layers of OSI Model in Computer network, Functions Networking
  • IPv4 Vs IPv6 | Difference between IPv4 and IPv6
    IPv4 Vs IPv6 | Difference between IPv4 and IPv6 Differences
  • Difference between Internet and Intranet
    Difference between Internet and Intranet Differences
  • 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