Computer Science, asked by shivgeetasgawali, 1 month ago

Write Python statements to do the following tasks.
a) Create a list that contains the names of 5 students of your class.
b Add one more name to the list of 5 students
c) Delete the first name from the list of students​

Answers

Answered by anindyaadhikari13
0

Answer:

1. Create a list that contains the names of 5 students of your class. Here comes the python statement -

\dag \ \boxed{\tt list=["A", "B", "C", "D", "E"]}

2. Add one more name to the list of 5 students. Here comes the python statement -

\dag \ \boxed{\tt list.append("F") \: }

3. Delete the first name from the list. This can be done in two ways.

a. Using del() function.

\dag \ \boxed{\tt del(list[0])}

b. Using pop() function.

\dag \ \boxed{\tt\: list.pop(0)\:}

Explanation:

1. Here, a list named "list" is created which stores names of 5 students.

2. Lists are mutable i.e., we can change and modify the list. To add items in list, the append() function is used.

3. To delete the first name, we can do this by using pop() function or by using del()

Syntax of pop: <list>.pop(index)

Syntax of del: del(variable)

So, to delete first name, we can write list.pop(0) (index of first element is 0) or we can also write del(l[0]). We can also use remove() element but to make it less complicated, it is not used.

Similar questions