Learn Python's data type summary from the old

  • 2020-04-02 14:07:29
  • OfStack

The table below lists the data types that you've already learned and are part of python's core data types, which are called built-in objects.

The object, that is, everything you face is an object. All data types are an object. The English word is "object", which directly means "object" in Chinese, just as we do in the real world, many things we see and use can be collectively referred to as "things". A thing is an object. In programming, that thing called object orientation is also known as "object orientation," right? It's ambiguous.

Object type For example,
int/float 123, 3.14
str 'qiwsir.github.io'
list [1, [2, 'three'], 4]
dict {'name':"qiwsir","lang":"python"}
tuple (1, 2, "three")
set set("qi"), {"q", "i"}

For any type of data, simply use dir(object) or help(obj) to view the relevant function in interactive mode, which is how you can view the relevant help documents. For example:


>>> dir(dict)

The viewer needs to move the mouse to see the entire list (which is essentially a list) :


['__class__', '__cmp__', '__contains__', '__delattr__', '__delitem__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'clear', 'copy', 'fromkeys', 'get', 'has_key', 'items', 'iteritems', 'iterkeys', 'itervalues', 'keys', 'pop', 'popitem', 'setdefault', 'update', 'values', 'viewitems', 'viewkeys', 'viewvalues']

Skip the ones at the beginning of the double underscore to see the following ones, which are the built-in functions of dict. As for the detailed operation method, it is obtained in a way similar to help(dict.pop). This is what was said before. Say it again.

My point of view: learning, the important is the learning method, not the step-by-step code.

Today is a review, we will improve on the original basis. So, also take a look at the things above that start with a double underscore. Please look around and see if you can find this: "arbitration doc". What is this? It's a file with a detailed explanation of the object being viewed. You can view it in interactive mode like this:

> > > Dict. __doc__
The display should look like this:


"dict() -> new empty dictionaryndict(mapping) -> new dictionary initialized from a mapping object'sn (key, value) pairsndict(iterable) -> new dictionary initialized as if via:n d = {}n for k, v in iterable:n d[k] = vndict(**kwargs) -> new dictionary initialized with the name=value pairsn in the keyword argument list. For example: dict(one=1, two=2)"

Notice if there is an \n sign in the jumbled English, what is it? The escape symbol \ was mentioned earlier when we were talking about strings. This is a new line. That is, if the text above, according to the typesetting requirements, should be like this (of course, in the text, if opened, it actually looks like the layout).


"dict() -> new empty dictionary
dict(mapping) -> new dictionary initialized from a mapping object's
(key, value) pairs
dict(iterable) -> new dictionary initialized as if via:
d = {}
for k, v in iterable:
d[k] = v
dict(**kwargs) -> new dictionary initialized with the name=value pairs
in the keyword argument list. For example: dict(one=1, two=2)"

The layout may still not meet the desire. Still, the judge might be able to see. I'm not talking about typography, I'm talking about telling the reader that one way to see the meaning of a data type is through the obj.doc file.

Hey, there is actually a way to see the results of the layout:


>>> print dict.__doc__
dict() -> new empty dictionary
dict(mapping) -> new dictionary initialized from a mapping object's
    (key, value) pairs
dict(iterable) -> new dictionary initialized as if via:
    d = {}
    for k, v in iterable:
        d[k] = v
dict(**kwargs) -> new dictionary initialized with the name=value pairs
    in the keyword argument list.  For example:  dict(one=1, two=2)

Above so toss about, it is to make up the space, otherwise this summary of things too little.

In short, with this method, you can get all the help documents, anytime, anywhere. If you can access the Internet, to the official website, is another way.

Do I need to explain anything else? It's redundant. The only thing you need is a little English. But I believe that the officer can read, I this two knives are not as good as the English level, can also make do with it, let alone the officer?

Conclusion does not mean the end, it means the continuation of the past. Wonderful is still behind, here is just a rest.


Related articles: