0% found this document useful (0 votes)
10 views28 pages

Lecture 4 Python Self Notes

The document provides an overview of Python programming concepts, focusing on loops, collection data types, and their characteristics. It explains the use of 'for-else' statements, break and continue statements, and details about lists and tuples, including their mutability and operations. Additionally, it includes examples of using nested loops and basic operations on lists and tuples.

Uploaded by

amedalsaby
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)
10 views28 pages

Lecture 4 Python Self Notes

The document provides an overview of Python programming concepts, focusing on loops, collection data types, and their characteristics. It explains the use of 'for-else' statements, break and continue statements, and details about lists and tuples, including their mutability and operations. Additionally, it includes examples of using nested loops and basic operations on lists and tuples.

Uploaded by

amedalsaby
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
You are on page 1/ 28

The Infinite Loop

Range function
The else block just after for/while is executed only when the loop is NOT
terminated by a break statement.

For -- else
Nested loop
Example:

• Write a python
program that
prints the
following shape:
Example:

• Write a python program that prints the following shape:


Example:
WRITE A PROGRAM USES A
N E S T E D - F O R L O O P TO
D I S P L AY M U LT I P L I C AT I O N
TA B L E S F R O M 1 - 1 2 .
Break statement
Break statement cont.
Continue statement
• There are four collection data types in the
Python programming language:
• List is a collection which is ordered and
changeable. Allows duplicate members.
Python • Tuple is a collection which is ordered and
unchangeable. Allows duplicate members.
Collections • Set is a collection which is unordered,
(Arrays) unchangeable, and unindexed. No duplicate
members.
• Dictionary is a collection which is unordered,
changeable and indexed. No duplicate
members.
lists
❑ A list is a collection which is ordered and changeable
Lists (Accessing, updating, deleting values)
Lists cont.
o lists are a mutable type, i.e. it is possible to change their content:
Basic List Operations
Built-in List Functions and Methods
Built-in List
Functions and
Methods
Cont.
Lists Cont.
It is possible to nest lists (create lists
containing other lists), for example:
List iterating
Iterating by Sequence Index
❑ A tuple is a collection of objects which ordered and immutable.
❑ Tuples are sequences, just like lists.
Tuple ❑ The main difference between the tuples and the lists is that the
tuples cannot be changed unlike lists.
❑ Tuples use parentheses, whereas lists use square brackets.
Accessing
Values in
Tuples
Updating
Tuples
❑Tuples are immutable,
which means you cannot
update or change the
values of tuple elements.
❑You are able to take
portions of the existing
tuples to create new
tuples as the following
example
Delete
Tuple
Elements
Removing individual tuple
elements is not possible.
Basic Tuples Operations
Indexing, Slicing, and Matrixes
Built-in
Tuple
Functions
Thanks

You might also like