Python Exercise Example 40
**Problem:** Output an array in reverse order.
**Program Analysis:** Swap the first element with the last one.
Program source code:
Example
#!/usr/bin/python
-- coding: UTF-8 --
if
name
==
'
main
'
:
a
=
[
9
,
6
,
5
,
4
,
1
]
N
=
len
(
a
)
(
a
)
for
i
in
range
(
len
(
a
)
//
2
)
:
a
[
i
]
,
a
[
N
i
1
]
=
a
[
N
i
1
]
,
a
[
i
]
(
a
)
The output of the above example is:
[9, 6, 5, 4, 1]
[1, 4, 5, 6, 9]
Python 100 Examples