Question: Use Python Shell Window to answer questions 1 to 3 on a word file. Given: L = ['a', 7, 6, 5,Jack,3.4], write a statement for
Use Python Shell Window to answer questions 1 to 3 on a word file.
- Given: L = ['a', 7, 6, 5,"Jack",3.4], write a statement for each of the followings:
- a statement that prints the first element in the list
- a statement that prints the last element in the list
- a statement that prints [7, 6, 5] ; use the slicing operator.
- a statement that prints ['a', 7, 6] ; use the slicing operator.
- a statement that prints ["Jack", 3.4]; use the slicing operator.
- a statement that creates a copy of list L; use the slicing operator.
- A statement that prints all elements in List L in reverse order; use the slicing operator.
- Given: L1 = [1,3,2] and L2 = [7,8], write a statement for each of the followings:
- a statement that inserts 0 at the end of list L1; after inserting 0, L1 = [1,3,2,0].
- a statement that removes the second elements of list L1; after removing the second element, L1 = [1, 3].
- A statement that inserts the elements in list L2 at the end of list L1; after inserting 7, and 8, L1 = [1,3,2,7,8].
- A Statement that sort list L1; after sorting, L1 = [1,2,3].
- A statement that inserts 11 before index 2 in L1; after inserting 11, L1 = [1,3,11,2].
- A statement to remove 3 from list L1; after removing 3, L1 = [1,2].
- A statement that reverses L1; after L1 reversed L1 = [2,3,1].
- Answer the followings:
- Consider the following code:
list1=[1,2,99]
list2=list1
list3=list2
list1=list1.remove(1)
print(list3)
(a) What is printed?
(b) How can you change the code so list3 is unchanged?
- Consider:
ListA = [1,2,3,4,5]
ListB = ListA
ListA[2] = 10
What is the value of ListB[2]?
- Consider:
ListA = [1,2,3,4,5]
ListB = []
for num in ListA:
ListB.append(num)
ListA[2] = 10
(a) What is the value of ListB[2]?
(b) What is the value of ListB?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
