Sovi.AI - AI Math Tutor

Scan to solve math questions

QUESTION IMAGE

what is the output of the following code? my_string = hello print(my_st…

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()

Explanation:

Step1: Analyze string indexing

In Python, negative indices count from the end of the string. For the string "Hello", the indices are:

Index (positive)01234
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.

Answer:

"e"