Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
List Creation
#1
Hi, Could you pls help me out that how to create a list consisting 1:100
Reply
#2
Please read: https://python-forum.io/misc.php?action=help&hid=19
Reply
#3
(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.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#4
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))
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  List Creation and Position of Continue Statement In Regular Expression Code new_coder_231013 3 1,662 Jun-15-2022, 12:00 PM
Last Post: new_coder_231013
  List creation and return in Function leoahum 3 2,417 Mar-04-2019, 04:45 PM
Last Post: leoahum
  2D list creation garikhgh0 2 2,601 Feb-01-2018, 11:28 AM
Last Post: garikhgh0

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020