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