Python sequences: tuples, dictionaries, sets

Article directory tuple Tuple creation and deletion The difference between tuples and lists Sequence unpacking generator expression dictionary Dictionary creation and deletion Reading dictionary elements Adding, modifying and deleting dictionary elements dictionary comprehension gather Collection creation and deletion Adding and deleting collection elements Set operations A sequence is a memory space used to store multiple […]

Python strings, lists, tuples, sets and dictionaries

Strings, lists, tuples, sets and dictionaries 1. String (str) A string is a text data type in Python, it is an immutable sequence of zero or more characters. String literals can be enclosed in single quotes, double quotes, or triple quotes, or special characters can be entered using backslash \ escape characters. str1 = ‘Hello, […]

Python dictionary parsing (creating a dictionary using a list of tuples, creating a dictionary using keyword arguments, dict() function, del, clear(), keys(), values(), items(), get(), dictionary derivation)

Article directory Python dictionary parsing Python dictionary creation method basic method Use the built-in dict() function Use a list of tuples Use keyword arguments Dictionary operations Access dictionary elements Modify dictionary Delete dictionary elements, clear dictionary, delete dictionary (del, clear()) The difference between deleting a dictionary and clearing a dictionary Clear the dictionary (clear()) Delete […]

Python containers–strings, lists, tuples, dictionaries

String Function: Used to store descriptive data String – Definition # 1. Single quote ‘abc’ # 2. Double quotes ‘abc’ # 3. Triple quotes ‘abc’ str1 = ‘string1’ str2 = “string2” str3 = “””First line second line The third row “”” print(str1) print(str2) print(str3) String – subscript (index) Strings in python can correspond to character […]

Python data containers – tuples and strings

1. Data container-tuple 1. Definition of tuple (1) Empty tuple: tuple name = () or tuple name = tuple() (2) Non-empty tuple: Tuple name = (element 1, element 2, element 3,…) When there is only one element, a comma is required: tuple name = (element 1,) # Define empty tuple tuple1 = () print(tuple1, type(tuple1)) […]

Python collections (lists, tuples, dictionaries)

Python collections (lists, tuples, dictionaries) Table of contents One: List 1.1 List overview 1.2 Add, delete, modify and check the list 1.2.1 Find elements in a list 1.2.2 Adding elements to the list 1.2.3 Modify elements in the list 1.2.4 Delete elements in the list 1.3 List traversal loop 1.3.1 for loop traverses the list […]

Python Basic Data Structures: A Deep Dive into Lists, Tuples, Sets, and Dictionaries

Personal website: [Tool Collection] [Game Collection] [God-level Source Code Resource Network] Front-end learning course: [28 cases to learn front-end fun] [400 JS interview questions] If you are looking for friends to learn, communicate, and fish, please click [Moyu Learning and Exchange Group] As a multi-purpose programming language, Python provides a variety of basic data structures, […]

Exploring use cases for TypeScript tuples

Tuples extend the functionality of the array data type. Using tuples, we can easily construct special types of arrays where elements are of a fixed type relative to index or position. Due to the nature of TypeScript, these element types are known at initialization time. Using tuples, we can define the type of data that […]

Lists, Tuples, Dictionaries and Sorting in Python

Python list Sequences are the most basic data structure in Python. Each value in the sequence has a corresponding position value, called an index, where the first index is 0, the second is 1, and so on. Python has 6 built-in types for sequences, but the most common are lists and tuples. Operations that can […]