SlideShare a Scribd company logo
PE1 Module 3
Sequence Data Types and Control
Structures in Python
2
Sequence Data Types
 Sequence data types allow you to store multiple
items/values in an organized and efficient fashion.
 The items are stored in sequence one after another
 Basic Sequence types:
list
tuple
3
Python Lists
 Lists are the most versatile of Python’s sequence
data types.
 A list is mutable: the items in the sequence can be
changed
 A list contains items separated by commas and
enclosed within square brackets [ ].
 The values stored in a list can be accessed using [ ]
or [ : ] ) with indexes starting at 0 in the beginning of
the list and working their way to end-1.
 The plus + sign is the list concatenation operator,
and the asterisk * is the repetition operator.
4
Python Lists
 The type() function in Python returns the data type
of the object passed to it as an argument.
5
Python Lists
6
Python Lists
Boeing 737 is no longer available and replaced by
Boeing 737 Original
7
List Slicing
 Slice: a span of items that are taken from a sequence
List slicing format: list[start : end]
Span is a list containing copies of elements from start
up to, but not including, end
If start not specified, 0 is used for start index
If end not specified, len(list) is used for end index
8
List Methods and Useful Built-in
Functions
 Len(): returns the length of a list
 sorted(): used to sort the elements of the list.
9
List Methods and Useful Built-in
Functions
 append(item): used to add items to a list – item is
appended to the end of the existing list.
10
List Methods and Useful Built-in
Functions
 insert(index, item): used to insert item at position index in
the list.
11
List Methods and Useful Built-in
Functions
 index(item): used to determine where an item is located
in a list
Returns the index of the first element in the list
containing item
Raises ValueError exception if item not in the list
12
List Methods and Useful Built-in
Functions (cont’d.)
 remove(item): removes the first occurrence of item in
the list
13
List Methods and Useful Built-in
Functions (cont’d.)
 reverse(): reverses the order of the elements in the list
 Activity: What will be the output of fighter_jets.reverse()
 clear(): The clear() method removes all the elements from a list.
14
List Methods and Useful Built-in
Functions (cont’d.)
 copy(): The Python copy() method creates a copy of an
existing list.
15
List Methods and Useful Built-in
Functions (cont’d.)
 del: removes an element from a specific index in a list
or name of the list from memory.
 print(boeing_planes)
16
List Methods and Useful Built-in
Functions (cont’d.)
 print(boeing_planes_copy)
 copy(): deep copy, the copy remains even the original
source is removed .
17
Shallow Copy
 Assignment operator(=) to copy a list: The assignment operator
( = ) only creates a reference to an object, and will create a new
variable referencing the same memory address.
18
List Methods and Useful Built-in
Functions (cont’d.)
 min and max functions: built-in functions that returns the
item that has the lowest or highest value in a sequence
The sequence is passed as an argument
Count(): method counts how many times an element has.
 What will be the output of print( fighter_jets.count(" Tiger
Moth"))
19
Tuples
 Tuple: an immutable sequence
 Very similar to a list
 Once it is created it cannot be changed
 A tuple contains items separated by commas and
enclosed within square brackets ().
 Tuples support operations as lists
Subscript indexing for retrieving elements
Methods such as index
Built in functions such as len, min, max, count, index
Slicing expressions
20
Tuples
 Tuples do not support the methods:
append
remove
insert
reverse
sorted
21
Control Structures
 Control flow is the order that instructions are executed in a program.
 A control statement is a statement that determines the control flow of a set of
instructions.
 A control structure is a set of instructions and the control statements
controlling their execution.
 The fundamental forms of controls in programming are:
1. Sequential statements ,
2. Selection/ Conditional statements ,
3. Iterative/loop statements .
4. Jump statements
 A program consisting of only sequential control is referred to as a “straight-
line program.”
 Selection control is provided by a control statement that selectively executes
instructions.
 Iterative control is provided by an iterative control statement that repeatedly
executes instructions.
 Jump statements are statements through which we can transfer control
anywhere in the program.
22
Sequential statements
 Sequential control is the default control structure;
instructions are executed one after another.
Statement 1
Statement 2
Statement 3
……..
……..
……..
23
Sequential Statement
24
Selection Statements
 The selection control statements are also known as
Decision control statements or conditional branching
statements.
 A conditional statement will select the block of statements
that will execute based on the given condition.
 A selection statement causes the program control to be
transferred to a specific flow based upon whether a certain
condition is true or not.
 The statements used to perform conditional branching :
if
if-else
if- elif-else
25
if Statement
 if statements are control flow statements that help us to run a
particular code, but only when a certain condition is met or
satisfied.
26
if Statement
Discus the output of the following codes:
27
if-else Statements
 The if-else statement evaluates the condition and will execute
the body of if, if the test condition is True, but if the
condition is False, then the body of else is executed.
28
if-else Statements
29
if-else Statements
Discus the output of the following codes:
30
if-else Statements
Discus the output of the following codes:
31
if- elif-else Statement
 if-elif-else: The if-elif-else statement is used to conditionally
execute a statement or a block of statements.
32
if- elif-else Statement
33
if- elif-else Statement
Discus the output of the following codes:
34
Iterative/Loop/Repetition statements
 A repetition statement is used to repeat a
group(block) of programming instructions.
 In Python, we generally have two loops/repetitive
statements:
for loop
while loop
35
for Loop
 A for loop is used to iterate over a sequence.
36
for Loop
friends = ['Jonathan', 'Kedija', 'Eba']
for friend in friends :
print('Happy New Year:', friend)
print('Done!')
Happy New Year: Jonathan
Happy New Year: Kedija
Happy New Year: Eba
Done!
37
for Loop
38
The range() function
 To achieve the functionality of conventional for-loop in
Python, the range() function is used. It returns a list of
integers.
39
The range() function
 r= range(10) is equivalent to r=range(0,10): the range function
starts at 0 and goes up to but does not include 10 for
sequences.
40
range() function in for Loop
 when the range() receives 3 arguments, the sequence starts at the
first value, ends before the second argument and increments or
decrements by the third value.
41
while loop
 A while loop consists of a condition and until that condition
is true, a set of statements is executed repeatedly.
42
while Loop
 Example : Program displays 1 – 5, after loop terminates,
num will be 6
43
Jump Statements
 Jump statements in python are used to alter the flow of
a loop like you want to skip a part of a loop or
terminate a loop.
 Types of jump statements in python:
continue
break
pass
44
continue Statement
 When the program encounters the continue statement, it will
skip all the statements present after the continue statement
inside the loop, and proceed with the next iterations.
 When continue executed in a while loop
 Current iteration of the loop terminates
 Execution returns to the loop’s header
45
break Statement
 A break statement in Python exits out of a loop.
 It terminates the execution of the loop.
46
pass Statement
 A pass statement is an empty/null statement that is considered
as a placeholder for future code.
 Empty code shouldn’t be included in loops, function definitions,
class definitions, or if statements because there is a possibility
that it will cause an error. To avoid errors, the user can simply
apply a pass statement.
47
Any Question?
Thank You!

More Related Content

Similar to PE1 Module 3.ppt

Python_Module_2.pdf
Python_Module_2.pdfPython_Module_2.pdf
Python_Module_2.pdf
R.K.College of engg & Tech
 
16. Arrays Lists Stacks Queues
16. Arrays Lists Stacks Queues16. Arrays Lists Stacks Queues
16. Arrays Lists Stacks Queues
Intro C# Book
 
if else python.pdf
if else python.pdfif else python.pdf
if else python.pdf
Gshs6
 
theory of programming languages by shikra
theory of programming languages by shikratheory of programming languages by shikra
theory of programming languages by shikra
jateno3396
 
Day2
Day2Day2
Data Structures: Stacks (Part 1)
Data Structures: Stacks (Part 1)Data Structures: Stacks (Part 1)
Data Structures: Stacks (Part 1)
Ramachandra Adiga G
 
Data Structures by Maneesh Boddu
Data Structures by Maneesh BodduData Structures by Maneesh Boddu
Data Structures by Maneesh Boddu
maneesh boddu
 
Introduction to C++.pptx learn c++ and basic concepts of OOP
Introduction to C++.pptx learn c++ and basic concepts of OOPIntroduction to C++.pptx learn c++ and basic concepts of OOP
Introduction to C++.pptx learn c++ and basic concepts of OOP
UbaidKhan930128
 
ppt python notes list tuple data types ope
ppt python notes list tuple data types opeppt python notes list tuple data types ope
ppt python notes list tuple data types ope
SukhpreetSingh519414
 
functions- best.pdf
functions- best.pdffunctions- best.pdf
functions- best.pdf
MikialeTesfamariam
 
c_programming.pdf
c_programming.pdfc_programming.pdf
c_programming.pdf
Home
 
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docx
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docxAssg 05 QuicksortCOSC 2336 Data StructuresObjectives.docx
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docx
jane3dyson92312
 
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docx
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docxAssg 05 QuicksortCOSC 2336 Data StructuresObjectives.docx
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docx
festockton
 
Ppt on java basics1
Ppt on java basics1Ppt on java basics1
Ppt on java basics1
Mavoori Soshmitha
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
AMAN ANAND
 
Ch-8.pdf
Ch-8.pdfCh-8.pdf
Control structures ii
Control structures ii Control structures ii
Control structures ii
Ahmad Idrees
 
Maxbox starter
Maxbox starterMaxbox starter
Maxbox starter
Max Kleiner
 
Python_UNIT-I.pptx
Python_UNIT-I.pptxPython_UNIT-I.pptx
Python_UNIT-I.pptx
mustafatahertotanawa1
 
UNIT II_python Programming_aditya College
UNIT II_python Programming_aditya CollegeUNIT II_python Programming_aditya College
UNIT II_python Programming_aditya College
Ramanamurthy Banda
 

Similar to PE1 Module 3.ppt (20)

Python_Module_2.pdf
Python_Module_2.pdfPython_Module_2.pdf
Python_Module_2.pdf
 
16. Arrays Lists Stacks Queues
16. Arrays Lists Stacks Queues16. Arrays Lists Stacks Queues
16. Arrays Lists Stacks Queues
 
if else python.pdf
if else python.pdfif else python.pdf
if else python.pdf
 
theory of programming languages by shikra
theory of programming languages by shikratheory of programming languages by shikra
theory of programming languages by shikra
 
Day2
Day2Day2
Day2
 
Data Structures: Stacks (Part 1)
Data Structures: Stacks (Part 1)Data Structures: Stacks (Part 1)
Data Structures: Stacks (Part 1)
 
Data Structures by Maneesh Boddu
Data Structures by Maneesh BodduData Structures by Maneesh Boddu
Data Structures by Maneesh Boddu
 
Introduction to C++.pptx learn c++ and basic concepts of OOP
Introduction to C++.pptx learn c++ and basic concepts of OOPIntroduction to C++.pptx learn c++ and basic concepts of OOP
Introduction to C++.pptx learn c++ and basic concepts of OOP
 
ppt python notes list tuple data types ope
ppt python notes list tuple data types opeppt python notes list tuple data types ope
ppt python notes list tuple data types ope
 
functions- best.pdf
functions- best.pdffunctions- best.pdf
functions- best.pdf
 
c_programming.pdf
c_programming.pdfc_programming.pdf
c_programming.pdf
 
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docx
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docxAssg 05 QuicksortCOSC 2336 Data StructuresObjectives.docx
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docx
 
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docx
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docxAssg 05 QuicksortCOSC 2336 Data StructuresObjectives.docx
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docx
 
Ppt on java basics1
Ppt on java basics1Ppt on java basics1
Ppt on java basics1
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
Ch-8.pdf
Ch-8.pdfCh-8.pdf
Ch-8.pdf
 
Control structures ii
Control structures ii Control structures ii
Control structures ii
 
Maxbox starter
Maxbox starterMaxbox starter
Maxbox starter
 
Python_UNIT-I.pptx
Python_UNIT-I.pptxPython_UNIT-I.pptx
Python_UNIT-I.pptx
 
UNIT II_python Programming_aditya College
UNIT II_python Programming_aditya CollegeUNIT II_python Programming_aditya College
UNIT II_python Programming_aditya College
 

More from balewayalew

slides.06.pptx
slides.06.pptxslides.06.pptx
slides.06.pptx
balewayalew
 
slides.07.pptx
slides.07.pptxslides.07.pptx
slides.07.pptx
balewayalew
 
slides.08.pptx
slides.08.pptxslides.08.pptx
slides.08.pptx
balewayalew
 
Chapter 1-Introduction.ppt
Chapter 1-Introduction.pptChapter 1-Introduction.ppt
Chapter 1-Introduction.ppt
balewayalew
 
Data Analytics.ppt
Data Analytics.pptData Analytics.ppt
Data Analytics.ppt
balewayalew
 
PE1 Module 4.ppt
PE1 Module 4.pptPE1 Module 4.ppt
PE1 Module 4.ppt
balewayalew
 
PE1 Module 2.ppt
PE1 Module 2.pptPE1 Module 2.ppt
PE1 Module 2.ppt
balewayalew
 
Chapter -6- Ethics and Professionalism of ET (2).pptx
Chapter -6- Ethics and Professionalism of ET (2).pptxChapter -6- Ethics and Professionalism of ET (2).pptx
Chapter -6- Ethics and Professionalism of ET (2).pptx
balewayalew
 
Chapter -5- Augumented Reality (AR).pptx
Chapter -5- Augumented Reality (AR).pptxChapter -5- Augumented Reality (AR).pptx
Chapter -5- Augumented Reality (AR).pptx
balewayalew
 
Chapter 8.ppt
Chapter 8.pptChapter 8.ppt
Chapter 8.ppt
balewayalew
 
PE1 Module 1.ppt
PE1 Module 1.pptPE1 Module 1.ppt
PE1 Module 1.ppt
balewayalew
 
chapter7.ppt
chapter7.pptchapter7.ppt
chapter7.ppt
balewayalew
 
chapter6.ppt
chapter6.pptchapter6.ppt
chapter6.ppt
balewayalew
 
chapter5.ppt
chapter5.pptchapter5.ppt
chapter5.ppt
balewayalew
 
chapter4.ppt
chapter4.pptchapter4.ppt
chapter4.ppt
balewayalew
 
chapter3.ppt
chapter3.pptchapter3.ppt
chapter3.ppt
balewayalew
 
chapter2.ppt
chapter2.pptchapter2.ppt
chapter2.ppt
balewayalew
 
chapter1.ppt
chapter1.pptchapter1.ppt
chapter1.ppt
balewayalew
 
Ch 1-Non-functional Requirements.ppt
Ch 1-Non-functional Requirements.pptCh 1-Non-functional Requirements.ppt
Ch 1-Non-functional Requirements.ppt
balewayalew
 
Ch 6 - Requirement Management.pptx
Ch 6 - Requirement Management.pptxCh 6 - Requirement Management.pptx
Ch 6 - Requirement Management.pptx
balewayalew
 

More from balewayalew (20)

slides.06.pptx
slides.06.pptxslides.06.pptx
slides.06.pptx
 
slides.07.pptx
slides.07.pptxslides.07.pptx
slides.07.pptx
 
slides.08.pptx
slides.08.pptxslides.08.pptx
slides.08.pptx
 
Chapter 1-Introduction.ppt
Chapter 1-Introduction.pptChapter 1-Introduction.ppt
Chapter 1-Introduction.ppt
 
Data Analytics.ppt
Data Analytics.pptData Analytics.ppt
Data Analytics.ppt
 
PE1 Module 4.ppt
PE1 Module 4.pptPE1 Module 4.ppt
PE1 Module 4.ppt
 
PE1 Module 2.ppt
PE1 Module 2.pptPE1 Module 2.ppt
PE1 Module 2.ppt
 
Chapter -6- Ethics and Professionalism of ET (2).pptx
Chapter -6- Ethics and Professionalism of ET (2).pptxChapter -6- Ethics and Professionalism of ET (2).pptx
Chapter -6- Ethics and Professionalism of ET (2).pptx
 
Chapter -5- Augumented Reality (AR).pptx
Chapter -5- Augumented Reality (AR).pptxChapter -5- Augumented Reality (AR).pptx
Chapter -5- Augumented Reality (AR).pptx
 
Chapter 8.ppt
Chapter 8.pptChapter 8.ppt
Chapter 8.ppt
 
PE1 Module 1.ppt
PE1 Module 1.pptPE1 Module 1.ppt
PE1 Module 1.ppt
 
chapter7.ppt
chapter7.pptchapter7.ppt
chapter7.ppt
 
chapter6.ppt
chapter6.pptchapter6.ppt
chapter6.ppt
 
chapter5.ppt
chapter5.pptchapter5.ppt
chapter5.ppt
 
chapter4.ppt
chapter4.pptchapter4.ppt
chapter4.ppt
 
chapter3.ppt
chapter3.pptchapter3.ppt
chapter3.ppt
 
chapter2.ppt
chapter2.pptchapter2.ppt
chapter2.ppt
 
chapter1.ppt
chapter1.pptchapter1.ppt
chapter1.ppt
 
Ch 1-Non-functional Requirements.ppt
Ch 1-Non-functional Requirements.pptCh 1-Non-functional Requirements.ppt
Ch 1-Non-functional Requirements.ppt
 
Ch 6 - Requirement Management.pptx
Ch 6 - Requirement Management.pptxCh 6 - Requirement Management.pptx
Ch 6 - Requirement Management.pptx
 

Recently uploaded

ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
Rahul
 
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
Mukeshwaran Balu
 
digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
drwaing
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
insn4465
 
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
awadeshbabu
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
SUTEJAS
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
jpsjournal1
 
Exception Handling notes in java exception
Exception Handling notes in java exceptionException Handling notes in java exception
Exception Handling notes in java exception
Ratnakar Mikkili
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
thanhdowork
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Christina Lin
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
camseq
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
gestioneergodomus
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
ClaraZara1
 
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
zwunae
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
Madan Karki
 
Low power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniquesLow power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniques
nooriasukmaningtyas
 
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTSHeap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Soumen Santra
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
This is my Environmental physics presentation
This is my Environmental physics presentationThis is my Environmental physics presentation
This is my Environmental physics presentation
ZainabHashmi17
 
Swimming pool mechanical components design.pptx
Swimming pool  mechanical components design.pptxSwimming pool  mechanical components design.pptx
Swimming pool mechanical components design.pptx
yokeleetan1
 

Recently uploaded (20)

ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
 
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
 
digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
 
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
 
Exception Handling notes in java exception
Exception Handling notes in java exceptionException Handling notes in java exception
Exception Handling notes in java exception
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
 
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单专业办理
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
 
Low power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniquesLow power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniques
 
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTSHeap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
This is my Environmental physics presentation
This is my Environmental physics presentationThis is my Environmental physics presentation
This is my Environmental physics presentation
 
Swimming pool mechanical components design.pptx
Swimming pool  mechanical components design.pptxSwimming pool  mechanical components design.pptx
Swimming pool mechanical components design.pptx
 

PE1 Module 3.ppt

  • 1. PE1 Module 3 Sequence Data Types and Control Structures in Python
  • 2. 2 Sequence Data Types  Sequence data types allow you to store multiple items/values in an organized and efficient fashion.  The items are stored in sequence one after another  Basic Sequence types: list tuple
  • 3. 3 Python Lists  Lists are the most versatile of Python’s sequence data types.  A list is mutable: the items in the sequence can be changed  A list contains items separated by commas and enclosed within square brackets [ ].  The values stored in a list can be accessed using [ ] or [ : ] ) with indexes starting at 0 in the beginning of the list and working their way to end-1.  The plus + sign is the list concatenation operator, and the asterisk * is the repetition operator.
  • 4. 4 Python Lists  The type() function in Python returns the data type of the object passed to it as an argument.
  • 6. 6 Python Lists Boeing 737 is no longer available and replaced by Boeing 737 Original
  • 7. 7 List Slicing  Slice: a span of items that are taken from a sequence List slicing format: list[start : end] Span is a list containing copies of elements from start up to, but not including, end If start not specified, 0 is used for start index If end not specified, len(list) is used for end index
  • 8. 8 List Methods and Useful Built-in Functions  Len(): returns the length of a list  sorted(): used to sort the elements of the list.
  • 9. 9 List Methods and Useful Built-in Functions  append(item): used to add items to a list – item is appended to the end of the existing list.
  • 10. 10 List Methods and Useful Built-in Functions  insert(index, item): used to insert item at position index in the list.
  • 11. 11 List Methods and Useful Built-in Functions  index(item): used to determine where an item is located in a list Returns the index of the first element in the list containing item Raises ValueError exception if item not in the list
  • 12. 12 List Methods and Useful Built-in Functions (cont’d.)  remove(item): removes the first occurrence of item in the list
  • 13. 13 List Methods and Useful Built-in Functions (cont’d.)  reverse(): reverses the order of the elements in the list  Activity: What will be the output of fighter_jets.reverse()  clear(): The clear() method removes all the elements from a list.
  • 14. 14 List Methods and Useful Built-in Functions (cont’d.)  copy(): The Python copy() method creates a copy of an existing list.
  • 15. 15 List Methods and Useful Built-in Functions (cont’d.)  del: removes an element from a specific index in a list or name of the list from memory.  print(boeing_planes)
  • 16. 16 List Methods and Useful Built-in Functions (cont’d.)  print(boeing_planes_copy)  copy(): deep copy, the copy remains even the original source is removed .
  • 17. 17 Shallow Copy  Assignment operator(=) to copy a list: The assignment operator ( = ) only creates a reference to an object, and will create a new variable referencing the same memory address.
  • 18. 18 List Methods and Useful Built-in Functions (cont’d.)  min and max functions: built-in functions that returns the item that has the lowest or highest value in a sequence The sequence is passed as an argument Count(): method counts how many times an element has.  What will be the output of print( fighter_jets.count(" Tiger Moth"))
  • 19. 19 Tuples  Tuple: an immutable sequence  Very similar to a list  Once it is created it cannot be changed  A tuple contains items separated by commas and enclosed within square brackets ().  Tuples support operations as lists Subscript indexing for retrieving elements Methods such as index Built in functions such as len, min, max, count, index Slicing expressions
  • 20. 20 Tuples  Tuples do not support the methods: append remove insert reverse sorted
  • 21. 21 Control Structures  Control flow is the order that instructions are executed in a program.  A control statement is a statement that determines the control flow of a set of instructions.  A control structure is a set of instructions and the control statements controlling their execution.  The fundamental forms of controls in programming are: 1. Sequential statements , 2. Selection/ Conditional statements , 3. Iterative/loop statements . 4. Jump statements  A program consisting of only sequential control is referred to as a “straight- line program.”  Selection control is provided by a control statement that selectively executes instructions.  Iterative control is provided by an iterative control statement that repeatedly executes instructions.  Jump statements are statements through which we can transfer control anywhere in the program.
  • 22. 22 Sequential statements  Sequential control is the default control structure; instructions are executed one after another. Statement 1 Statement 2 Statement 3 …….. …….. ……..
  • 24. 24 Selection Statements  The selection control statements are also known as Decision control statements or conditional branching statements.  A conditional statement will select the block of statements that will execute based on the given condition.  A selection statement causes the program control to be transferred to a specific flow based upon whether a certain condition is true or not.  The statements used to perform conditional branching : if if-else if- elif-else
  • 25. 25 if Statement  if statements are control flow statements that help us to run a particular code, but only when a certain condition is met or satisfied.
  • 26. 26 if Statement Discus the output of the following codes:
  • 27. 27 if-else Statements  The if-else statement evaluates the condition and will execute the body of if, if the test condition is True, but if the condition is False, then the body of else is executed.
  • 29. 29 if-else Statements Discus the output of the following codes:
  • 30. 30 if-else Statements Discus the output of the following codes:
  • 31. 31 if- elif-else Statement  if-elif-else: The if-elif-else statement is used to conditionally execute a statement or a block of statements.
  • 33. 33 if- elif-else Statement Discus the output of the following codes:
  • 34. 34 Iterative/Loop/Repetition statements  A repetition statement is used to repeat a group(block) of programming instructions.  In Python, we generally have two loops/repetitive statements: for loop while loop
  • 35. 35 for Loop  A for loop is used to iterate over a sequence.
  • 36. 36 for Loop friends = ['Jonathan', 'Kedija', 'Eba'] for friend in friends : print('Happy New Year:', friend) print('Done!') Happy New Year: Jonathan Happy New Year: Kedija Happy New Year: Eba Done!
  • 38. 38 The range() function  To achieve the functionality of conventional for-loop in Python, the range() function is used. It returns a list of integers.
  • 39. 39 The range() function  r= range(10) is equivalent to r=range(0,10): the range function starts at 0 and goes up to but does not include 10 for sequences.
  • 40. 40 range() function in for Loop  when the range() receives 3 arguments, the sequence starts at the first value, ends before the second argument and increments or decrements by the third value.
  • 41. 41 while loop  A while loop consists of a condition and until that condition is true, a set of statements is executed repeatedly.
  • 42. 42 while Loop  Example : Program displays 1 – 5, after loop terminates, num will be 6
  • 43. 43 Jump Statements  Jump statements in python are used to alter the flow of a loop like you want to skip a part of a loop or terminate a loop.  Types of jump statements in python: continue break pass
  • 44. 44 continue Statement  When the program encounters the continue statement, it will skip all the statements present after the continue statement inside the loop, and proceed with the next iterations.  When continue executed in a while loop  Current iteration of the loop terminates  Execution returns to the loop’s header
  • 45. 45 break Statement  A break statement in Python exits out of a loop.  It terminates the execution of the loop.
  • 46. 46 pass Statement  A pass statement is an empty/null statement that is considered as a placeholder for future code.  Empty code shouldn’t be included in loops, function definitions, class definitions, or if statements because there is a possibility that it will cause an error. To avoid errors, the user can simply apply a pass statement.