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

set in python

In this video you will learn about sets in python.
A set is also a primitive data structure which allows us to store the values. The set is also a part of python core collection. A set does not stores the elements in any specific order, so a set is unordered and unindexed. A set can-not store duplicate data. A set is mutable, it means we can add or remove elements from a set. A set internally uses a hash table. To create a set we can use following :
• Creating set using curly brackets: We can create a set using the curly brackets.
Example:
fruits={"apple","banana","grapes","strawberry","blueberry","mango"}
print(fruits #Sets are unordered so we cannot be sure in which order elements will be printed.

ages={34,56,67,89}
print(ages)
• Creating set using set() constructor: We can also create a set using set() constructor.
Example:
fruits=set(("apple","banan","grapes","strawberry","blueberry","mango"))
print(fruits)
Note: We have to use double (()) while creating set using the set() constructor.

Access the set elements
As we know that sets does not have any index or key, so we can only use a set using the for loop only.
Example:
fruits=set(("apple","banan","grapes","strawberry","blueberry","mango"))
print(fruits)
for fruit in fruits:
print(fruit)
Adding elements to set
• add() : The add function takes an argument and add it to the set.
Example:
numbers={10,20}
print(numbers)
numbers.add(30)
print(numbers)
• update() : The update function can take a list of arguments and add all the elements of list to the set.
numbers={10,20}
print(numbers)
numbers.update ([30,40,50])
print(numbers)

Deleting element from the set
• remove(): The remove() method takes an element as argument and remove it from set if it is in the set. If the element is not in the set then remove generates key error.
Example
numbers={10,20}
print(numbers)
numbers.remove(10)
print(numbers)

• discard() : The discard() method removes the element from the set. It does not generates error if the element is not in the set.
Example
numbers={10,20}
print(numbers)
numbers.discard (10)
print(numbers)

• pop() : The pop() method deletes the last element from the set. As the order is not defined in the set, so we can not predict which item will be popped.
Example
numbers={10,20}
print(numbers)
numbers.pop()
print(numbers)

• clear() : The clear method deleted all the elements of the set.
Example
numbers={10,20}
print(numbers)
numbers.clear()
print(numbers)

• del : We can delete the complete set using del keyword.
Example
numbers={10,20}
print(numbers)
del numbers
print(numbers)#Error, numbers does not exist

Searching a value in set
We can search value in set() with the help of in operator.
Example
numbers={10,20}
print(numbers)
if 10 in numbers:
print(“The value is found in the set”)

#python_by_tarun_sir #tarun_sir #python #tarun_sir_python #python_video #set_in_python #find_sum #python_tutorial

Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «set in python», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.

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

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

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