Python data structures¶
Python data structures are used to store and organize collections of data efficiently. The most common structures include lists (often referred to as arrays) and dictionaries, which allow for the management of complex data sets such as customer records.^[400-devops__09-Scripting-Language__python__introduction__README.md]
Lists (Arrays)¶
Lists are ordered collections of items that can hold multiple values.^[400-devops__09-Scripting-Language__python__introduction__README.md] They are typically used when a sequence of data, such as a list of customer names, needs to be stored and accessed.^[400-devops__09-Scripting-Language__python__introduction__README.md]
Accessing and Modifying Elements¶
Items within a list are accessed using a zero-based index^[400-devops__09-Scripting-Language__python__introduction__README.md]. For example, the first item is located at index 0.^[400-devops__09-Scripting-Language__python__introduction__README.md] While values can be retrieved by their index, lists in Python are dynamic in size; new items are added using the append() method rather than assigning to a specific index.^[400-devops__09-Scripting-Language__python__introduction__README.md] Items can be removed from the list using the remove() function.^[400-devops__09-Scripting-Language__python__introduction__README.md]
Dictionaries¶
Dictionaries are data structures that store key-value pairs.^[400-devops__09-Scripting-Language__python__introduction__README.md] Unlike arrays, which require knowing the index number to find an item, dictionaries allow items to be retrieved using a specific key, such as a unique customer ID.^[400-devops__09-Scripting-Language__python__introduction__README.md]
Manipulation¶
You can create or update items in a dictionary by assigning a value to a specific key^[400-devops__09-Scripting-Language__python__introduction__README.md]. Retrieval is done by accessing the dictionary with the desired key^[400-devops__09-Scripting-Language__python__introduction__README.md].
Related Concepts¶
- [[Classes and Objects]]: Used to group variables into more complex data types.
- [[Loops]]: Used to iterate over data structures.
- [[Variables]]: Used to hold data within structures.
Sources¶
- 400-devops__09-Scripting-Language__python__introduction__README.md