Python basic grammar reverse and reversed

1. The reverse() method
reverse() is a built-in method of the list in python (there is no such built-in method in dictionaries, strings and tuples), which is used to reverse the data in the list

insert image description here
Note that the return value of the lista.reverse() operation is None, and the result of its action needs to be printed to see the specific effect of the list.

2. The reversed() function
reserved() is one of python's built-in functions. Its function is to return an iteration of a reversed sequence for a given sequence (including lists, tuples, strings, and range(n) intervals). The syntax format of the operator (for traversing the reverse sequence)
:

reversed(seq)

seq can be a list, an element, a string, and a range list generated by range()

Note: Using the reversed() function to reverse the order will not modify the order of elements in the original sequence.
insert image description here
When b gets the flip value of a, add list(xxx)

Guess you like

Origin blog.csdn.net/weixin_44934373/article/details/130038700