How To Make A List In Python?

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

Use the `list()` function: `my_list = list((1, 2, 3))`

Create an empty list: `my_list = []`

Create an empty list with `list()`: `my_list = list()`

Create a list of strings: `my_list = [“apple”, “banana”, “cherry”]`

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

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

Use a list comprehension: `my_list = [x for x in range(5)]`

Suggested for You

Trending Today