Module 2 Summary: Python
Data Structures
Congratulations! You have completed this module. At this point, you know that:
In Python, we often use tuples to group related data [Link] refer to ordered
and immutable collections of elements.
Tuples are usually written as comma-separated elements in parentheses “()".
You can include strings, integers, and floats in tuples and access them using both
positive and negative indices.
You can perform operations such as combining, concatenating, and slicing on tuples.
Tuples are immutable, so you need to create a new tuple to manipulate it.
Tuples, termed nesting, can include other tuples of complex data types.
You can access elements in a nested tuple through indexing.
Lists in Python contain ordered collections of items that can hold elements of different
types and are mutable, allowing for versatile data storage and manipulation.
A list is an ordered sequence, represented with square brackets "[]".
Lists possess mutability, rendering them akin to tuples.
A list can contain strings, integers, and floats; you can nest lists within it.
You can access each element in a list using both positive and negative indexing.
Concatenating or appending a list will result in the modification of the same list.
You can perform operations such as adding, deleting, splitting, and so forth on a list.
You can separate elements in a list using delimiters.
Aliasing occurs when multiple names refer to the same object.
You can also clone a list to create another list.
Dictionaries in Python are key-value pairs that provide a flexible way to store and
retrieve data based on unique keys.
Dictionaries consist of keys and values, both composed of string elements.
You denote dictionaries using curly brackets.
The keys necessitate immutability and uniqueness.
The values may be either immutable or mutable, and they allow duplicates.
You separate each key-value pair with a comma, and you can use color highlighting to
make the key more visible.
You can assign dictionaries to a variable.
You use the key as an argument to retrieve the corresponding value.
You can make additions and deletions to dictionaries.
You can perform an operation on a dictionary to check the key, which results in a true or
false output.
You can apply methods to obtain a list of keys and values in a dictionary.
Sets in Python are collections of unique elements, useful for tasks such as removing
duplicates and performing set operations like union and intersection. Sets lack order.
Curly brackets "{}" are helpful for defining elements of a set.
Sets do not contain duplicate items.
A list passed through the set function generates a set containing unique elements.
You use “Set Operations” to perform actions such as adding, removing, and verifying
elements in a set.
You can combine sets using the ampersand "&" operator to obtain the common
elements from both sets.
You can use the Union function to combine two sets, including both the common and
unique elements from both sets.
The sub-set method is used to determine if two or more sets are subsets.
)الصفوف( Tuplesالـ ⃣️1
(Immutable).التعريف :مجموعة مرتبة وغير قابلة للتغيير
( ).التمثيل :عناصر مفصولة بفواصل داخل أقواس
:مثال
)my_tuple = (10, 20, "Python", 3.5
)]print(my_tuple[0 يطبع # 10
يطبع print(my_tuple[-1]) # 3.5
:العمليات
)tuple1 = (1, 2
)tuple2 = (3, 4
combined = tuple1 + tuple2
)print(combined) # (1, 2, 3, 4
.مالحظة :لتعديل الصفوف يجب إنشاء صف جديد
)القوائم( Listsالـ ⃣️2
(Mutable).التعريف :مجموعة مرتبة وقابلة للتغيير
[ ].التمثيل :بين أقواس مربعة
:مثال
]"my_list = [1, 2, 3, "Data
)my_list.append(4
]print(my_list) # [1, 2, 3, "Data", 4
my_list[0] = 10
]print(my_list) # [10, 2, 3, "Data", 4
Cloning ()نسخ قائمة:
list_copy = my_list.copy()
Aliasing:
alias = my_list
alias[1] = 20
print(my_list) # التغيير يظهر في القائمة األصلية أيًضا
3️⃣ الـDictionaries ()القواميس
قيمة- زوج مفتاح:( التعريفKey-Value) لتخزين البيانات.
بين أقواس:} { التمثيل.
مثال:
my_dict = {"name": "Ali", "age": 25}
print(my_dict["name"]) # Ali
my_dict["age"] = 26
my_dict["city"] = "Rabat"
print(my_dict) # {'name': 'Ali', 'age': 26, 'city': 'Rabat'}
العمليات:
print("age" in my_dict) # True
print(my_dict.keys()) # ['name', 'age', 'city']
print(my_dict.values()) # ['Ali', 26, 'Rabat']
4️⃣ الـSets ()المجموعات
مجموعة غير مرتبة من العناصر الفريدة:( التعريفUnique).
مثال:
my_set = {1, 2, 3, 3}
print(my_set) # {1, 2, 3} # محذوف3 تكرار الرقم
Set Operations:
set1 = {1, 2, 3}
set2 = {3, 4, 5}
print(set1 & set2) # {3} # العناصر المشتركة
print([Link](set2)) # {1, 2, 3, 4, 5} # الدمج
print([Link](set1)) # False
✅ الخالصة مع األمثلة
الهيك
Ordered Mutable Syntax أمثلة للعمليات
ل
Tuple نعم ال ( ) indexing, slicing, concatenation
List نعم نعم [ ] append, insert, delete, slicing
Dict ال نعم { } key-value access, add, delete
Set ال نعم { } union, intersection, add, remove
Glossary: Python Data Structures
Welcome! This alphabetized glossary contains many of the terms in this course. This comprehensive
glossary also includes additional industry-recognized terms not used in course videos. These terms
are important for you to recognize when working in the industry, participating in user groups, and
participating in other certificate programs.
Term Definition
Aliasing Aliasing refers to giving another name to a function or a variable.
Ampersan
A character typically "&" standing for the word "and."
d
Compound Compound statements contain (groups of) other statements; they affect or control the
elements execution of those other statements in some way.
A delimiter in Python is a character or sequence of characters used to separate or
Delimiter mark the boundaries between elements or fields within a larger data structure, such as a
string or a file.
Term Definition
Dictionarie A dictionary in Python is a data structure that stores a collection of key-value pairs,
s where each key is unique and associated with a specific value.
A function is a block of code, defining a set procedure, which is executed only when it
Function
is called.
Immutable Objects are of in-built datatypes like int, float, bool, string, Unicode, and
Immutable
tuple. In simple words, an immutable object can't be changed after it is created.
Intersectio The intersection of two sets is a new set containing only the elements that are present
n in both sets.
The keys () method in Python Dictionary, returns a view object that displays a list of all
Keys
the keys in the dictionary in order of insertion using Python.
Lists A list is any list of data items, separated by commas, inside square brackets.
Logic In Python, logic operations refer to the use of logical operators such as "and," "or," and
operations "not" to perform logical operations on Boolean values (True or False).
Mutable objects in Python are objects whose values can be changed after they are
Mutable created. These objects allow modifications such as adding, removing, or altering elements
without creating a new object.
A nested function is simply a function within another function and is sometimes called
Nesting
an "inner function".
Ratings in Ratings in Python typically refer to a numerical or qualitative measure assigned to
python something to indicate its quality, performance, or value.
Set Set operations in Python refer to mathematical operations performed on sets, which
operations are unordered collections of unique elements.
Sets in
A set is an unordered collection of unique elements.
python
Syntax The rules that define the structure of the language for python is called its syntax.
Term Definition
Tuples These are used store multiple items in a single variable.
Type
In python, this is converting one data type to another.
casting
In python, a variable is a symbolic name or identifier used to store and manipulate
Variables data. Variables serve as containers for values, and these values can be of various data
types, including numbers, strings, lists, and more.
Venn A Venn diagram is a graphical representation that uses overlapping circles to illustrate
diagram the relationships and commonalities between sets or groups of items.
Versatile Versatile data, in a general context, refers to data that can be used in multiple ways, is
data adaptable to different applications or purposes, and is not restricted to a specific use case.