What are the three types of python sequence types?
What three types of python sequence types include
Python sequence types include: List, tuple, dictionary
List: ordered variable sequence
Create: userlist = [1,2,3,4,5,6]
Modify: userlist[ 5] = 999
Add: userlist.append(777)
Delete: userlist.remove(4) or del(userlist[3])
pop method: move Except one element, defaults to the last one.
userlist.pop(3) removes the third element and returns the value.
Insertion: userlist.insert(3,555)
Sort: userlist.sort() The default is ascending order userlist.sort(reverse=True) uses descending order. Or use sorted(userlist) to sort
Reverse: userlist.reverse()
Search: userlist.index(3) Or use in reserved words to search
Get Element: userlist[2]
Get coordinates: userlist.index(999)
Connection of list: extend() method. Or use to concatenate two lists. The two are different
Tuple: ordered immutable sequence
Creation: tuple1=(1,2,3,4,5,6)
Modification: The value cannot be modified
Add: There is no append function, it can only be added by assignment: tuple2=(tuple1,7,8,9)
Delete: (None for immutable sequence) This attribute)
Insert: (Immutable sequence has no such attribute)
Sort: Only sorted(userlist) can be used for sorting
Reverse: (Immutable sequence has no such attribute) This attribute)
Search: userlist.index(3) or use in reserved word to search
Get the element: tuple1[4]
Get the coordinates: tuple1.index( 3)
Deduplication: set(tuple1)
Unpacking: a,b,c,d,e,f = tuple1
Dictionary: Unordered Variable sequence
Create: dict1={'a':'001','b':'002','c':'003','d':'004'} or Create a dictionary using a function: dict1 = dict([('a','001'),('b','002'),('c','003'),('d','004')] )
Modification: The value cannot be modified
Add: direct assignment: dict1['f'] = '006'; or use the setdefault() function to add dictionary elements: dict1.setdefault('e ','005'), when the key already exists, keep the original k-v unchanged, and when the key does not exist, add the k-v.
Delete: There is no remove() function for the dictionary, but the kv of the dictionary can be deleted with the del() function: del(dict1['e']). You can also use the pop() method to delete the specified element. Since the dictionary is unordered, pop() will not delete the last element by default. You must specify the key
for insertion: the dictionary has no index coordinates. Only addition, no insertion
Sort: The dictionary has no index coordinates, so it is also unordered, and the value can only be found through the key. But it can be sorted by other methods: for k in sorted(dict1): print(k,dict1[k])
Reverse: (Unordered and cannot be reversed)
Find: dict1[ 'c'] or use the in reserved word to search. Or use the items() method to convert each kv pair of the dictionary into a tuple for convenient search
Get elements: dict1['c'] or use dict1.get('c')
Get coordinates: key is unique, value is not unique, can only be found by looping the convenience dictionary
Deduplication: key is unique, no need to deduplicate
String – tuple –List-Dictionary type conversion
1. Convert tuple to list: list()
2. Convert list to tuple: tuple()
3. Convert dictionaries to lists and tuples: dict1.items()
4. Convert list tuples to dictionaries: dict()
numerouspython training videos, all on the Python Learning Network, welcome to online learning!
The above is the detailed content of What are the three types of python sequence types?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

To run Python code in Sublime Text, you need to install the Python plug-in first, then create a .py file and write the code, and finally press Ctrl B to run the code, and the output will be displayed in the console.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Golang is better than Python in terms of performance and scalability. 1) Golang's compilation-type characteristics and efficient concurrency model make it perform well in high concurrency scenarios. 2) Python, as an interpreted language, executes slowly, but can optimize performance through tools such as Cython.

Writing code in Visual Studio Code (VSCode) is simple and easy to use. Just install VSCode, create a project, select a language, create a file, write code, save and run it. The advantages of VSCode include cross-platform, free and open source, powerful features, rich extensions, and lightweight and fast.

Running Python code in Notepad requires the Python executable and NppExec plug-in to be installed. After installing Python and adding PATH to it, configure the command "python" and the parameter "{CURRENT_DIRECTORY}{FILE_NAME}" in the NppExec plug-in to run Python code in Notepad through the shortcut key "F6".
