158k views
1 vote
What is the missing line of code?

>>> phrase = "You are amazing!"
>>> _____
'u a'

phrase[3:6]

phrase[2:6]

phrase[3:5]

phrase[2:5]

1 Answer

4 votes

Answer:

phrase[2:5]

Step-by-step explanation:

Given:

The above code segment

Required

Which instruction returns 'u a'

First, we need to get the index of u in the phrase:

u is at the third position but in programming, index starts at 0.

So, u is at index 2

Next, we need to get the index of a in the phrase:

a is at index 4

One of the ways to return a sub string from a string in python is
string[start:stop+1]

Where:


start = 2 ----- index of u


stop = 4 ----- index of a

phrase ---- The string variable

So, the instruction that returns 'u a' is:
phrase[2:5]

Where 5 = 4 + 1

User Roberto Pegoraro
by
7.6k points

No related questions found