python learning, List

Python List

What is a list

A list is a collection of column data types, similar to a tuple, but the difference is that lists are mutable

Lists are represented by square brackets []

1
2
3
4
5
6
7
students = ['Bil Gates', 'Hello', 'Mark']

teachers = ['teacher1', 'teacher2', 'teacher3', 'teacher4']

lsit1 = [1, 3, 5, 6, 2]

list2 = ['a', 'b', 'c', 'z', 'q']

Access list element

1
2
3
4
5
6
7
students = ['Bil Gates', 'Hello', 'Mark']

# The first element of the access list
students[0]

# Access element 3
students[2]

Modify list

1
2
3
4
5
6
7
students = ['Bil Gates', 'Hello', 'Mark']

# Modify the second element of the list
students[1] = 'Hello, front club'

# Append elements to the end of the list
students.append('Pony')

Remove list element

1
2
3
4
students = ['Bil Gates', 'Hello', 'Mark']

# Delete the second element of the list 'Hello'
del students[1]

Some methods of lists

1
2
3
4
5
6
7
students = ['Bil Gates', 'Hello', 'Mark']

# Get the number of list elements
len(students)

# List append element
students.append('Really')
Persist in original technology sharing, your support will encourage me to continue to create!