Python Sequence Data types in Brief

jyostnabodapati 1,297 views 20 slides Nov 27, 2020
Slide 1
Slide 1 of 20
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20

About This Presentation

Introduces Various Python Sequence Data types like strings, Lists and Tuples


Slide Content

Sequence Data Types
by
JyostnaDevi Bodapati

Python Programming Specialization
Python Programming –Data Structures
Python Data Types
Data Types
Scalar Data
int
float
complex
boolean
Sequence Data
List
Tuple
String
Mapping Type
Dictionary
Set Type
Set
Frozen Set

Python Programming Specialization
Python Programming –Data Structures
Sequence Types

Python Programming Specialization
Python Programming –Data Structures
Sequence Data Types
Sequence is the ordered collection of elements
Allows to store multiple values in an organized and efficient manner
Sequence
String List Tuple

Python Programming Specialization
Python Programming –Data Structures
Sequence Data Type: str

Python Programming Specialization
Python Programming –Data Structures
Sequence Types: str
•A string is a collection of one or more characters
•Python strings can be enclosed either in single, double or triple quotes
•Python Strings belongs to strclass

Python Programming Specialization
Python Programming –Data Structures
Creation of Strings
>>>S1 = ‘Python’
>>>S2 = “Python”
>>>S3 = ‘’’Python’’’
>>>S4 = ‘’’Python
Programming
Specialization’’’

Python Programming Specialization
Python Programming –Data Structures
Accessing String Elements
•Let S1 = “HELLO WORLD”
•How do we access the contents of the string?
•String elements can be accessed by passing an index with the name of the
string
•String name [ index ]

Python Programming Specialization
Python Programming –Data Structures
String Indexing
•Indexing must be an integer
•Both negative and positive indexing are valid
•Ex: S1 = “HELLO WORLD”

Python Programming Specialization
Python Programming –Data Structures
String Indexing
•Integer indexing can be used to access string elements
•Both negative and positive indexing are valid
•Ex: S1 = “HELLO WORLD”

Python Programming Specialization
Python Programming –Data Structures
String Indexing
•Integer indexing can be used to access string elements
•Both negative and positive indexing are valid
•Ex: S1 = “HELLO WORLD”

Python Programming Specialization
Python Programming –Data Structures
Accessing String Elements
•Ex: S1 = “HELLO WORLD”
>>> S1 [ 0 ]
>>> S1 [ 4 ]
>>> S1 [ -2 ]
>>> S1 [ 2: 7 ]

Python Programming Specialization
Python Programming –Data Structures
Accessing String Elements
•Ex: S1 = “HELLO WORLD”
>>> S1 [ 0 ]
>>> S1 [ 4 ]
>>> S1 [ -2 ]
>>> S1 [ 2 : 7 ]
>>> S1 [ 2 : 10 : 2 ]
#returns H
#returns O
#returns L
#returns LLO W
#returns LOWR

Python Programming Specialization
Python Programming –Data Structures
Sequence Data Type: list

Python Programming Specialization
Python Programming –Data Structures
Sequence Types: list
•Orderedcollections of objects​ of same or different types
•ListsareMutable​
•Examples:
•>>>L3 = [10, 20, 30, 40]
•>>> L4= [‘Ram', 786 , 2.23, ‘Raj', 70.2]

Python Programming Specialization
Python Programming –Data Structures
Sequence Types: list
•L1 = [10, 20, 30, 40, 50, 60, 70]
•Access theentire list→useis its name.​
•>>> Print ( L1 )​
•Access asingle item→use index operator [ ] ​
•>>> L1 [ 0 ] ​
•Accesspart of a list→use slicing operator [ : : ]​
•>>> L1 [ 4 : 8 : 2 ]

Python Programming Specialization
Python Programming –Data Structures
Sequence Data Type: tuple

Python Programming Specialization
Python Programming –Data Structures
Sequence Types: tuple
•Orderedcollections of objects​ of same or different types
•TuplesareImmutable
•Examples:
•>>> T1 = ( 9, 2, 13, 24 )
•>>> T2 = ( ‘Ram', 786 , 2.23, ‘Raj', 70.2 )

Python Programming Specialization
Python Programming –Data Structures
Access tuple Elements
•T1 = ( 10, 20, 30, 40, 50, 60, 70 )
•Access theentire tuple→useis its name.​
•>>> Print ( T1 )​
•Access asingle item→use index operator [ ] ​
•>>> T1 [ 0 ] ​
•Accesspart of a tuple→use slicing operator [ : : ]​
•>>> T1 [ 2 : 6 : 2 ]