AppDividend
Latest Code Tutorials

# What are the List Attributes in Python

Python list is a collection of arbitrary objects, ordered, dynamic, mutable, somewhat similar to an array in other programming languages but more flexible. The list has many attributes and methods that we can use.

## List Attributes Python

1. Python lists are dynamic.
2. Lists in Python are mutable.
3. Lists are ordered.
4. Lists can be nested to arbitrary depth.
5. Lists can contain any arbitrary objects.
6. List elements can be accessed by index.

To find the length of the list, use the len() method.

```list = [11, 18, 19, 21, 46, 29]
print(len(list))```

#### Output

`6`

To calculate the total occurrence of a given element of List, use the count() method.

```list = [11, 18, 19, 21, 46, 29, 19]
print(list.count(19))```

#### Output

`2`

To calculate the minimum of all the elements of the list, use the min() function.

```list = [11, 18, 19, 21, 46, 29, 19]
print(min(list))```

#### Output

`11`

To calculate the maximum of all the elements of the list, use the max() function.

```list = [11, 18, 19, 21, 46, 29, 19]
print(max(list))```

`46`

## Python list methods

### list.append()

To append or add a list in Python, use the append() method.

```listA = ['PS5', 'XboxSeriesX']
listA.append('Nintendo Switch')
print(listA)
```

#### Output

`['PS5', 'XboxSeriesX', 'Nintendo Switch']`

### list.extend()

To add the content of one list to another list, use the extend() method.

```listA = ['PS5', 'XboxSeriesX']
listB = ["Returnal", "Halo Infinite"]

listA.extend(listB)
print(listA)```

#### Output

`['PS5', 'XboxSeriesX', 'Returnal', 'Halo Infinite']`

### list.pop()

To remove an element from the list, use the pop() method.

```list = [11, 18, 19, 21, 46, 29, 19]
print(list.pop())```

#### Output

`19`

That is it for Python list attributes.

This site uses Akismet to reduce spam. Learn how your comment data is processed.