4. Giv n a string that has a length of 1000, write a line of code to get substri
ID: 3743727 • Letter: 4
Question
4. Giv n a string that has a length of 1000, write a line of code to get substring (a sequence of string) of the string. 1. Given start 10 end 80, return required string. 2. Given start = 800, extract all characters from start position to end 3. Given start 800, end 700, extract all characters 4. Given start = 800, step =-1, extract all characters 5. Extract substring from original one with a step of 3 6. Reverse original string 7. Get character that at position 987 of given string 8. Reverse the string, start 72, end 199Explanation / Answer
/*If you have any query do comment in the comment section else like the solution*/
Note: Copy and paste the below python code carefully with proper indentation in your IDE or you will get compilation errors
I have a confusion in step 3,4 and 5 if my answer is wrong do comment with explanation I will rectify the solution.
# Hello World program in Python
str=input();
tmp=str
print("1. String from 10 to 80v: ",str[10:-919]);
print("2. String from 800 to end: ",str[10:]);
print("3. String from 800 to 700: ",(str[700:-199])[::-1]);
print("4. String from 800 to step -1 : ",(str[799:-199])[::-1]);
print("5. String from 0 to step of 3: ",str[0:-199]);
print("6. Reverse of original string : ", tmp[::-1]);
print("7. Character at index 987: ",str[987]);
print("8. Reverse string from 72 to 199: ",(str[72:-800])[::-1]);
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.