Creating a list | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

Creating a list

What is the python code to create a list using a for loop?

2nd Nov 2020, 6:35 AM
Mawande Mbudane
Mawande Mbudane - avatar
6 Answers
+ 11
Mawande Mbudane , please show us your attempt before we can help. Thanks!
2nd Nov 2020, 10:22 AM
Lothar
Lothar - avatar
+ 4
#suppose you want to create a list from 1 to 100 X = [i for i in range(1,101)]
2nd Nov 2020, 9:54 AM
Md. Faheem Hossain
Md. Faheem Hossain - avatar
+ 2
print(*[ i for i in range((int(input("min scale"))),(int(input("max scale")))+1)],sep=", ") #or print([ i for i in range((int(input("min scale"))),(int(input("max scale")))+1)])
2nd Nov 2020, 1:19 PM
Radosław Krzysiu Krzyżagórski
Radosław Krzysiu Krzyżagórski - avatar
+ 1
1 add string 2 separate by comma 3 Concatenate 4 add [ ] 🤔
3rd Nov 2020, 5:16 PM
Sanjay Kamath
Sanjay Kamath - avatar
+ 1
Thank you so much for all your valued input. I needed to use a loop to add items in a list though the append() append function. I cracked the code and wrote a lottery game (check my codes). Thank you all 🙏
3rd Nov 2020, 5:28 PM
Mawande Mbudane
Mawande Mbudane - avatar
0
name=[2,5,6,7,8,9,1] for i in name: print(i)
2nd Nov 2020, 8:06 PM
Vincent Birma Reuben
Vincent Birma Reuben - avatar