Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

How can I do the following in Python?

array = [0, 10, 20, 40] 

for (i = array.length() - 1; i >= 0; i--)

I need to have the elements of an array, but from the end to the beginning.

1 Answer

0 votes
by (106k points)

Simply use the below-mentioned method to reverse a list in a Python:-

>>> L = [0,10,20,40] 

>>> L[::-1] 

[40, 20, 10, 0]

Related questions

0 votes
1 answer
asked Jul 3, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
asked Feb 19, 2021 in Python by laddulakshana (16.4k points)
0 votes
1 answer

Browse Categories

...