219 views

3 Answers

0 0 votes

A. None

[9,7,8]

s.append(6) $\rightarrow$ [6,7,8,6] returns None to print

s.insert(0,9) $\rightarrow$ [9,6,7,8,6] Adds 9 at 0

x $\leftarrow$ 6, removing from s (s[1] was 6) [9, 7, 8, 6]

s.remove(x) Remove first occurence of x from s. [9, 7, 8]

0 0 votes

Initially:

s = [6, 7, 8]

$\texttt{append}$ changes the list in place and returns $\texttt{None}$.

print(s.append(6))

So the first output is:

None

Now the list becomes:

[6, 7, 8, 6]

After inserting $9$ at index $0$:

[9, 6, 7, 8, 6]

Then:

x = s.pop(1)

This removes and returns $6$. So $\texttt{x = 6}$ and the list becomes:

[9, 7, 8, 6]

Now $\texttt{s.remove(x)}$ removes the first occurrence of $6$.

[9, 7, 8]

Final output:

None
[9, 7, 8]
Answer:
Position:
Show:

Related questions

2 2 votes
2 2 answers
230
230 views
GO Classes asked Jul 2
230 views
A function $\texttt{deep_map(f, s)}$ replaces every non-list element $\texttt{x}$ inside a nested list $\texttt{​​​​​​​s}$ with $\texttt{f(x)}$.It modifies $\texttt{​​​​​...
2 2 votes
3 3 answers
211
211 views
GO Classes asked Jul 2
211 views
A function $\texttt{shuffle(s)}$ takes a sequence $\texttt{s}$ with an even number of elements. It returns a new list by interleaving the first half of $\texttt{s}$ with ...
2 2 votes
3 3 answers
167
167 views
GO Classes asked Jul 2
167 views
Consider the following Python code:s = [3] s.extend([4, 5]) s.extend([s.append(9), s.append(10)]) print(s)What is the output of the code above?[3, 4, 5, 9, 10][3, 4, 5, N...
2 2 votes
3 3 answers
185
185 views
GO Classes asked Jul 2
185 views
Consider the following Python code:s = [9, 7, 8] a, b = s, s[:] print(a is s, b == s, b is s) print(a.pop()) print(a + b)What is the output of the code above?True True Tr...