Latest web development tutorials

Python includes exercises 40

Python 100 Li Python 100 Li

Title: an array of reverse output.

Program Analysis: The last exchange with the first one.

Source Code:

#!/usr/bin/python
# -*- coding: UTF-8 -*-

if __name__ == '__main__':
    a = [9,6,5,4,1]
    N = len(a) 
    print a
    for i in range(len(a) / 2):
        a[i],a[N - i - 1] = a[N - i - 1],a[i]
    print a

The above example output is:

[9, 6, 5, 4, 1]
[1, 4, 5, 6, 9]

Python 100 Li Python 100 Li