0% found this document useful (0 votes)
1 views2 pages

Unit 4 List in Python

Lists in Python are used to store multiple items in a single variable and are one of four built-in data types for data collections. They are created using square brackets, are ordered, changeable, and allow duplicate values, with items indexed starting from 0. Lists can be sliced and concatenated, allowing access to specific elements using their indices.
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)
1 views2 pages

Unit 4 List in Python

Lists in Python are used to store multiple items in a single variable and are one of four built-in data types for data collections. They are created using square brackets, are ordered, changeable, and allow duplicate values, with items indexed starting from 0. Lists can be sliced and concatenated, allowing access to specific elements using their indices.
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

List – Unit 4 Python

1) Lists are used to store multiple items in a single variable.


2) Lists are one of 4 built-in data types in Python used to store collections
of data, the other 3 are Tuple, Set, and Dictionary, all with different
qualities and usage.
3) Lists are created using square brackets:
4) Example of the list in Python
Here we are creating a Python List using [].
Python

Var = ["Geeks",
"for", "Geeks"]
print(Var)

List Items:
List items are ordered, changeable, and allow duplicate values.
List items are indexed, the first item has index [0], the second item has
index [1] etc.
Ordered
When we say that lists are ordered, it means that the items have a defined
order, and that order will not change.
If you add new items to a list, the new items will be placed at the end of the
list.
ACCESS VALUE IN LIST;
List can also be sliced and Concatenated. To access value in list, Square
brackets are used to slice along with the index or indices to get value stored
at that index.
The Syntax for the Slice operation is
Seq=List[Start:stop:step]
Example : Program to demonstrate hthe Slice operation used to access the
elements in the list
Num_list=[1,2,3,4,5,6,7,8,9,10]
Print(“num_list is:”,num_list)
Print(“First element in the list is”,num_list[0])
Print(“num_list[2:5]=”,num_list[2:5])
Print(num_list[::2]=”,num_list[::2])
Print(“num_list[1::3]=”,num_list[1::3])

Output:
Num_list is :[

You might also like