Simple program using list:-
list = [1,"vishal",35,5.0]
print(list)
print(list[2])
Output:
program with list methods
list = [1, 35, 344, 34433, 34, 3423]
print("list \n", list)
# NOTE:- you can use these methods only in integer list.
# sorting
list.sort()
print("\nafter sorting \n", list)
# reverse
list.reverse()
print("\nafter reversing \n", list)
# append
list.append(6) # u can add only one item at a time
print("\nafter appending\n", list)
# insert
# to insert item at a particular index
list.insert(0,0)
print("\nafter inserting at index 0\n", list)
# pop
# to pop a element from the index to screen after deleting from list
list.pop(3)
print("\nafter poping element from list\n", list)
# remove
# for this operation you should know the elment in list not the index
list.remove(3423)
print("\nafter removing the number 3423\n",list)
output:
Program with user input List
s1 = int(input("enter marks for student 1 "))
s2 = int(input("enter marks for student 2 "))
s3 = int(input("enter marks for student 3 "))
s4 = int(input("enter marks for student 4 "))
s5 = int(input("enter marks for student 5 "))
s6 = int(input("enter marks for student 6 "))
mark_list=[s1,s2,s3,s4,s5,s6]
mark_list.sort()
print(mark_list)
Output:
No comments:
Post a Comment