Python Practice Example 40

Python 100例Python 100 Examples

Problem:Output an array in reverse order.

Program analysis:Swap the first with the last.

Program source code:

Example

#!/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 output of the above example is:

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

Python 100例Python 100 Examples

Other extensions