How to sort in python

爱喝马黛茶的安东尼
Release: 2019-06-20 10:49:20
Original
4568 people have browsed it

In the python design language, there are many methods that can be used directly to operate elements of data types. Among them, the sorted method is to sort the elements of Python's basic data types, which can be numbers, strings, etc.

How to sort in python

How to sort in python?

The steps are as follows:

The first step is to define a variable a and call the sorted method to sort the elements (strings) in the list, as shown in the figure below Display:

How to sort in python

Related recommendations: "python video tutorial"

The second step, in addition to strings, the list can , it can also be of numerical type, as shown in the figure below:

How to sort in python

#The third step, if you put positive numbers and negative numbers together and sort them according to their absolute values, you can Use the sorted method and add key=abs, as shown in the figure below:

How to sort in python

The fourth step, if the sorted elements are strings, you can also use strings Sort by capital letters, as shown in the figure below:

How to sort in python

The fifth step, in addition to sorting by capital letters of the string, you can also sort in reverse order, use the reverse attribute, as follows As shown in the picture:

How to sort in python

The sixth step, if you use the lowercase letters of the string to sort, and do not use reverse order, as shown in the following picture:

How to sort in python

The above is the detailed content of How to sort in python. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template