0% found this document useful (0 votes)
94 views6 pages

Python List

A Python list is a mutable sequence type that can store different data types and be accessed by index; lists are defined using square brackets and commas to separate items, and have characteristics such as maintaining element order and allowing duplicate values. Lists in Python provide a flexible way to organize and store sequential data like collections of primitive values, strings, and other objects.

Uploaded by

Krishna Krishna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
94 views6 pages

Python List

A Python list is a mutable sequence type that can store different data types and be accessed by index; lists are defined using square brackets and commas to separate items, and have characteristics such as maintaining element order and allowing duplicate values. Lists in Python provide a flexible way to organize and store sequential data like collections of primitive values, strings, and other objects.

Uploaded by

Krishna Krishna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Python List

A list in python is used to store the


sequence of various types of data.
A list can be defined as a collection of
values or items of different types.
Python list are mutable type.
The item in the list are separated with
comma(,) and enclosed with the square
brackets[].
List Declaration: -
# a simple List
list1 = [1,2,”python”,”Program”,12.3]
list2 =
[“Army”,”Navy”,”Airforce”,”Police”]

# print the list


print(list1)
print(list2)

#printing the type of list


print(type(list1))
print(type(list2))

o/p: -
[1, 2, 'Python', 'Progam', 12.3]
['Army', 'Navy', 'Airforce', 'Police']
<class 'list'>
<class 'list'>

Characteristics of Lists: -
The list has some characteristics which
are going to see below.
 The lists are ordered sequence.
 The elements of the list can
access by index.
 The lists are the mutable type.
 A list can store the number of
various elements.

Ordered List checking: -


#example
a = [1,2,"Ram",3.50,"Rahul",5,6]
b = [1,2,5,"Ram",3.50"Rahul",6]
a == b
o/p: - False
#example
a = [1,2,"Ram",3.50,"Rahul",5,6]
b = [1,2,"Ram",3.50,"Rahul",5,6]
a == b
O/p: - True

Lists permanently preserve the


element’s order.

Example: -
#list example in details
emp = [“John”, 102, “USA”]
Dep1 = [“CS”,10]
Dep2 =[“IT”,11]
HOD_CS = [10,”Mr.Rahul”]
HOD_IT = [11,”Mr.Balu”]
print(“printing employee data…”)
Print(“Name : %s, ID: %d, Country:
%s” %(emp[0],emp[1],emp[2])
print(“printing departments...”)
print(“Department1:\nName: %s.ID:
%d\n Department2:\nName:%s, ID:
%s”%
(Dep1[0],Dep2[1],Dep2[0],Dep2[1]))
print(“HOD Details…”)
print(“CS HOD Name: %s, id: %d”
% (HOD_CS[1],HOD_CS[0]))
print(“IT HOD Name: %s, id: %d %
(HOD_IT[1],HOD_IT[0]))
o/p: -?
ERROR!
printing employee data…
Traceback (most recent call last):
File "<string>", line 10, in <module>
NameError: name 'Print' is not defined.
Did you mean: 'print'?

You might also like