Notes on Lists in Python for Class 12 Computer Science
Notes on Lists in Python for Class 12 Computer Science 1. Definition A list is a built-in data structure in Python used to store multiple items in a single variable. It is one of the most versatile and commonly used sequence types. 2. Key Characteristics Ordered: Items hold a specific position (index). Mutable: You can add, remove, or change items after the list is created. Heterogeneous: Can store elements of different data types (integers, strings, booleans, even other lists) together. Allow Duplicates: The same value can appear multiple times. 3. Syntax & Creation Lists are created using square brackets [] , separating elements with commas. Python # Empty List my_list = [] # Integers numbers = [ 10 , 20 , 30 , 40 ] # Mixed Data Types mixed = [ 1 , "Hello" , 3.14 , True ] # Nested List (List inside a list) nested = [ 1 , [ 2 , 3 ], 4 ] 4. Indexing and Slicing Python uses zero-based indexing . You can access elements from the start (positive index) or t...