QUESTION IMAGE
Question
what is the output of the following code?
my_string = hello
print(my_string-4)
\h\
\e\
\i\
error
question 13
which method is used to convert a string to uppercase?
upper case()
upper()
to_upper()
make_upper()
Step1: Analyze string indexing
In Python, negative indices count from the end of the string. For the string "Hello", the indices are:
| Index (positive) | 0 | 1 | 2 | 3 | 4 |
|---|---|---|---|---|---|
| Index (negative) | -5 | -4 | -3 | -2 | -1 |
Step2: Access the character
When we use my_string[-4], we are accessing the character at the -4th index. From the above mapping, the character at -4th index is "e".
In Python, the method to convert a string to uppercase is upper(). uppercase() is not a valid Python string method. to_upper() and make_upper() are also not standard Python string methods for this purpose.
Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
"e"