Sequence Data Type

Last updated: Apr 12, 2026

Sequence Type


Sequence is the ordered collection of similar or different data types. Sequences allow you to store multiple values in an organized and efficient fashion. There are several sequence types in Python:
  • String
  • List
  • Tuple

String

Creating a String: Strings are arrays of bytes representing Unicode characters. String is a collection of one or more characters put in a single quote, double-quote or triple quote. In Python there is no character data type, a character is a string of length one. It is represented by the str class.

Example:

# Creation of String

# Single Quotes
String1 = 'Welcome to the Libed'
print("String with the use of Single Quotes: ")
print(String1)

# Double Quotes
String1 = "I'm a Python Developer"
print("\nString with the use of Double Quotes: ")
print(String1)
print(type(String1))

# Triple Quotes
String1 = '''I'm a Developer and I am learning from "Libed"'''
print("\nString with the use of Triple Quotes: ")
print(String1)
print(type(String1))

# Creating String with triple quotes allows multiple lines
String1 = '''Liberation
            By
            Education'''
print("\nCreating a multiline String: ")
print(String1)

Output:

String with the use of Single Quotes:
Welcome to the Libed

String with the use of Double Quotes:
I'm a Python Developer
<class 'str'>

String with the use of Triple Quotes:
I'm a Developer and I am learning from "Libed"
<class 'str'>

Creating a multiline String:
Liberation
            By
            Education

Accessing characters: Individual characters of a string can be accessed by using the method of indexing. Indexing allows negative addresses to access characters from the back of the string.

L I B E D
0 1 2 3 4
-5 -4 -3 -2 -1

Example:

# Access characters of String
String1 = "LIBED"
print("Initial String: ")
print(String1)

# Printing First character
print("\nFirst character of String is: ")
print(String1[0])

# Printing Last character
print("\nLast character of String is: ")
print(String1[-1])

Output:

Initial String:
LIBED

First character of String is:
L

Last character of String is:
D

List

Lists are just like dynamically sized arrays, declared in other languages. In simple language, a list is a collection of things, enclosed in [ ] and separated by commas. Lists are created using [ ].

Var = ["Libed", "Tutorials"]
print(Var)
['Libed', 'Tutorials']

Lists are the simplest containers that are an integral part of the Python language. Lists need not be homogeneous always which makes it the most powerful tool in Python. A single list may contain data types like integers, strings, as well as objects. List is a collection which is ordered and mutable. Since lists are mutable they can be altered even after their creation. It will also allow duplicate members.

Creating a List in Python: Lists in Python can be created by just placing the sequence inside the square brackets [ ]. Unlike sets, a list doesn't need a built-in function for its creation of a list.

Example:

# Creating a List
List = []
print("Blank List: ")
print(List)

# Creating a List of numbers
List = [10, 20, 30]
print("\nList of numbers: ")
print(List)

# Creating a List of strings and accessing using index
List = ["Libed", "Python", "Tutorial"]
print("\nList Items: ")
print(List[0])
print(List[2])

Output:

Blank List:
[]

List of numbers:
[10, 20, 30]

List Items:
Libed
Tutorial

Tuples

Tuple is a collection of Python objects much like a list. The sequence of values stored in a tuple can be of any type, and they are indexed by integers. Values of a tuple are syntactically separated by 'commas'. A tuple can be defined by closing the sequence of values in parentheses. Tuple is a collection which is ordered and immutable. Allows duplicate members.

Creating a Tuple: Tuples are created by placing a sequence of values separated by 'comma' with or without the use of parentheses for grouping the data sequence. Creation of tuples without the use of parentheses is known as Tuple Packing.

Example:

# Creating an empty Tuple
Tuple1 = ()
print("Initial empty Tuple: ")
print(Tuple1)

# Creating a Tuple with the use of string
Tuple1 = ('Libed', 'Tutorial')
print("\nTuple with the use of String: ")
print(Tuple1)

# Creating a Tuple with the use of list
list1 = [1, 2, 4, 5, 6]
print("\nTuple using List: ")
print(tuple(list1))

# Creating a Tuple with the use of built-in function
Tuple1 = tuple('Python')
print("\nTuple with the use of function: ")
print(Tuple1)

Output:

Initial empty Tuple:
()

Tuple with the use of String:
('Libed', 'Tutorial')

Tuple using List:
(1, 2, 4, 5, 6)

Tuple with the use of function:
('P', 'y', 't', 'h', 'o', 'n')