Загрузка...

Collection in python set,list,tuple, dict

*Python Collection Data Types: Set, List, Tuple, Dictionary*

Hey everyone! 🚀 In this video, we'll cover Python's four main collection data types: List, Tuple, Set, and Dictionary. These data structures make your coding easier and more efficient!

1. List 📝
- *What is it?* An ordered, mutable (changeable) collection of elements.
- *Syntax:* `my_list = [1, 2, 3]`
- *Features:* Indexing, slicing, allows duplicates.
- *Use Case:* When you need ordered data and want to make changes.

2. Tuple 📦
- *What is it?* An ordered, immutable (unchangeable) collection of elements.
- *Syntax:* `my_tuple = (1, 2, 3)`
- *Features:* Faster than lists, use for fixed data.
- *Use Case:* When data shouldn't change (constants).

3. Set 🔗
- *What is it?* An unordered collection of unique elements.
- *Syntax:* `my_set = {1, 2, 3}`
- *Features:* No duplicates, fast lookup.
- *Use Case:* To store unique items.

4. Dictionary 📚
- *What is it?* An unordered collection of key-value pairs.
- *Syntax:* `my_dict = {'name': 'John', 'age': 25}`
- *Features:* Fast lookup by key, mutable.
- *Use Case:* When you need to access data via keys.

*Example Code:*
List
fruits = ['apple', 'banana', 'orange']
fruits.append('grapes')
print(fruits) # Output: ['apple', 'banana', 'orange', 'grapes']

Tuple
days = ('Mon', 'Tue', 'Wed')
print(days[0]) # Output: Mon

Set
numbers = {1, 2, 3, 3}
print(numbers) # Output: {1, 2, 3}

Dictionary
person = {'name': 'Alice', 'age': 30}
print(person['name']) # Output: Alice
*Summary:*
- *List:* Ordered, mutable.
- *Tuple:* Ordered, immutable.
- *Set:* Unordered, unique.
- *Dictionary:* Key-value pairs.

👉 *Practice Tip:* Understand each use case and practice! 🚀

#Python #DataStructures #Coding #Programming #Collections #python #coding #programming #operators #controlstatements #learnpython #pythonloops #controlstatement

Видео Collection in python set,list,tuple, dict канала Tech Pandit
Яндекс.Метрика
Все заметки Новая заметка Страницу в заметки
Страницу в закладки Мои закладки
На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.
О CookiesНапомнить позжеПринять