Python Sequences and Collections
Python offers several built-in data structures for working with sequences and collections of data. These data structures are crucial for organizing and manipulating data effectively. Some of the most commonly used ones include:
Lists: Lists are ordered collections that can hold items of different data types. They are defined using square brackets and can be modified after creation.
my_list = [1, 2, 3, 'hello', True]
Tuples: Tuples are similar to lists but are immutable, meaning their elements cannot be changed after creation. They are defined using parentheses and are often used for representing fixed sets of values.
my_tuple = (1, 2, 3, 'hello', True)
Strings: Strings are sequences of characters. They are also immutable, like tuples. Strings can be defined using single or double quotes.
my_string = "Hello, world!"
original published on https://pythonprox.blogspot.com/2023/08/python-sequences-and-collections.html