Course Content
🎁 Bonus Modules (Integrated Throughout)
Data Analytics
Strings, Lists, Sets, and Tuples

Python offers a variety of collection data types to store and manage groups of values. Each one has different properties depending on how you want to access, update, or organize your data.


Strings (str)

A string is a sequence of characters enclosed in quotes (' ' or " "). Strings are immutable, meaning they cannot be changed after creation.

 

message = "Hello, World!"
print(message[0]) # Output: H

 

You can:

  • Access characters by index
  • Slice a portion: message[0:5]"Hello"
  • Use string methods like lower(), upper(), replace(), etc.
print(message.upper()) # HELLO, WORLD!
print(message.replace("World", "Python")) # Hello, Python!

Lists (list)

A list is an ordered, mutable collection that allows duplicates. Use square brackets [].

 

fruits = ["apple", "banana", "cherry"]
print(fruits[1]) # Output: banana

 

You can:

  • Add items: fruits.append("orange")
  • Change values: fruits[0] = "grape"
  • Remove items: fruits.remove("banana")Lists are best when you need to modify, sort, or loop through a collection in order.

Tuples (tuples)

A tuple is like a list, but immutable—you can’t change its elements after creation. Use parentheses ().

 

coordinates = (10, 20)
print(coordinates[0]) # Output: 10

 

Tuples are useful when you want to ensure the data remains constant, like coordinates, colors, or fixed values.


Sets (set)

A set is an unordered, mutable, and unique collection—duplicates are not allowed. Use curly braces {}.

 

unique_numbers = {1, 2, 3, 2}
print(unique_numbers) # Output: {1, 2, 3}

 

Sets are great for:

  • Eliminating duplicates
  • Performing set operations like union, intersection:
a = {1, 2, 3}
b = {3, 4, 5}
print(a & b) # Intersection → {3}
print(a | b) # Union → {1, 2, 3, 4, 5}

 

Note: Sets are unordered, so you can’t access elements by index.


Summary
Type Ordered Mutable Allows Duplicates Indexed
String
List
Tuple
Set
0% Complete
WhatsApp Icon

Hi Instagram Fam!
Get a FREE Cheat Sheet on System Design.

Hi LinkedIn Fam!
Get a FREE Cheat Sheet on System Design

Loved Our YouTube Videos? Get a FREE Cheat Sheet on System Design.