Python Forum
List Creation - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: List Creation (/thread-16805.html)



List Creation - sunnyarora - Mar-15-2019

Hi, Could you pls help me out that how to create a list consisting 1:100


RE: List Creation - Larz60+ - Mar-15-2019

Please read: https://python-forum.io/misc.php?action=help&hid=19


RE: List Creation - perfringo - Mar-15-2019

(Mar-15-2019, 01:28 PM)sunnyarora Wrote: Hi, Could you pls help me out that how to create a list consisting 1:100

Start with documentation: list

Quote:Lists may be constructed in several ways:
  • Using a pair of square brackets to denote the empty list: []
  • Using square brackets, separating items with commas: [a], [a, b, c]
  • Using a list comprehension: [x for x in iterable]
  • Using the type constructor: list() or list(iterable)

You don't want get empty list so first option is out. If you want to have list with numbers 1-100 in it then you can always use second option:

lst = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
      11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 
      21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 
      31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 
      41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 
      51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 
      61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 
      71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 
      81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 
      91, 92, 93, 94, 95, 96, 97, 98, 99, 100]
However, if you are not so much in typing then I suggest to explore options three and four.


RE: List Creation - farhan275 - Mar-15-2019

At first I want to give you a basic idea about list. In python List is a collection which is ordered and changeable.
fruit_list = ["Apple","Banana","Grape"]#this list can changeable. You can add or remove any item from this list.

fruit_list.append("orange") #append() function used for add item in list 

print(fruit_list) 

you can use range function to create a list consisting 1:100
list(range(1, 101))