I want to summarize Python data types and learn python data types.

Source: Internet
Author: User

I want to summarize Python data types and learn python data types.

The following table lists the learned data types, which are also part of the core data types of python. These are called built-in objects.

Object, that is, all the things you face are objects, and the readers should gradually get familiar with this title. All data types are an object. An English word is an object. It means an object directly in Chinese. It is like we are in reality. We can refer to a lot of what we see and use as "things. "Things" are "objects" and "objects. In programming, the so-called object-oriented can also be said to be "Object-Oriented", right? It is easy to be ambiguous.

Object Type 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 "}

Regardless of the data type, you only need to use dir (object) or help (obj) to view the relevant functions in interactive mode, that is, to view the relevant help documentation. Example:

Copy codeThe Code is as follows:
>>> Dir (dict)

You need to move the mouse to view the audience (the following is essentially a list ):

Copy codeThe Code is as follows:
['_ Class _', '_ cmp _', '_ ins INS _', '_ delattr __', '_ delitem _', '_ doc _', '_ eq _', '_ format _', '_ ge __', '_ getattribute _', '_ getitem _', '_ gt _', '_ hash _', '_ init __', '_ iter _', '_ le _', '_ len _', '_ lt _', '_ ne __', '_ new _', '_ reduce _', '_ performance_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']

Which of the following statements start with an underscore (_) is the built-in function of dict. For detailed operation methods, you can obtain them using the help (dict. pop) method. This is what we have said before. Let's talk about it again to deepen your impression.

My point is: learning, the most important thing is learning methods, rather than coding step by step.

Now that we are reviewing, we need to improve it on the basis of the past. Therefore, you should also look at the items that begin with double underscores (_ doc). Please refer to the official documents and see if you have found this: "_ doc ". What is this? It is a file that records a detailed explanation of the currently viewed object. You can view it in interactive mode as follows:

>>> Dict. _ doc __
The display should be like this:

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

Check whether \ n is in the messy English. What is this? As mentioned above, the escape character \ is used to change the line. That is to say, if the text above is based on typographical requirements, it should be like this (of course, in the text, if it is opened, it is actually a good layout ).

Copy codeThe Code is as follows:
"Dict ()-> new empty dictionary
Dict (mapping)-> new dictionary initialized from a mapping object's
(Key, value) pairs
Dict (iterable)-> new dictionary initialized as if:
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 not match the requirement. However, you can see it clearly. What I want to talk about is not a layout. I want to talk about the official website. I want to refer to the obj.doc file.

Hey, there is actually a way to see the typographical result:

Copy codeThe Code is as follows:
>>> 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:
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 above is a bit of effort to gather space, otherwise there will be too few things to summarize.

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

Do you need to explain anything else? Are redundant. The only thing you need is that you must be able to speak English. However, I believe that the readers can understand what they think. I am not as good at English as I can. What's more, what about the readers?

The conclusion does not mean the end, but the future. The highlights are still at the end. Here is just a rest.


How to Learn about Python

C ++, Java, and even C # can all be seen as the same type of language: C ++ is flexible, but complicated syntax makes production efficiency low, and Java improves production efficiency, however, flexibility is lost. C # is a good balance between production efficiency and flexibility, but it is still not enough. Otherwise, the father of Boo language will not be angry with Boo. Python is a dynamic type and a strong type language. A dynamic type means that you no longer need to make numerous declarations for the type of each variable, because the compiler will help you make type judgments, it will determine the type of the Variable Based on the Value assignment of the variable. A strong type means that you cannot use a string as an int unless you explicitly convert it. Python itself is compact, because space is ignored in C ++, Java, C #, and "{}" to define code blocks, if you like it, you can write all the code on one line, so you can write it as dizzy as possible. It is not possible, because there is only one Separator in it, namely the colon ":", and the code block is distinguished by indentation. Maybe you will be a bit unaccustomed to this method at the beginning, but later, you will find that this method will benefit you a lot, because you have developed a good code style. Don't think that Python is a very academic language, although many people think it is very suitable as an entry-level language for learning programming. In fact, Python is not only suitable for beginners to learn programming, but also a powerful language. You can use it to do anything other languages can do. Python itself is almost everywhere, and programs written in Python can run in various mainstream operating systems, even Palm. Oh, I almost forgot. Eric Raymond also told us that hackers must master four languages. The first step is Python ., Of course, if you cannot leave. NET in a day, you should start learning Python from IronPython. Compared with C ++, Java, and even C #, is it much faster to write and execute this classic program in Python? Haha ~~~ If I make up my mind to say that Python is highly productive, you will already scold me for being a lie. Okay. Let's try some practical code. But before that, you have to download two very famous class libraries: wxPython and Twisted. Is the download and Installation complete? Let's start our tour of EnjoyPythonwith you in ten minutes. FromwxPython. wximportwxPySimpleApp, wxFrameapp = wxPySimpleApp () frame = wxFrame (None,-1, "HelloWorld ")

What is the use of "class" in python? Why use a class?

To put it simply, a class is a kind of high-level abstraction. It is an advanced data type, a blueprint for an object, and a blueprint for defining the attributes and behaviors of the object you want to use, why do you want to use classes? You can compare them with those without classes. For example, if you compare them with structured programming, what are the advantages of classes? The summary is encapsulation, inheritance, and polymorphism, the more advanced and abstract you need to understand, the closer you are to people's thinking, the easier you can understand and use.

Related Article

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.