Join the conversation
TypeError: 'tuple' object does not support item assignment sir i find this eror what can i do
Reply
![](https://codanics.com/wp-content/uploads/2024/07/ikh-removebg-preview-1.jpg)
sir why did the tuple value not change?
Reply
bcz tuple mostly ap waha use karty hu jaha koi apki chezy change karsaky some kind of sceruity hope i clear your concept
car={"brand":"ford","model":"mustang","year":1995}
print(car)
print(car["brand"])
print('brand: {}'.format(car["brand"]))#Using the format() Method:
print('Brand: ' + car["brand"])#Using String Concatenation:
print(f'Brand: {car["brand"]}')#Using f-Strings (Python 3.6+):
print(car.keys())
print(car.values())
Reply
Data structure Order mutability duplicate items access
list yess yess yess index
tuple yess no yess index
set no yess no no
dictonaries yess yess values can be duplicate but keys must be unique key
Reply
Sir, I would like to thank you, and appreciate your efforts in explaining concepts and teaching us python, Machine Learning, Data Science and many more other topics in a comprehensive manner like HALWA.
Reply
In Python, data structures are used to organize and store data efficiently. The primary data structures include lists, tuples, sets, and dictionaries. Here’s a brief comparison highlighting their similarities and differences:
1. Lists:
• Ordered: Elements have a defined order.
• Mutable: Elements can be changed.
• Indexable: Access elements using an index.
• Duplicates: Allows duplicate elements.
• Example: [1, 2, 3, 2]
2. Tuples:
• Ordered: Elements have a defined order.
• Immutable: Once created, elements cannot be changed.
• Indexable: Access elements using an index.
• Duplicates: Allows duplicate elements.
• Example: (1, 2, 3, 2)
3. Sets:
• Unordered: No defined order for elements.
• Mutable: Elements can be added or removed.
• Non-indexable: Cannot access elements using an index.
• Unique: Does not allow duplicate elements.
• Example: {1, 2, 3}
4. Dictionaries:
• Unordered: Insertion order is preserved in Python 3.7+.
• Mutable: Keys and values can be changed.
• Key-Value Pairs: Access elements using keys.
• Unique Keys: Keys must be unique; values can be duplicated.
• Example: {'a': 1, 'b': 2}
Similarities:
• Lists and Tuples: Both are ordered and can contain duplicates.
• Sets and Dictionaries: Both use hash tables for fast lookups.
• Mutability: Lists, sets, and dictionaries are mutable, allowing for dynamic changes.
Differences:
• Order: Lists and tuples are ordered, while sets and dictionaries are unordered (with dictionaries preserving insertion order from Python 3.7+).
• Mutability: Lists and dictionaries are mutable, tuples are immutable, and sets are mutable but do not allow duplicates.
• Access: Lists and tuples are accessed by index, sets by membership testing, and dictionaries by keys.
Reply
(1)List: "data structure that stores the elements in columns of a single row or multiple rows."Symbol = [], Mutable(entries can be change/duplicate), created by "list()" function, Access by Index, ordered, Example = [1,2,3](2) Set: "data structure which stores the elements in a single row."
Symbol = {}, Mutable(entries can be change),duplication not possible, created by "set()" function, Access by Index, ordered , Example = {1,2,3}(3) Tuple: "data structure that stores elements in columns of a single row or multiple rows."
Symbol = (), immutable(entries can't be change/duplicate), created by "set()" function, Access by Index, not ordered, Example = (1,2,3)(4) Dictionary: "Data structure that stores key-value pairs."
Symbol = {}, Mutable(entries can be change/update) but duplicate keys not allowed, duplicate values are possible, created by "dict()" function, Access by Keys, ordered(python version >3.7) , Example = {a : 1,b :2, c:3}
Reply
![](https://codanics.com/wp-content/uploads/2023/09/LIAQAT-PHOTO.jpeg)
List of string
Reply
![](https://codanics.com/wp-content/uploads/2023/09/LIAQAT-PHOTO.jpeg)
List
Reply
![](https://codanics.com/wp-content/uploads/2023/12/shariq.jpg)
List is an ordered collection of items and mutable, enclosed in square brackets and each individual item can be accessed by its index.Tuple is an ordered collection of items and immutable, enclosed in parenthesis and each individual item can be accessed by its index.Set is an unordered collection of items and mutable, enclosed in curly-brackets and each individual item cannot be accessed.Dictionary is an ordered collection of items and mutable, enclosed in curly-brackets and each individual item can be accessed by its key.
Reply