SlideShare a Scribd company logo
Lists in Python
By Naimish Dobariya
Introduction to Lists
• • A list is a collection of items in a particular
order.
• • Lists are mutable (can be changed).
• • Lists can contain different data types.
Creating Lists
• • Lists are defined using square brackets []
• • Example: my_list = [1, 2, 3, 'Python', True]
Accessing Elements
• • Use indexing to access elements (zero-based
indexing)
• • Example: my_list[0] gives first element
• • Negative indexing: my_list[-1] gives last
element
Modifying Lists
• • Lists are mutable, meaning elements can be
changed.
• • Example: my_list[1] = 'New Value'
Common List Methods
• • append(): Adds an item to the end
• • insert(): Inserts an item at a specified index
• • remove(): Removes a specific item
• • pop(): Removes and returns the last or
specified item
• • sort(): Sorts the list
Looping Through Lists
• • Use a for loop to iterate through a list
• • Example:
• for item in my_list:
• print(item)
List Comprehensions
• • A concise way to create lists
• • Example: squares = [x**2 for x in range(10)]
List Operations
• • Concatenation: list1 + list2
• • Repetition: list * 3
• • Membership: 'item' in list
Examples & Exercises
• • Create a list of your favorite fruits.
• • Access the second item in the list.
• • Append a new item and print the list.
• • Remove an item from the list.

More Related Content

PPTX
List In Python Programming. The linked list
PPTX
Python Array Power Point Presentation.pptx
PDF
Python_Lists_. Full_Presentation.pdf
PDF
Data type list_methods_in_python
PPTX
lists_list_of_liststuples_of_python.pptx
PPTX
List in Python
PPTX
Python list
PPTX
Python Lists is a a evry jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj...
List In Python Programming. The linked list
Python Array Power Point Presentation.pptx
Python_Lists_. Full_Presentation.pdf
Data type list_methods_in_python
lists_list_of_liststuples_of_python.pptx
List in Python
Python list
Python Lists is a a evry jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj...

Similar to Python programing basic knowledge hh.pdf (20)

PPTX
updated_list.pptx
PPTX
Lists Data Structures and Algorithm.pptx
PPTX
list in python and traversal of list.pptx
PDF
Python lists
PPTX
Lecture2.pptx
PPTX
fundamental of python --- vivek singh shekawat
PPTX
list.pptx
PPTX
Python - List, Dictionaries, Tuples,Sets
PPTX
Pythonlearn-08-Lists.pptx
PPTX
List in Python
PPTX
powerpoint 2-13.pptx
PPTX
Brixon Library Technology Initiative
PPTX
Python list concept
PPTX
Chapter 15 Lists
PPTX
Sixth session
DOCX
Python Materials- Lists, Dictionary, Tuple
PDF
beginners_python_cheat_sheet -python cheat sheet description
PPTX
Python Lists.pptx
PPTX
LIST_tuple.pptx
updated_list.pptx
Lists Data Structures and Algorithm.pptx
list in python and traversal of list.pptx
Python lists
Lecture2.pptx
fundamental of python --- vivek singh shekawat
list.pptx
Python - List, Dictionaries, Tuples,Sets
Pythonlearn-08-Lists.pptx
List in Python
powerpoint 2-13.pptx
Brixon Library Technology Initiative
Python list concept
Chapter 15 Lists
Sixth session
Python Materials- Lists, Dictionary, Tuple
beginners_python_cheat_sheet -python cheat sheet description
Python Lists.pptx
LIST_tuple.pptx
Ad

Recently uploaded (20)

PPTX
BSCS lesson 3.pptxnbbjbb mnbkjbkbbkbbkjb
PDF
Interior Structure and Construction A1 NGYANQI
PDF
YOW2022-BNE-MinimalViableArchitecture.pdf
PDF
SEVA- Fashion designing-Presentation.pdf
PPTX
ANATOMY OF ANTERIOR CHAMBER ANGLE AND GONIOSCOPY.pptx
PPTX
EDP Competencies-types, process, explanation
PPTX
LITERATURE CASE STUDY DESIGN SEMESTER 5.pptx
PPT
WHY_R12 Uaafafafpgradeaffafafafaffff.ppt
PDF
Trusted Executive Protection Services in Ontario — Discreet & Professional.pdf
DOCX
actividad 20% informatica microsoft project
PPTX
6- Architecture design complete (1).pptx
PPT
UNIT I- Yarn, types, explanation, process
PDF
UNIT 1 Introduction fnfbbfhfhfbdhdbdto Java.pptx.pdf
PPTX
Tenders & Contracts Works _ Services Afzal.pptx
PDF
Quality Control Management for RMG, Level- 4, Certificate
PDF
Phone away, tabs closed: No multitasking
PDF
Key Trends in Website Development 2025 | B3AITS - Bow & 3 Arrows IT Solutions
PPTX
Media And Information Literacy for Grade 12
PPTX
Special finishes, classification and types, explanation
PPTX
joggers park landscape assignment bandra
BSCS lesson 3.pptxnbbjbb mnbkjbkbbkbbkjb
Interior Structure and Construction A1 NGYANQI
YOW2022-BNE-MinimalViableArchitecture.pdf
SEVA- Fashion designing-Presentation.pdf
ANATOMY OF ANTERIOR CHAMBER ANGLE AND GONIOSCOPY.pptx
EDP Competencies-types, process, explanation
LITERATURE CASE STUDY DESIGN SEMESTER 5.pptx
WHY_R12 Uaafafafpgradeaffafafafaffff.ppt
Trusted Executive Protection Services in Ontario — Discreet & Professional.pdf
actividad 20% informatica microsoft project
6- Architecture design complete (1).pptx
UNIT I- Yarn, types, explanation, process
UNIT 1 Introduction fnfbbfhfhfbdhdbdto Java.pptx.pdf
Tenders & Contracts Works _ Services Afzal.pptx
Quality Control Management for RMG, Level- 4, Certificate
Phone away, tabs closed: No multitasking
Key Trends in Website Development 2025 | B3AITS - Bow & 3 Arrows IT Solutions
Media And Information Literacy for Grade 12
Special finishes, classification and types, explanation
joggers park landscape assignment bandra
Ad

Python programing basic knowledge hh.pdf

  • 1. Lists in Python By Naimish Dobariya
  • 2. Introduction to Lists • • A list is a collection of items in a particular order. • • Lists are mutable (can be changed). • • Lists can contain different data types.
  • 3. Creating Lists • • Lists are defined using square brackets [] • • Example: my_list = [1, 2, 3, 'Python', True]
  • 4. Accessing Elements • • Use indexing to access elements (zero-based indexing) • • Example: my_list[0] gives first element • • Negative indexing: my_list[-1] gives last element
  • 5. Modifying Lists • • Lists are mutable, meaning elements can be changed. • • Example: my_list[1] = 'New Value'
  • 6. Common List Methods • • append(): Adds an item to the end • • insert(): Inserts an item at a specified index • • remove(): Removes a specific item • • pop(): Removes and returns the last or specified item • • sort(): Sorts the list
  • 7. Looping Through Lists • • Use a for loop to iterate through a list • • Example: • for item in my_list: • print(item)
  • 8. List Comprehensions • • A concise way to create lists • • Example: squares = [x**2 for x in range(10)]
  • 9. List Operations • • Concatenation: list1 + list2 • • Repetition: list * 3 • • Membership: 'item' in list
  • 10. Examples & Exercises • • Create a list of your favorite fruits. • • Access the second item in the list. • • Append a new item and print the list. • • Remove an item from the list.