Computer Science, asked by tapastapu864, 4 months ago

) Write a program to assign “ LONDON BRIDGE IS FALLING DOWN ” in an


appropriate variable. Print the following:-

i) 9 characters from left.) Write a program to assign “ LONDON BRIDGE IS FALLING DOWN ” in an

appropriate variable. Print the following:-

i) 9 characters from left.

ii) 9 characters starting from 8th characters.

iii) last 4 characters. [3]





ii) 9 characters starting from 8th characters.

iii) last 4 characters. [3]​

Answers

Answered by Equestriadash
7

string = “LONDON BRIDGE IS FALLING DOWN”

i) string[-9:]

ii) string[7:16]

iii) string[-4:]

String slicing is the act of retrieving a substring from a given string. It is performed using index values assigned to each character in a string.

Positive indexing [left to right] starts from 0 and negative indexing [right to left] starts from -1. It is important to keep in mind that if a string contains spaces/special characters, those will also have an assigned index value.

A slice command follows this syntax:

string_name[start:stop:step]

where,

  • start - starting index value
  • stop - ending index value
  • step - the value by which the traversing must skip
Similar questions