Computer Science, asked by Gomin, 1 day ago

Write the Python Program to Perform following operation on string “Interpreted Language” a. First one character b. Last one character c. Everything except the first one character d. Everything except the last one character e. Everything between first and last two character f. Skip one character g. Reverse String.

Answers

Answered by Equestriadash
14

Co‎de:

\tt s\ =\ in put("Enter\ a\ string:\ ")\\print()\\\sf \#a.\ first\ character\\\tt print(s[0])\\\sf \#b.\ last\ character\\\tt print(s[-1])\\\sf \#c.\ everything\ except\ the\ first\ character\\\tt print(s[1:])\\\sf \#d.\ everything\ except\ the\ last\ character\\\tt print(s[:-1])\\\sf \#e.\ everything\ between\ first\ and\ last\ two\ characters\\\tt print(s[2:-2])\\\sf \#f.\ skip\ one\ character\\\tt print(s[::2])\\\sf \#g.\ reverse\ string\\\tt print(s[::-1])

Explanation:

The above operations can be done using string slicing, which is an act of retrieving a subset from a set, using its index values. Each character in the string has its own positive and negative indexing, and a slice command is passed as follows:

\tt <string\_na me>[start:stop:step]

  • start - represents the starting index
  • stop - represents the ending index
  • step - represents the step value/by how many values it needs to skip

To know more about slicing, refer to the link below:

brainly.in/question/16088533

Similar questions