0% found this document useful (0 votes)
2 views3 pages

List Tuple Python

The document outlines basic operations for lists and tuples in programming, including creation, accessing elements, modification, and methods for manipulation. Lists are mutable and support operations like adding, removing, and sorting elements, while tuples are immutable and provide methods for accessing and counting elements. Key concepts include indexing, slicing, and tuple unpacking.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

List Tuple Python

The document outlines basic operations for lists and tuples in programming, including creation, accessing elements, modification, and methods for manipulation. Lists are mutable and support operations like adding, removing, and sorting elements, while tuples are immutable and provide methods for accessing and counting elements. Key concepts include indexing, slicing, and tuple unpacking.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1. Creating a List 6.

Looping Through a List

You can create a list using square brackets []: Using a for loop

Using a while loop

2. Accessing List Elements


7. List Slicing
Indexing
Extract a portion of the list:
Lists use zero-based indexing, meaning the first
element is at index 0.

3. Modifying a List 8. Sorting and Reversing a List

Lists are mutable, meaning elements can be Sorting a List


changed.

4. Adding Elements to a List

Using append() (adds at the end) Reverse a list

5. Removing Elements from a List

Using pop() (removes by index and returns the


value)
9. Copying a List Using while loop

1. Creating a Tuple

Tuples are created using parentheses (). 6. Tuple Length

To find the number of elements in a tuple:

7. Concatenating and Repeating Tuples

Concatenation (Joining Two Tuples)

2. Accessing Tuple Elements

Tuples use zero-based indexing like lists.

8. Checking if an Element Exists in a Tuple

4. Tuples are Immutable

Once a tuple is created, its elements cannot be


modified.
9. Tuple Methods

Even though tuples are immutable, they have


some useful methods.

5. Looping Through a Tuple Finding the Index of an Element

Using a for loop

Counting the Occurrences of an Element


10. Unpacking Tuples

Tuple unpacking allows you to assign multiple


values at once.

You might also like