Загрузка...

19- What is tuple and set in python?

In Python, tuples and sets are both built-in collection data types, but they differ significantly in their characteristics and use cases.
Tuples:
Ordered and Immutable: Tuples are ordered sequences of elements, meaning the order in which elements are added is preserved. Once a tuple is created, its elements cannot be changed, added, or removed. This immutability makes them suitable for data that should not be modified, such as fixed configurations or records.
Allow Duplicates: Tuples can contain duplicate elements.
Indexed: Elements in a tuple can be accessed using an index, similar to lists, starting from 0.
Syntax: Tuples are defined using parentheses ().

Sets:
Unordered and Mutable (but elements are immutable): Sets are unordered collections of unique elements. While you can add or remove elements from a set, the individual elements themselves must be immutable (hashable).
No Duplicates: Sets automatically handle duplicate elements, ensuring that each element in a set is unique. If you try to add a duplicate, it will be ignored.
Unindexed: Elements in a set cannot be accessed by an index because sets are unordered.
Syntax: Sets are defined using curly braces {}.

Видео 19- What is tuple and set in python? канала TechLearn(تک لرن)
Яндекс.Метрика
Все заметки Новая заметка Страницу в заметки
Страницу в закладки Мои закладки
На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.
О CookiesНапомнить позжеПринять