The document discusses different sequence data types in Python including strings, lists, and tuples. It provides information on how each type is defined and created, how elements within each type can be accessed using indexes and slicing, and notes that lists are mutable while tuples are immutable. Key differences between each type such as enclosure for strings and allowed element types for lists and tuples are also outlined.
2. Python Programming Specialization
Python Programming ¨C 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
4. Python Programming Specialization
Python Programming ¨C 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
6. Python Programming Specialization
Python Programming ¨C 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 str class
8. Python Programming Specialization
Python Programming ¨C 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 ]
9. Python Programming Specialization
Python Programming ¨C Data Structures
String Indexing
? Indexing must be an integer
? Both negative and positive indexing are valid
? Ex: S1 = ¡°HELLO WORLD¡±
10. Python Programming Specialization
Python Programming ¨C Data Structures
String Indexing
? Integer indexing can be used to access string elements
? Both negative and positive indexing are valid
? Ex: S1 = ¡°HELLO WORLD¡±
11. Python Programming Specialization
Python Programming ¨C Data Structures
String Indexing
? Integer indexing can be used to access string elements
? Both negative and positive indexing are valid
? Ex: S1 = ¡°HELLO WORLD¡±