Creating List in Python
पाइथन में लिस्ट तैयार करने के बहुत से तरीके होते हैं।
1. Empty List:-
Empty List बनाने के लिए, simple रूप से square bracket ([]) का use किया जाता है।
Example:-
my_list = []
print(my_list) # [ ]
print(type(my_list) # list
2. List with Items:-
List with Items के साथ लिस्ट बनाने के लिए, आइटम को square bracket में अलग-अलग comma (,) द्वारा separate करके दिया जाता है।
Example:-
l=[10,20,30,40]
print(l)
3. Dynamic list creation:-
l=eval(input(“Enter list element in square bracket “)
print(l)
print(type(l))
4. Using List function:-
List function is used to Separate character by character
list1=list(input(“enter element of list “))
print(list1)
5. Using split function:-
Split function is used to separate word by word.
list2=”ak it solution”
print(list2)
l=list2.split()
print(l)
print(type(l))
Creating List in Python
There are many ways to prepare lists in Python.
1. Empty List:-
To create an empty list, simply square bracket ([]) is used.
Example:-
my_list = []
print(my_list) # [ ]
print(type(my_list) # list
2. List with Items:-
To create a list with List with Items, items are placed in square brackets, separated by commas (,).
Example:-
l=[10,20,30,40]
print(l)
3. Dynamic list creation:-
l=eval(input(“Enter list element in square bracket “)
print(l)
print(type(l))
4. Using List function:-
List function is used to Separate character by character
list1=list(input(“enter element of list “))
print(list1)
5. Using split function:-
Split function is used to separate word by word.
list2=”ak it solution”
print(list2)
l=list2.split()
print(l)
print(type(l))