Python Forum

Full Version: List Creation
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, Could you pls help me out that how to create a list consisting 1:100
(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.
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))