This Edureka Python tutorial will help you in learning various sequences in Python - Lists, Tuples, Strings, Sets, Dictionaries. It will also explain various operations possible on them. Below are the topics covered in this tutorial:
1. Python Sequences
2. Python Lists
3. Python Tuples
4. Python Sets
5. Python Dictionaries
6. Python Strings
4. www.edureka.co/pythonEDUREKA PYTHON CERTIFICATION TRAINING
What Are Sequences?
➢ Sequences are containers with items that are accessible by indexing or slicing.
➢ The built-in len function takes any container as an argument and returns the number of items in the container.
Sequence of Cars
14. www.edureka.co/pythonEDUREKA PYTHON CERTIFICATION TRAINING
Lists
Fruits = ['Mango', 'Apple', 'Grapes'] List.append(elem)
List.insert(index,elem)
List.extend(list2)
List.index(elem)
List.remove(elem)
List.sort()
List.reverse()
Append
Extend
Insert
Index
Remove
Sort
Reverse
The list is a most versatile datatype available in Python which can be written as a list of comma-separated
values (items) between square brackets. Important thing about a list is that items in a list need not be of
the same type.
16. www.edureka.co/pythonEDUREKA PYTHON CERTIFICATION TRAINING
Tuples
➢ A tuple is a sequence of immutable Python objects.
➢ Tuples are sequences, just like lists. The differences between tuples and lists are, the
tuples cannot be changed unlike lists and tuples use parentheses.
Fruits = ('Mango', 'Apple', 'Grapes‘)
Tuple.index(elem)Index
Tuple.count(elem)Count
Tuple1+Tuple2Concatenation
Tuple[range]Slicing
Tuple * xRepetition
18. www.edureka.co/pythonEDUREKA PYTHON CERTIFICATION TRAINING
Strings
➢ We can create them simply by enclosing characters in quotes.
➢ Python treats single quotes the same as double quotes.
Fruits = 'Mango Apple Grapes'
String[range]
Updating
Slicing
Concatenation
Reverse
Repetition
Membership
String[range] + ‘x’
String 1 + String 2
String 1 * x
In, not in
String [:-1]
20. www.edureka.co/pythonEDUREKA PYTHON CERTIFICATION TRAINING
Sets
➢ A set contains an unordered collection of unique and immutable objects.
➢ The set data type is, as the name implies, a Python implementation of the
sets as they are known from mathematics.
A BA B
A B
C
(A C) / B (B C) / A
C
Fruits = {'Mango', 'Apple', 'Grapes‘}
Slicing
Add Element
Clear
Copy
Difference
Discard
Remove
Intersection
22. www.edureka.co/pythonEDUREKA PYTHON CERTIFICATION TRAINING
Dictionaries
➢ Dictionary is an unordered collection of key-value pairs.
➢ It is generally used when we have a huge amount of data.
Example:
Length
del d [K]
Membership Testing
Key
Value