Q. In a string slice, the start and end values can be beyond limits. Why?


Answer = 

 

Python will consider the limits of the string i.e., for missing begin-index, it will consider 0 (the first index) and for missing last value, it will consider length of the string.

Example - 

>>> a = "Path Walla" 

>>>a[ :7 ]

Path w

>>> a [3:]

h Walla


4 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. In string slice the start and ending of values can be beyond limits why

    ReplyDelete
    Replies
    1. Skip either of the begin-index or last, Python will consider the limits of the string i.e., for missing begin-index, it will consider 0 (the first index) and for missing last value, it will consider length of the string.

      Delete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post