Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
17 views

Python Lecture 2 Data Structures in Python

This lecture introduces some of the main data structures in Python - lists, tuples, sets, and dictionaries. Lists are ordered and changeable collections that use square brackets. Tuples are similar to lists but are immutable and use parentheses. Sets are unordered collections of unique elements defined using curly braces. Dictionaries are unordered collections of key-value pairs defined using curly braces. Each data structure has different characteristics that make it suitable for different use cases.

Uploaded by

Ayman Younis
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Python Lecture 2 Data Structures in Python

This lecture introduces some of the main data structures in Python - lists, tuples, sets, and dictionaries. Lists are ordered and changeable collections that use square brackets. Tuples are similar to lists but are immutable and use parentheses. Sets are unordered collections of unique elements defined using curly braces. Dictionaries are unordered collections of key-value pairs defined using curly braces. Each data structure has different characteristics that make it suitable for different use cases.

Uploaded by

Ayman Younis
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Introduction to Python Programming

Lecture 2: Data Structures in Python

Introduction to Data Structures

Understanding data structures is fundamental in programming. Data structures are ways of

organizing and storing data so that they can be accessed and worked with efficiently. Python

provides a variety of built-in data structures, such as lists, tuples, sets, and dictionaries, each with its

unique characteristics and use cases.

Lists

Lists in Python are ordered collections that are changeable and allow duplicate members. They are

created by placing all the items (elements) inside square brackets [ ], separated by commas. Lists

support various methods such as append(), remove(), and sort() that help in manipulating the data.

Tuples

Tuples are similar to lists but are immutable, meaning they cannot be changed after creation. They

are written with round brackets ( ). Tuples are faster than lists and are used to protect the data from

being changed.

Sets

Sets are unordered collections of unique elements. They are defined by values separated by

commas inside curly braces { }. Sets are useful for removing duplicate values from a list or tuple and
Introduction to Python Programming

for performing common math operations like unions and intersections.

Dictionaries

Dictionaries in Python are unordered collections of data in a key:value pair form. They are written

with curly brackets, and they have keys and values. Dictionaries are optimized to retrieve values

when the key is known.

You might also like