RUVIDEO
Поделитесь видео 🙏

Set Data Type and Methods in Python || Lesson 25 || Python || Learning Monkey || смотреть онлайн

#pytho #learningmonke #pythoncodin #placement #pythontutorial #pythoncours #pythonforbeginner #pythonfordatascienc #pythonfullcours #pythonprogrammin #pythonfreecourse
Set Data Type and Methods in python
In this class, we discuss set data type and methods in python.
Set Data Type
Before going to understand set data type, the reader should have an idea of tuple data type. Click here.
First, we will refresh the concepts of set operations.
For complete basics on sets. Please check our discrete mathematics course.
Set is a group of distinct elements. I.e. duplicates are not allowed in the set.
Example:
A={1,2,5,6,7,8} is a set of elements.
B= {5,6,9,10,11} is a set of elements.
Set Union
Union operation is given a symbol U.
AUB means the union of all the elements in set A and set B. Duplicates are not taken
AUB set contains elements {1,2,5,6,7,8,9,10,11}
Set Intersection
The intersection operation is given a symbol ∩.
Intersection operation considers the common elements.
A ∩ B will result {5,6}
Set Difference
set difference operation is given symbol -.
The difference operation result elements are in A and not in B.
A-B will result {1,2,7,8}. 5,6 elements present in set B. so remove those elements from set A.
Set data type in python is defined to do these set operations.
Set is a collection that is unordered, not indexed, and no duplicates.
Unordered means how elements are defined are not displayed in the same order.
The data types we discussed previously are list and tuple. They are ordered.
How are the set elements saved in the memory?
Python uses a hash table to save the elements in the set.
Please watch our data structures course for a detailed explanation of hash tables.
Define and Access Set
Set is defined using {}.
a={1,2,3,4}
print(a)
The set is unordered.
Example:
a={“hello”,”this”,”is”,”python”,”program”}
print(a) will display {“is”,”hello”,”this”,”python”,”program”}
set within set and list within the set are not allowed.
Accessing elements in a set.
We do not have an index to access. We use a loop to iterate on elements.
The program is shown below.
Membership operator on set
a={“hello”,”this”,”is”,”python”,”program”}
print(“hello” in a) will display True.
Methods in Set
add method
The add method is used to add elements to the set.
We can not change the elements in a set. but we can add elements in a set.
a={“hello”,”this”,”is”,”python”,”program”}
a.add(“java”)
print(a) will display {“is”,”hello”,”this”,”java”,”python”,”program”}
update method
The update method is used to add multiple elements to a set.
a={“hello”,”this”,”is”,”python”,”program”}
a.update([“java”,”pascal”])
remove method
The remove method is used to remove an element in the set.
Example:
a={“hello”,”this”,”is”,”python”,”program”}
a.remove(“python”)
print(a) will display {“is”,”hello”,”this”,”program”}
If the element is not found in the set, the remove method will give an error.
Example
a.remove(“p”)
print(a) will give a key error.
discard method
The discard method will delete the element from the set and do not give an error if the element not found.
Example:
a={“hello”,”this”,”is”,”python”,”program”}
a.discard(“pascal”)
print(a) will display {“is”,”hello”,”this”,”python”,”program”}.
clear method
the clear method is used to remove all the elements in a set.
Example:
a={“hello”,”this”,”is”,”python”,”program”}
a.clear()
print(a) will display set(). i.e. empty set.
Set Operations
There are many set operations we discuss only few in this class.
Union operation
Example:
a = {1, 2, 3, 4, 5}
b = {4, 5, 6, 7, 8}
print(a|b) will display {1, 2, 3, 4, 5,6,7,8}
print(a.union(b)) will display {1, 2, 3, 4, 5,6,7,8}
We can do union operation using pipe symbol. or we can use union method.
Both are shown in above example.
Intersection Operation
Example:
a = {1, 2, 3, 4, 5}
b = {4, 5, 6, 7, 8}
print(a&b) will display (4,5}
print(a.intersection(b) will display (4,5}
Intersection operation can be done using symbol & and intersection Method.
Both are shown in the example.
Set Difference Operation
Example:
a = {1, 2, 3, 4, 5}
b = {4, 5, 6, 7, 8}
print(a-b) will display {1,2,3}
print(a.difference(b)) will display {1,2,3}
Set difference operation can be done using symbol – and using difference method.
Both are shown in the example.


Link for playlists:
https://www.youtube.com/channel/UCl8x4Pn9Mnh_C1fue-Yndig/playlists


Link for our website: https://learningmonkey.in

Follow us on Facebook @ https://www.facebook.com/learningmonkey

Follow us on Instagram @ https://www.instagram.com/learningmonkey1/

Follow us on Twitter @ https://twitter.com/_learningmonkey

Mail us @ [email protected]

Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Set Data Type and Methods in Python || Lesson 25 || Python || Learning Monkey ||» бесплатно и без регистрации, вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.

Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.

Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!

Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.