close

List of Numbers From 1 to N in Python

Hello guys. How are you all? I hope you all fine. In this tutorial we will learn about how to make list of Numbers From 1 to N in Python. so without wasting time lets learn about of this.

List of Numbers From 1 to N in Python

  1. How to make List of Numbers From 1 to N in Python

    To make List of Numbers From 1 to N in Python just use range(). By using range() you can make list of Numbers From 1 to N in Python. So lets learn about of this without wasting time by given below example: mylst = list(range(5,10+1)) print(mylst)
    Output : [5, 6, 7, 8, 9, 10]

  2. List of Numbers From 1 to N in Python

    To make List of Numbers From 1 to N in Python just use for loop. By using for loop you can make list of Numbers From 1 to N in Python. So lets learn about of this without wasting time by given below example: def createList(n): lst = [] for i in range(n+1): lst.append(i) return(lst) print(createList(6)) Output : [0, 1, 2, 3, 4, 5, 6]

  3. 1 in python

    To make List of Numbers From 1 to N in Python just use range(). By using range() you can make list of Numbers From 1 to N in Python. So lets learn about of this without wasting time by given below example: mylst = list(range(5,10+1)) print(mylst)
    Output : [5, 6, 7, 8, 9, 10]

Method 1: list of Numbers From 1 to N Using range()

By using range() you can make list of Numbers From 1 to N. So lets learn about of this without wasting time by given below example:

mylst = list(range(5,10+1))
print(mylst)

Output :

[5, 6, 7, 8, 9, 10]

Method 2: Use for loop

By using for loop you can make list of Numbers From 1 to N. So lets learn about of this without wasting time by given below example:

def createList(n):
    lst = []
    for i in range(n+1):
        lst.append(i)
    return(lst)
print(createList(6)) 

Output :

[0, 1, 2, 3, 4, 5, 6]

Conclusion

It’s all About this Tutorial. Hope all methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which method worked for you?

Also, Read

Leave a Comment