Chapter 2: Introduction to Python Lists
Data & AI Transformation Lead โข 15+ years of experience in AI-driven Quality Engineering, Data Analytics, and Test Automation. โข Expertise in AI/ML, Data Testing, Cloud Automation, ETL Pipelines, and Observability tools. โข Hands-on leader in AI-driven automation, predictive analytics, and cloud data validation. โข Strong technical proficiency in Snowflake, DBT, Power BI, Python, AWS, SQL, and MLOps pipelines. โข Proven success in reducing defects, optimizing performance, and streamlining data workflows. โข Expertise in integrating security into CI/CD pipelines, automated security scanning, vulnerability assessment, and compliance-driven quality engineering. โข Expertise in JMeter, BlazeMeter, Snowflake SQL Profiler, optimizing application & data performance testing for high-scale environments. โข Strong expertise in SAFe, Scrum, and Kanban methodologies, ensuring seamless collaboration between development, testing, and operations teams.
๐น 1. List
- A collection of elements (numbers, strings, etc.)
fruits = ["apple", "banana", "cherry"]
๐น 2. Subset of List (Indexing)
- Accessing a single element using its index
print(fruits[1]) # Output: "banana"
print(fruits[-1]) # Output: "cherry"
๐น 3. Slicing
- Extracting a portion (sublist) using a range of indices
print(fruits[0:2]) # Output: ["apple", "banana"]
print(fruits[1:]) # Output: ["banana", "cherry"]
print(fruits[:2]) # Output: ["apple", "banana"]
๐น 4. Subset Slicing (Nested List)
- Access part of an inner list or string inside a list
nested = [["room", 10], ["hall", 12]]
print(nested[0][0]) # Output: "room"
print(nested[0][0][1:]) # Output: "oom" โ slicing string inside list
๐น 5. Referencing vs Copying
- Referencing: changing one affects the other
a = [1, 2, 3]
b = a
b[0] = 100
print(a) # Output: [100, 2, 3] โ both point to same list
- Copying: use slicing or
copy()
c = a[:] # or c = a.copy()
c[0] = 50
print(a) # Output: [100, 2, 3]
print(c) # Output: [50, 2, 3]
๐น 6. List Concatenation
- Adding elements to a list using the
+operator creates a new list.
โ Step-by-step Explanation:
areas = ["hallway", 11.25, "kitchen", 18.0, "chill zone", 20.0,
"bedroom", 10.75, "bathroom", 10.50]
- This is your original list with alternating room names and their sizes.
areas_1 = areas + ["poolhouse", 24.5]
A new list
areas_1is created by adding"poolhouse"and its area24.5to the end ofareas.areasremains unchanged (since+creates a copy).
areas_2 = areas_1 + ["garage", 15.45]
Another new list
areas_2is created by adding"garage"and its area15.45toareas_1.Again, this doesn't modify
areas_1.
๐น 7. List Growth Through Concatenation
Each time, a new list is created, so:
areas: original listareas_1: original + poolhouseareas_2: areas_1 + garage
โ Summary Table:
| List | Contents Added | Total Length |
areas | Original 10 elements | 10 |
areas_1 | + "poolhouse", 24.5 | 12 |
areas_2 | + "garage", 15.45 | 14 |
๐น 8. BUILT IN PYTHON FUNCTIONS
| Category | Functions | Purpose |
| Type Conversion | int(), float(), str(), bool() | Convert data types |
| Type Checking | type(), isinstance() | Check the type of a variable |
| Sequence Operations | len(), max(), min(), sum() | Work on lists, tuples, etc. |
| Mathematical | abs(), round(), pow() | Basic math operations |
| I/O Operations | print(), input() | Display or receive user input |
| Functional Programming | map(), filter(), zip(), sorted() | Apply functions to iterables |
| Object Introspection | dir(), help(), id() | Examine objects and their properties |
| Memory & ID | id() | Get unique ID of an object |
| Evaluation | eval(), exec() | Execute strings as Python code |
| Miscellaneous | any(), all(), enumerate(), range() | Utility functions for logic/iteration |

