+ 3
What will be the output of the following python code?explain
A=[1,2,3,4,5,6,7,8,9,10,] Print(a[-1:-5])
8 Respuestas
+ 8
That will cause an error since 'a' is not the same with A. Same with 'Print'.
Syntax Errors aside, that will output an empty list [ ]
A [ -1 : -5 ]
A [ last_index : fifth_last_index ]
In non negative index term.
A [9:5]
This will return an empty list since the start index is greater than the end index.
https://code.sololearn.com/cO84hAw9kNje/?ref=app
+ 3
Moreover there are many syntax errors present in your code
+ 3
Atul Just to clarify. You can have negative numbers as start index, as long as it is less than the end index, otherwise it will output an empty list or empty string.
For example:
print(a [-5:-1] )
>> [6, 7, 8, 9]
+ 3
Atul No need to apologise, don't mind it.👍 Just a little correction, you still give good explanations.
+ 2
An empty list will be outputted.
Because index -1 is after index -5, and the list slices only works if a[N:U:M], where "N < U and M > 0" or "N > U and M < 0", otherwise an empty list produced.
The third number does not appear, so use the default number 1. That means first number should be less than the second.
+ 2
Sorry all of you actually I was carrying a wrong concept in my mind . Thanks for correcting me and again sorry all of you for my blunder
+ 1
a=[1,2,3,4,5,6,7,8,9,10,]
print(a[1:])
Use this to print a
+ 1
A=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
print(A[-1:-5])
is this what you want