Python Learning Notes (iii)------from the Turtle video learning

Source: Internet
Author: User

010-012 Main contents:

1. The list can have integers, floating-point numbers, strings, objects

General list: love = [' Apple ', ' banana ', ' redhat ', ' CPU ']

Mixed list: Mix = [2, ' Liebiao ', 3.14,[1,2,3]]

Empty list: empty = []

2.append () Adds an element to the tail of the list, adding only one

Example: >>>love.append (' Hello ')

At this time love = [' Apple ', ' banana ', ' redhat ', ' CPU ', ' hello ']

3.extend () extension list, you can add 2 elements to the end, but the parameter can only be one, and it is a list form. The principle is to extend another list with one list

e.g. >>>love.extend ([' Earth ', ' moon ')

At this time love = [' Apple ', ' banana ', ' redhat ', ' CPU ', ' hello ', ' earth ', ' moon ']

4.insert (the position of the list (the first bit is 0), the inserted element)

For example >>>love.insert (1, ' sun ')

At this time love = [' Apple ', ' sun ', ' banana ', ' redhat ', ' CPU ', ' hello ', ' earth ', ' moon ']

5. Replacement of the order of elements in the list (median temp = love[1])

6. Removing elements from a list

Love.remove (' Earth ')

7.del Love[3] The position of the element in parentheses

Del love parentheses followed by list name, list will be deleted

8.love.pop (position ordinal, can be omitted, default delete last) The return value is the deleted element

9. List copy love[1 (if omitted, viewable as 0): 5 (does not include this position; if omitted, always included to the last element)]

10.dir ()

11..count () detects the number of occurrences of elements in parentheses in the list

12..index (element, range) detects the position of the target element

Eg:love.index (cpu,0,7)

Position reversal in 13..reverse () list

14..sort () sort from small to large

. Sort (reverse=true) from big to small

15. The difference between copy love2 = love1 and love2 = love1[:]

Python Learning Notes (iii)------from the Turtle video learning

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.