Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c

List in python Programming language

Posted on June 11, 2017September 15, 2019

Table of Contents

  • List in a Python Programming language
  • 1. Accessing value in a list
    • the output of the above program
  • 2. Updating list elements
    • Output above program
  • 3. Delete Elements of list
  • 4.Insert Elements of the list
  • 5.Count Elements of the list
  • 6.Reverse Elements of the list
  • 7.Append Elements of list
  • 8.pop Elements of list
  • [‘php’, ‘html’, ‘java’, ‘C’, ‘C++’, ‘vb.net’, ‘Asp.net’, ‘jquary’] php [‘html’, ‘java’, ‘C’, ‘C++’, ‘vb.net’, ‘Asp.net’, ‘jquary’] 9.sort Elements of list
  • 10.index Elements of list

List in a Python Programming language

In this tutorial, we will discuss the list in python programming language.

The list is a data type in python that is used to store the sequence of data. When creating the list, we can use comma to separate the values between two square bracket- it looks like an array format. Each element of a sequence is named with a variable and assigned a number. It is called an index. Its position in the index is from first to last zero(the first element is 0 and the last element is on)
Syntex of list
list=[element 1,element 2, element 3, element 4, element 5,……., element n];
List index
For an example of the list
Languages=[“php”,”html”,”java”,”C”, “C++”,”vb.net”,”Asp.net”,”jquary”];
Numbers=[“45, “67”, “89”, “76”, “54”, “43”, “32”, “91”];

alphabets=[“a”,”b”,”c”,”d”,”e”,”f”,”g”,”h”];

List may be contain multiple type of data

multilist=[“physics”,”chemistry”,”1998″,”2017″];

1. Accessing value in a list

We can accessing data in list using index indice of list

Languages=[“php”,”html”,”java”,”C”, “C++”,”vb.net”,”Asp.net”,”jquary”];
Numbers=[“45”, “67”, “89”, “76”, “54”, “43”, “32”, “91”];

alphabets=[“a”,”b”,”c”,”d”,”e”,”f”,”g”,”h”];

multilist=[“physics”,”chemistry”,”1998″,”2017″];

We can seperate every element of list using follwing code

print(Languages[0]); – Seperate 0 index element from list of Language

print(Numbers[2]); – Seperate 3 index element from list of Numbers

print(multilist[3]); – Seperate 4 index element from list of multilist

 

List in python Programming language
Example

the output of the above program

 
Languages[0] – php
Numbers[2] – 89
alphabets[6] – g

multilist[3] – 2017

2. Updating list elements


We can update a single or multiple elements of the list using assign operator given below

print(“New value in the list of languages available in index 2:”)

Languages[2]=”CSS”;  // insert to list of Languages

List in python Programming language
Example

 

Output above program

Value in the list of languages available in index 2:
java
New value in the list of languages available in index 2:
New value in languages available in index 2:
CSS


3. Delete Elements of list

 

To remove the list element, we can use del statement or remove() method

multilist=[“physics”,”chemistry”,”1998″,”2017″];

print(multilist)

del(multilist[2]) // using del statement

print(multilist)  //print multilist after del index [2] element

multilist.remove(multilist[2]) // remove index[2] element from new list

List in python Programming language
Example

 

Output of above program

[‘physics’, ‘chemistry’, ‘1998’, ‘2017’]
[‘physics’, ‘chemistry’, ‘2017’]
[‘physics’, ‘chemistry’]

 


4.Insert Elements of the list


We can insert elements of list using insert() method

Numbers=[“45”, “67”, “89”, “76”, “54”, “43”, “32”, “91”];   // list

print(number)

Number.insert(3,100)    // use insert method

print(number)

List in python Programming language
Example

Output above code

[’45’, ’67’, ’89’, ’76’, ’54’, ’43’, ’32’, ’91’]
[’45’, ’67’, ’89’, 100, ’76’, ’54’, ’43’, ’32’, ’91’100]

 

5.Count Elements of the list


We can count element of the list using count() method

Number=[’45’, ’67’, ’89’, 100, ’76’, ’54’, ’43’, ’32’, ’91’100];

print(Number)

Number.count(‘100’)    // use count method

print(Number)

Output of above program

[’45’, ’67’, ’89’, ‘100’, ’76’, ’54’, ’43’, ’32’, ’91’, ‘100’]

2


6.Reverse Elements of the list


We can change reverse order element of the list using reverse() method

Number=[’45’, ’67’, ’89’, 100, ’76’, ’54’, ’43’, ’32’, ’91’100];

print(Number)

Number.reverse()

print(Number)

Output above program

[’45’, ’67’, ’89’, ‘100’, ’76’, ’54’, ’43’, ’32’, ’91’, ‘100’]
[‘100′, ’91’, ’32’, ’43’, ’54’, ’76’, ‘100’, ’89’, ’67’, ’45’]

 

7.Append Elements of list

 

Languages=[“php”,”html”,”java”,”C”, “C++”,”vb.net”,”Asp.net”,”jquary”];

print(Number)

Number.Append([“css”,”Js”,”ruby”])

print(Number)


Output above program

[‘php’, ‘html’, ‘java’, ‘C’, ‘C++’, ‘vb.net’, ‘Asp.net’, ‘jquary’]

[‘php’, ‘html’, ‘java’, ‘C’, ‘C++’, ‘vb.net’, ‘Asp.net’, ‘jquary’, [‘css’, ‘Js’, ‘ruby’]]


8.pop Elements of list

 

Languages=[“php”,”html”,”java”,”C”, “C++”,”vb.net”,”Asp.net”,”jquary”];

print(Languages)

print(Languages.pop(0))

print(Languages)

List in python Programming language
Example
Output

[‘php’, ‘html’, ‘java’, ‘C’, ‘C++’, ‘vb.net’, ‘Asp.net’, ‘jquary’]
php
[‘html’, ‘java’, ‘C’, ‘C++’, ‘vb.net’, ‘Asp.net’, ‘jquary’]



9.sort Elements of list


We can sort object of a list

Languages=[“php”,”html”,”java”,”C”, “C++”,”vb.net”,”Asp.net”,”jquary”];

print(Languages)

Languages.sort();

print(Languages)

List in python Programming language
Example




Output

[‘php’, ‘html’, ‘java’, ‘C’, ‘C++’, ‘vb.net’, ‘Asp.net’, ‘jquary’]

[‘Asp.net’, ‘C’, ‘C++’, ‘html’, ‘java’, ‘jquary’, ‘php’, ‘vb.net’]

 

10.index Elements of list


Languages=[“php”,”html”,”java”,”C”, “C++”,”vb.net”,”Asp.net”,”jquary”];

print(Languages)

print(Languages.index(“java”));

List in python Programming language
Example








Output

[‘php’, ‘html’, ‘java’, ‘C’, ‘C++’, ‘vb.net’, ‘Asp.net’, ‘jquary’]

2

Related post

Data type in Python                                        

Tuple in Python                                            Dictionary in Python

Set Data type in Python

Related

Recent Posts

  • Subtract two numbers using method overriding
  • PHP Star triangle Pattern program
  • Using function or method to Write temperature conversion : Fahrenheit into Celsius
  • Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user
  • Write temperature conversion program: Fahrenheit into Celsius
  • How to write a program to convert Fahrenheit into Celsius

tag

Addition (6) Array (38) C++ language (91) C language (98) c sharp (23) Division (6) Function (29) if else (32) Java language (102) JavaScript (5) loops (137) Multiply (7) Oop (2) patterns (65) PHP (13) Python Language (38) Subtraction (7) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2025 Code for Java c | Powered by SuperbThemes