Login using Social Account
     Continue with GoogleLogin using your credentials
A segment of a string is called a slice.
s = "cloudxlab"
print(s[1:5])
It prints the segment starting from the character with index 1
to index 4
i.e., 'loud'
. Therefore, it includes the 1st i.e. 1
and excludes the last i.e. 5
.
If the 1st index is greater or equal to the 2nd index, it returns an empty string enclosed in the quotation,
print(s[4:4])
It prints ''
. This is also a string with length 0.
We can also use negative indices
to get some character from the string. Negative indices
count backward from the last. To access the last character
we can write,
print(s[-1])
For second last character,
print(s[-2])
and likewise.
slicing_func
that takes an argument (assume string)Sample Input:
slicing_func("Hello World")
Sample Output:
llo World
Taking you to the next exercise in seconds...
Want to create exercises like this yourself? Click here.
Note - Having trouble with the assessment engine? Follow the steps listed here
Loading comments...