2. WHAT IS SEQUENCE?
• A sequence is a collection of objects, arranged in a particular order. A
sequence can be either a list, a tuple, or a string. Sequences are
inerrable, meaning you can loop over the elements in a sequence
one by one.
• Sequences are containers with items stored in a deterministic
ordering. Each sequence data type comes with its unique capabilities.
3. SEQUENCE TYPE OPERATORS
Sequence Operator Function
seq[ind] Element located at index ind of seq
seq[ind1:ind2] Elements from ind1 up to but not including ind2 of seq
seq * expr seq repeated expr times
seq1 + seq2 Concatenates sequences seq1 and seq2
obj in seq Tests if obj is a member of sequence seq
obj not in seq Tests if obj is not a member of sequence seq
4. TYPES OF SQUENCES
THERE ARE SIX TYPES OF SEQUENCES NAMELY;
1. STRING
2. LIST
3. TUPLES
4. BYTES SEQUENCES
5. BYTE ARRAYS
6. RANGE()OBJECTS
5. STRINGS
• Strings in python are surrounded by either single quotation marks, or double
quotation marks.
• 'hello' is the same as "hello". We can create string using str()function also.
• We can literally display string with print()statement;
• Example: Creating a string
print(“Hello”)
print(‘hello’)
6. HOW TO ACCESS VALUES
• Assigning a string to a variable is done with the variable name followed by an equal sign
and the string:
Example:
>>>a = "Hello"
>>>print(a)
Output:
Hello
>>>a[1:5]
Output:
"ello"
7. UPDATE A STRING
• You can “update” an existing string by (re)assigning a variable to another
string
>>> aString = aString[:6] + 'Python!’
>>> aString
'Hello Python!’
8. REMOVE A STRING
• strings are immutable, so you cannot remove individual characters from an existing
string.
Example:
>>> aString = ‘’
>>> aString
‘’
>>>del aString
9. MULTILINE STRINGS
• You can assign a multiline string to a variable by using three
quotes:
Example:
a = """welcome all ,
Good to see you all,
Good morning"""
print(a)
10. STRINGS ARE ARRAYS
• strings in Python are arrays of bytes representing Unicode
characters. Python does not have a character data type.
• Square brackets can be used to access elements of the
string.
Example: a = "Hello, World!"
print(a[1])
11. PYTHON - STRING METHODS
• Python has a set of built-in methods that you can use on
strings.
Method Description
capitalize() Converts the first character to upper case
casefold() Converts string into lower case
center() Returns a centered string
count() Returns the number of times a specified value occurs in a string
lower() Converts a string into lower case
replace() Returns a string where a specified value is replaced with a
specified value
split() Splits the string at the specified separator, and returns a list
12. LIST
• Lists are used to store multiple items in a single variable.
• Lists are one of 4 built-in data types in Python used to store
collections of data.
• Lists are created using square brackets.
Example: Creating a list,
13. LIST ITEMS
• List items are ordered, changeable, and allow duplicate values.
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
14. CHANGEABLE
• The list is changeable, meaning that we can change, add, and
remove items in a list after it has been created.
ALLOW DUPLICATES
• Since lists are indexed, lists can have items with the same value:
Example:
15. LIST LENGTH
• To determine how many items a list has,use len()function;
Example
Print the number of items in the list:
16. TUPLE
• Tuples are used to store multiple items in a single variable.
• A tuple is a collection which is ordered and unchangeable.
• Tuples are written with round brackets.
Example
• Create a Tuple:
17. UPDATE TUPLE
• Tuple items are ordered, unchangeable, and allow duplicate
values.
Example:
18. TUPLE METHODS
METHOD DESCRIPTION
count() Returns the number of times a specified value occurs in a tuple
index() Searches the tuple for a specified value and returns the position of where it was found