Study "Python": Reverse the list

This function is used when writing code, it is also very simple, just record it.

table of Contents

1. reverse () 

2. Examples


1. reverse () 

The reverse () function is used to reverse the elements in the list .

Note that this method does not return value argument is useless , but it will reverse the sort order of the elements of the list , usage is as follows:

# 无参数、无返回
list.reverse()

2. Examples

Code:

a = [1, 2, 3, 4, 5]
a.reverse()

print(a)

Output:

[5, 4, 3, 2, 1]

Published 28 original articles · praised 105 · visits 9843

Guess you like

Origin blog.csdn.net/qq_41297934/article/details/105430072