Little Turtle Python After the 11th lecture exercise

Source: Internet
Author: User

0. Note that this question is a bit different from the one in the last lesson, please go on the computer experiment or the answer.

Old = [1, 2, 3, 4, 5]
New = Old
Old = [6]
Print (new)

What do you think will be printed if you do not operate on the computer?

1,2,3,4,5

1. How do I change the ' Little Turtle ' below this list to ' small squid '?
List1 = [1, [1, 2, [' Little Turtle ']], 3, 5, 8, 13, 18]

list1[1][2]=[' small squid ']

2. In order to sort a list, what method do I use?

List name. Sort ()

3. To sort the list in reverse order, what method do I use?

List name. Sort ()

List name. Reverse ()

or list name. Sort (reverse=true)

4. The list also has two built-in methods not to introduce, but smart you should be able to explore the use of the doorway it: Copy () and Clear ()

list1=[1,2,3,4]

List1.clear () #clear () do not add parameters

Print (LIST1)----[]

List2=list1.copy ()

Print (LIST2)-----[1,2,3,4]

5. Have you ever heard of list derivation or list parsing?

List comprehensions, also called List parsing, is inspired by the functional programming language Haskell. Ta is a very useful and flexible tool that can be used to dynamically create lists with syntax such as:
[About A's expression for a-B]

such as the equivalent

List1 = []
For x in range (10):
List1.append (x**2)

Little Turtle Python After the 11th lecture exercise

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.