This document discusses various array based data structures in Python including lists, tuples, dictionaries, sequences, and sets. It provides examples of how to declare and manipulate lists, describes common list methods like append and insert, explains that tuples are immutable like lists but without methods, dictionaries associate keys with values, and sequences allow membership testing and indexing.
Download as ODP, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
23 views
Array Sequence Rev
This document discusses various array based data structures in Python including lists, tuples, dictionaries, sequences, and sets. It provides examples of how to declare and manipulate lists, describes common list methods like append and insert, explains that tuples are immutable like lists but without methods, dictionaries associate keys with values, and sequences allow membership testing and indexing.
Download as ODP, PDF, TXT or read online on Scribd
You are on page 1/ 9
Array Based Sequence
in Python
List - 1
Format to Declare list variable in Python, we
can use a pair of parentheses ([])
Example : shoplist = ['apple', 'mango',
'carrot', 'banana']
To print list's content, we can use for loop or
we can use print command.
Example print shoplist
List - 2
Available methods in list :
append This method is used to append
list's item in the last of item
insert This method is used to insert an
item's list in any order
Sort this method is used to sort the list's
item
del use to del item in any index
Tuple
Tuples are used to hold together multiple
objects. Think of them as similar to lists, but without the extensive functionality that the list class gives you. One major feature of tuples is that they are immutable Tuples are usually used in cases where a statement or a user-defined function can safely assume that the collection of values i.e. the tuple of values used will not change
Dictionary
A dictionary is like an address-book where
you can find the address or contact details of a person by knowing only his/her name In dictionary we associate keys (name) with values (details). Note that the key must be unique Note that you can use only immutable objects (like strings) for the keys of a dictionary but you can use either immutable or mutable objects for the values of the dictionary.
Sequence
Lists, tuples and strings are examples of
sequences The major features is that they have membership tests (i.e. the in and not in expressions) and indexing operations. The three types of sequences mentioned above - lists, tuples and strings, also have a slicing operation which allows us to retrieve a slice of the sequence i.e. a part of the sequence.
Set
Lists, tuples and strings are examples of
sequences The major features is that they have membership tests (i.e. the in and not in expressions) and indexing operations. The three types of sequences mentioned above - lists, tuples and strings, also have a slicing operation which allows us to retrieve a slice of the sequence i.e. a part of the sequence.
Reference
When you create an object and assign it to a
variable, the variable only refers to the object and does not represent the object itself! That is, the variable name points to that part of your computer's memory where the object is stored.
Reference Byte of Python, Chapter Data Structures Data Structure and Algorithm in Python Chapter 5