11. ancestor of python, 11. ancestor of python
According to my previous learning methods, first let's take a look at help (tuple) to see which built-in methods are available.
Help on class tuple in module _ builtin __: class tuple (object) | tuple ()-> empty tuple | tuple (iterable) -> tuple initialized from iterable's items | If the argument is a tuple, the return value is the same object. | Methods defined here: | _ add __(...) | x. _ add _ (y) <==> x + y | _ contains __(...) | x. _ contains _ (y) <=> y in x | _ eq __(...) | x. _ eq _ (y) <=> x = y | _ ge __(...) | x. _ g E _ (y) <==> x> = y | _ getattribute __(...) | x. _ getattribute _ ('name') <=> x. name | _ getitem __(...) | x. _ getitem _ (y) <=> x [y] | _ getnewargs __(...) | _ getslice __(...) | x. _ getslice _ (I, j) <=> x [I: j] | Use of negative indices is not supported. | _ gt __(...) | x. _ gt _ (y) <==> x> y | _ hash __(...) | x. _ hash _ () <=> hash (x) | _ iter __(...) | x. _ iter _ () <=> iter (x) | _ le __(...) | X. _ le _ (y) <=> x <= y | _ len __(...) | x. _ len _ () <=> len (x) | _ lt __(...) | x. _ lt _ (y) <==> x <y | _ mul __(...) | x. _ mul _ (n) <=> x * n | _ ne __(...) | x. _ ne _ (y) <=> x! = Y | _ repr __(...) | x. _ repr _ () <=> repr (x) | _ rmul __(...) | x. _ rmul _ (n) <=> n * x | count (...) | T. count (value)-> integer -- return number of occurrences of value | index (...) | T. index (value, [start, [stop])-> integer -- return first index of value. | Raises ValueError if the value is not present. | attributes | Data and other attributes defined here: | _ new _ = <built-in method _ new _ of type object> | T. _ new _ (S ,...) -> a new object with type S, a subtype of TTuple
We can see that the built-in methods of yuanzu seem to be a little small, and the general can be divided into the following types:
1. Sequence-related operations, such as indexes, slices, addition, multiplication, and member operations. (These are all described in the blog in my previous python sequence. I will not repeat them here)
2. built-in functions (according to the Convention, the built-in functions will be summarized in another article, which will be ignored temporarily)
3. Comparison operators such as greater than, less than, and equal
4. Two General built-in methods.
So we need to talk about the two parts after removing the mentioned and not talking about them for the time being. Let's look at the analysis below.
1. Comparison operators greater than, less than, or equal
How can we compare the size of the original ancestor?
In fact, it is very simple. To sum up, compare the elements in the index.
When a and B are compared, the first element is extracted first. Here, the first element is a string, and then compared by character string. The 'S' is larger than 'A', so the number of ancestor a is greater than that of ancestor B. That is to say, as long as one element is greater than the other, the whole ancestor is larger than the other, which is irrelevant to the number of elements.
Here we can summarize the rules for comparing the original ancestor:
The element at the corresponding position is retrieved one by one based on the index, so that the elements are compared. If the elements are equal, the next element is compared until the size is determined. If the elements are equal after comparison, the two ancestor is equal.
In fact, the comparison between the Yuan ancestor is like playing the game against the platform. Each Party sends a contestant. If a contestant wins, the contestant's team wins, if the two sides fail to win, the two sides will send another contestant. If the two sides fail to win at the end of the competition, they will have to shake hands to make peace.
However, in this case:
Although there is no victory or defeat in the front, I have one more, even if this is a Null String, everything is fine. In this case, it is equivalent to comparing it with an empty object None, and the Null Object None is the smallest, which must be greater than the smallest one.
Some may wonder how to compare different data types of elements, such as how to compare strings and numbers. For details, refer to my summary of comparison operators in python numbers: stamp here
2. Two common built-in Methods
2.1 T. count (value)-> integer
Returns the number of times the value appears in the ancestor (Counter). If it is not found, 0 is returned.
2.2 T. index (value, [start, [stop])
ReturnsFirstIndex. If not found, the ValueError is triggered.
When there are multiple, find the first one. You can specify the range through the index. If the index exceeds the value of python, it will be processed elegantly. However, specifying a range does not mean re-indexing. The index is calculated from the beginning of the entire ancestor.
If no error is found, note that '123' is a string. Do not confuse it.
Well, the built-in methods of yuanzu will be finished. At this time, some people will say: Coach, how can you do this?Short!
Well, it's really a little short. Here I will talk about my personal understanding of yuanzu.
First of all, I have proved in the sequence of python that every element in the ancestor is an object (those who didn't see it). Then, is the ancestor similar to a container, the container contains a series of objects. When we say that the ancestor is immutable, does it mean that the container size is fixed. However, this statement is not perfect, because I can put various objects in it, for example, I put a list, and the size of the list can be changed. If I keep increasing the list, and the list is placed in the container of yuanzu, will the list be full one day?
Certainly not. Therefore, the better image metaphor is to regard yuanzu as a menu, and the page number of this menu is fixed. Each dish in the menu has a label, that is, the index, but this menu is special. I can not only order food, but also click another menu through this menu, how to add pages to another menu is also irrelevant to the original menu.
This is my personal understanding of the ancestor.
Well, let's talk about yuanzu first. concentration is the essence. Even if it is short, it is not full of dry goods.
How can you not like such a good article?
I am so tired that I feel that I have done a good job. As a result, my blog is quite deserted. If I continue this way, I will be ill in May. What is it by the end of May?