Remove first n
characters from a string
Write a program to remove characters from a string starting from zero up to n
and return a new string.
For example:
remove_chars("pynative", 4)
so output must be tive
. Here we need to remove first four characters from a string.
remove_chars("pynative", 2)
so output must be native
. Here we need to remove first two characters from a string.
Note: n
must be less than the length of the string.
Hint:
Use string slicing to get the substring. For example, to remove the first four characters and the remeaning use
s[4:]
.Solution:
exaplanation in video:
need an explanation for this answer? contact us directly to get an explanation for this answer