python basics - arrays

【Array】

1 Tuple: A built-in data structure in python. A tuple consists of different elements, each of which can store different types of data such as strings, numbers or even elements. Tuples are write-protected, that is, they cannot be modified after they are created. Tuples often represent a row of data, and the elements in a tuple represent different data items. You can think of tuples as immutable arrays. An example of creating a tuple is as follows:

tuple_name=(“apple”,”banana”,”grape”,”orange”)
2 List (list): Similar to a tuple, a list is also composed of a set of elements. The list can implement add, delete, and search operations, and the value of the elements can be modified. Lists are arrays in the traditional sense. An example of list creation is as follows:
list_name=[“apple”,”banana”,”grage”,”orange”]

Note: The difference between a list and a tuple is square brackets and parentheses, and a dictionary uses curly brackets.

You can use the append method to append elements to the end and remove to remove elements.

3 Dictionary: A collection of key-value pairs, where the values ​​in the dictionary are referenced by keys. Keys and values ​​are separated by colons, and key-value pairs are separated by commas, and are enclosed in a pair of curly braces. Create an example as follows:

dict={“a”:”apple”, “b”:”banana”, “g”:”grage”, “o”:”orange”}

4 Sequences: Sequences are collections with indexing and slicing capabilities. Tuples, lists, and strings are all sequences.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325252764&siteId=291194637
Recommended