0% found this document useful (0 votes)
17 views1 page

Python Data Structures Guide

Uploaded by

topgsprites
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views1 page

Python Data Structures Guide

Uploaded by

topgsprites
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

**PYTHON 101: CORE DATA STRUCTURES REFERENCE GUIDE**

This document provides a quick overview of the four fundamental built-in data
structures in Python, useful for beginners and intermediate coders.

**1. LIST (mutable, ordered)**


* **Definition:** A collection of items that is ordered and changeable. Allows
duplicate members.
* **Syntax:** Defined with square brackets: `my_list = [10, "apple", True]`
* **Key Operations:**
* Adding elements: `.append()`, `.insert()`
* Removing elements: `.remove()`, `.pop()`
* Accessing: `my_list[index]`

**2. TUPLE (immutable, ordered)**


* **Definition:** A collection of items that is ordered and **unchangeable**
(immutable). Allows duplicate members. Used when data integrity is crucial.
* **Syntax:** Defined with parentheses: `my_tuple = (5, "banana", 3.14)`
* **Key Operations:**
* Cannot add, remove, or modify elements after creation.
* Accessing: `my_tuple[index]`
* Used for function return values that shouldn't change.

**3. SET (mutable, unordered, unique)**


* **Definition:** A collection of **unique** items that is unordered and unindexed.
Does not allow duplicates.
* **Syntax:** Defined with curly braces: `my_set = {"red", "blue", "green"}`
* **Key Operations:**
* Adding elements: `.add()`
* Set math operations: `.union()`, `.intersection()`, `.difference()`
* Used efficiently to check for membership.

**4. DICTIONARY (mutable, unordered, key-value pairs)**


* **Definition:** A collection of **key-value pairs**. Ordered from Python 3.7+;
changeable. Keys must be unique and immutable.
* **Syntax:** Defined with curly braces and colons: `my_dict = {"name": "Alice",
"age": 30}`
* **Key Operations:**
* Accessing values: `my_dict["key"]`
* Adding/Updating: `my_dict["city"] = "NY"`
* Getting all keys: `.keys()`
* Getting all values: `.values()`

You might also like