GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||
GeezerVison is showing codescracker.com — Difference between list, tuple, set, and dictionary in Python
Difference between list, tuple, set, and dictionary in PythonThis article is created to differentiate the four built-in data structures in Python that are used to store collections of data. The four built-in data structures that are differentiated here are: The table below distinguishes between the four built-in data structures in Python.
Lists are ordered sequences of elements that can be changed. This means that you can change, add, or remove items from a list after it has been made. Lists are made by putting a series of values separated by commas inside square brackets []. For instance: my_list = [10, 20, "codes", "cracker"] Tuples are like lists, but their values can't be changed once they're made. Tuples are made by putting a list of values separated by commas between parentheses (). For instance: my_tuple = (10, 20, "codes", "cracker") Unordered collections of distinct elements make up sets. This implies that every component of a set must be distinct. A comma-separated list of values is enclosed in curly braces to form sets. For instance: my_set = {10, 20, "codes", "cracker"}
Dictionaries are collections of key-value pairs that are not ordered. A dictionary's keys must each uniquely correspond to a value. Curly braces are used to enclose key-value pairs in dictionaries, which are key-value pairs separated by commas. For instance: my_dict = {"key1": "value1", "key2": "value2", "key3": "value3", "key4": "value4"}
Tuples and lists are both ordered sequences of elements, but tuples are immutable and lists are mutable. Dictionary entries are key-value pairs, while sets are unordered collections of distinct elements. « Previous Tutorial Next Tutorial » Practice Quizzes
Test your programming and computer science knowledge with interactive MCQs and topic-based quizzes. Popular Topics
Explore the most popular programming and computer science tutorials on CodesCracker. | ||||||||||||||||||||||||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |