I am a beginner in Python programming. I have checked what the methods does separately, but not getting as a whole. Here is a program was written as a answer for the problem: Write a program to print all elements of an array in reverse order:
if __name__ == '__main__': #1
n = int(input()) #2
#3
arr = list(map(int, input().rstrip().split())) #4
for i in range(n): #5
print(arr[-i-1],end=' ') #6
I am not getting line 4. Can anyone explain step by step what that line is doing? How they are working and giving the output as a whole? The inputs were separated by space:
5 #length of the array
1 2 3 4 5 #inputs separated by space