To reverse and print an array of integers in Python, you can use the built-in reverse()
method and a for
loop to print the reversed array.
Here's an example code snippet:
main.py192 chars7 lines
Output:
main.py10 chars2 lines
In the above code, we first create an example array arr
with integers from 1 to 5. Then we call the reverse()
method on arr
to reverse the elements in-place. Finally, we use a for
loop to iterate over the reversed array and print each element separated by a space using the end=" "
argument of the print()
function.
gistlibby LogSnag