Module 4 - While Loop, List, and Tuple
Module 4 - While Loop, List, and Tuple
While Loop,
List, and Tuple
Module 4
1
Click to edit Master title style
Outline:
• While Loop
• List
• Tuple
2
Click to
While edit Master title style
Loop
3
Click to
While edit Master title style
Loop
4
Click to
While edit Master title style
Loop
5
Clickfrom
Exit to edit
theMaster title style
While Loop
• Use the break keyword to exit the while loop at some condition
• Use the if condition to determine when to exit from the while loop
6
Click to edit
Continue NextMaster title style
Iteration
• Use the continue keyword to start the next iteration and skip the
statements after the continue statement on some conditions
7
Click to
While editwith
Loop Master
elsetitle style
Block
8
Click to edit[11]
Simulation Master title style
9
Click to List
Python edit Master title style
10
ClickData
List to edit
andMaster
Accesstitle style
11
ClickClass
List to edit Master title style
• All the list objects are the objects of the list class in Python
• Use the list() constructor to convert from other sequence types
such as tuple, set, dictionary, string to list
12
ClickIteration,
List to edit Master title
Update, andstyle
Remove
13
ClickOperators
List to edit Master title style
14
ClickOperators
List to edit Master title style
15
ClickOperators
List to edit Master title style
16
ClickOperators
List to edit Master title style
17
ClickOperators
List to edit Master title style
18
ClickMethods
List to edit Master title style
19
Click to edit[12]
Simulation Master title style
20
Click to Tuples
Python edit Master title style
21
Click to editTuples
Identifying Master title style
22
Click to edit
Accessing Master
Tuple title style
Elements
23
Click to edit
Accessing Master
Tuple title style
Elements
• If the element at the specified index does not exist, then the error
"index out of range" will be thrown
• Tuple elements can be unpacked and assigned to variables
• However, the number of variables must match with the number of
elements in a tuple; otherwise, an error will be thrown
24
Click to /edit
Update Master
Delete title
Tuple style
Elements
• Tuple is unchangeable
• So, once a tuple is created, any operation that seeks to change its
contents is not allowed
• However, you can delete an entire tuple using the del keyword
25
Click to
Tuple edit Master title style
Class
26
Click to
Tuple edit Master title style
Operations
27
Click to
Tuple edit Master title style
Operations
28
Click to
Tuple edit Master title style
Operations
29
Click to edit[13]
Simulation Master title style
30