Small turtle Python twelfth lecture exercises --- 013 tuple

0. Please describe in one sentence what is a list? Describe what a tuple is in one sentence?

List: A large repository where you can add and remove anything at any time.  
Tuple: The enclosing list, once defined, cannot be changed (cannot be added, deleted or modified).

 

1. When would you need to use a tuple instead of a list?

We use tuples (to put power in a cage) when we want the content not to be easily overwritten.  
When we need to modify data frequently, we use lists.

 

2. Please connect the built-in methods in the list on the left of the figure below with the comments on the right, and circle the methods that can be used by the tuple.
Tuples have only two methods that tuples can use, and none of the other methods.
 
3. When creating a tuple, under what circumstances must commas and parentheses exist at the same time?
When creating a tuple with only one element, for example: a=(1,)
 
4. x, y, z = 1, 2, 3 Is x, y, z a tuple?
The default type of all multi-object, comma-separated sets that are not explicitly defined with a symbol is a tuple.
 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325912466&siteId=291194637