How to Make List in Python?

Use square brackets: `my_list = [1, 2, 3]`

Use empty brackets: `my_list = []`

Use the `list()` constructor: `my_list = list()`

Create a list from an iterable: `my_list = list(“abc”)`

Create a list with mixed types: `my_list = [1, “two”, 3.0, True]`

Create a nested list: `my_list = [[1, 2], [3, 4]]`

Create a list with repeated values: `my_list = [0] * 5`

Add items with `append()`: `my_list.append(4)`

Add multiple items with `extend()`: `my_list.extend([5, 6])`

Insert an item with `insert()`: `my_list.insert(1, 10)`

Suggested for You

Trending Today