Computer Science, asked by Anonymous, 1 year ago

What are negative indexes and why are they used?

@Python

Answers

Answered by EHSASS
9

╰☆☆ ʜᴇʀᴇ ɪs ʏᴏᴜʀ ᴀɴsᴡᴇʀ ☆☆╮

The sequences in Python are indexed and it consists of the positive as well as negative numbers.

The numbers that are positive uses ‘0’ that is uses as first index and ‘1’ as the second index and the process goes on like that.

The index for the negative number starts from ‘-1’ that represents the last index in the sequence and ‘-2’ as the penultimate index and the sequence carries forward like the positive number.

The negative index is used to remove any new-line spaces from the string and allow the string to except the last character that is given as S[:-1]. The negative index is also used to show the index to represent the string in correct order.

ᴇʜsᴀss ☆

Answered by bharati27
1

index's are used in arrays in all programming languages.we can access the elements of an array by going through their indexs.but no programming language allows us to use negative index value such as -4.python programming language supports negative indexing of arrays, which is not available in arrays in most other programming languages.this means that the negative index value of -1 gives the last element and -2 gives the second last element of an array.the negative indexing starts from where the array ends.this means that the last element of the array is the first element in the negative indexing which is -1.

hope it will help you..

✌️✌️✌️✌️

Similar questions