Python Learning 2

Source: Internet
Author: User

First, Sort:

1. Using the method sort () to sort the list permanently

2. Use function sorted () to sort the list temporarily

Note: reverse () does not refer to arranging list elements in the opposite order of alphabetical order, but simply reversing the row of list elements
Column order:

Cars = ['BMW','Audi','Toyota','Subaru']Print(Cars) cars.reverse ()Print(Cars) ['BMW','Audi','Toyota','Subaru']['Subaru','Toyota','Audi','BMW']

Method reverse () permanently modifies the order in which the list elements are arranged, but can revert to the original arrangement at any time, in order to
Just call reverse () again on the list.

Second, determine the length of the list

Use the function Len () to quickly learn the length of the list.

  

>>> cars = ['bmw'Audi'Toyota ' ' Subaru ' ]>>> len (Cars)4 When you need to do the following tasks, Len () is useful: Determine how many aliens have not been shot, how many visualization data you need to manage, how many registered users the site has, and so on. 

Note Python starts at 1 when calculating the number of list elements, so you should not encounter a bad error when determining the length of the list.

Python Learning 2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.