0% found this document useful (0 votes)
3 views54 pages

11.python Lists

The document provides an overview of Python lists, highlighting their characteristics such as being ordered, changeable, and allowing duplicate values. It covers various operations including accessing, modifying, adding, and removing items, as well as methods for sorting and joining lists. Additionally, it includes examples of list comprehensions and generating lists based on specific criteria.
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)
3 views54 pages

11.python Lists

The document provides an overview of Python lists, highlighting their characteristics such as being ordered, changeable, and allowing duplicate values. It covers various operations including accessing, modifying, adding, and removing items, as well as methods for sorting and joining lists. Additionally, it includes examples of list comprehensions and generating lists based on specific criteria.
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

Python Lists

Example
List Items
• Ordered,
• Changeable,
• Allow Duplicate Values.

• List items are indexed, the first item has index [0], the second
item has index [1] etc.
• Ordered
Lists are ordered, it means that the items have a defined order, and
that order will not change.

• Changeable
The list is changeable, meaning that we can change, add, and
remove items in a list after it has been created.

• Allow Duplicates
Lists are indexed, lists can have items with the same value.
Allow Duplicates Example
List Length
Different Data Types
list() Constructor
Access List Items
Access Items
Negative Indexing
Range of Indexes
Example
Check if Item Exists
Change List Items
Change a Range of Item Values
Add List Items
Append Items
• To add an item to the end of the list, use the append() method
Insert Items
Extend List
Remove List Items
Remove Specified Item
Remove Specified Index
pop() -Remove Last Item
Del - Remove Specified Index
Delete List Complete
Clear List
Python - Loop Lists
list Items - Loop
Loop - Index Numbers
While Loop
List Comprehension
List Comprehension
Example
New List Upper Case:
Set all values in the new list to 'hello'
Sort Lists
• List objects have a sort() method that will sort the list
alphanumerically, ascending, by default.
Sort Lists
Sort the list Numerical
Sort Descending
Reverse Order
Copy Lists
Copy Lists
Join Lists
Python - Join Lists
Example
Extend() Method
Create a List of Squares of numbers
from 1 to 10
Create a List of Even numbers
from 1 to 20
Generate a list of characters from a string
Create a list of lengths of words in a
sentence
Generate a List of Tuples Containing a
Number and its Square
Generate a list of common multiples of 3
and 5 up to 100
Thank You

You might also like