Can someone explain both? A = [1,2,3,4,5] Print [-1:-3:-1] And Print[:]
Print(a[:]) Will return all value as a list have because it indicates from first to last And for print(a[-1:-3:-1]) Assume it as a[-1:-(3-1)] And in reverse order last index is indicated with -1
' : ' is slice operator,it will take two arguments and one more optional arguments. The two arguments are start and end . Here start is included and end is excluded. print(A[:]) here no arguments given it start at 0 and ends at len(A). Third one option argument is jump. A[-1:-3:-1] Start -1 End -3 Jump -1
Got it thank you 😊
Devika Krishnan i was asking how it works. Its not defined.
In list A = [1,2,3,4,5] We will count, 1 as 0 2 as 1 3 as 2 4 as 3 And so on... If you print [:] in this way, then the output would be [1,2,3,4,5]
but this code will show u an error Print[-1:-3:-1] NameError: name 'Print' is not defined
Problem Statement Given two integers a and b, your task is to calculate and print the following four values:
Please help, any idea?
Loop question, I've tried everything that I knew I just don't know. Please help me solve it out
What is wrong? Error on test.