How to Initialize a List in Python
![how to initialize a list in python](https://pythonpoint.net/wp-content/uploads/2020/12/how-to-initialize-a-list-in-python-1024x576.jpg)
A list can be initialized in different ways in Python.
- Using for loop and append
li = [] for i in range(1, 11): li.append(i) print(li)
Output:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
- Using List comprehension
li = [i for i in range(1, 11)] print(li)
Output:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Subscribe
Login
Please login to comment
0 Discussion