Assume that the variable data refers to the string "myprogram.exe". Write the expressions that perform the following tasks: a. Extract the substring "gram" from data. b. Truncate the extension ".exe" from data. c. Extract the character at the middle position from data.
Assuming PYTHON language
To extract a substring from a given string, we put a colon(:) in the subscript and last index after : is not counted and is excluded.
a.) print(data[5:9]) as g has index 5 and m has index 8. So we need to print from index 5 to 9 as 9 is excluded.
b.) print(data[0:9]) as first m of 'myprogram' has index 0 and last m of 'myprogram' has index 8. So we need to print from index 0 to 9 as 9 is excluded.
c.) print(data[6:7]) since middle character has index 6. So we need to print from index 6 to 7 as 7 is excluded.
Get Answers For Free
Most questions answered within 1 hours.