17.9k views
3 votes
I dont understand this at all! PLZ help me

DO NOT ENTER CODE INTO THE COMPUTER! What will be printed by each of the print statements in the following code with this list

 ex = [5, 3, 0, 1, 2]



I dont understand this at all! PLZ help me DO NOT ENTER CODE INTO THE COMPUTER! What-example-1
User Philkark
by
4.3k points

1 Answer

4 votes

Answer:

See explanation

Step-by-step explanation:

Given


ex = [5,3,0,1,2]

Solving (a):

print(ex[0:2])

This prints the elements from 0 index to 2-1

In other words, it prints index 0 and 1

Hence, the output is [5, 3]

Solving (b):

ex.append(8) --> This adds 8 to the end of the list

print(ex) --> This prints the updated list: [5, 3, 0, 1, 2, 8]

Solving (c):

ex.remove(0) --> This removes 0 from the list

print(ex) --> This prints the updated list: [5, 3, 1, 2, 8]

Solving (d):

ex.pop() --> This removes the last ite, from the list

print(ex) --> This prints the updated list: [5, 3, 1, 2]

User Gammelgul
by
4.3k points