Head first python cainiao Study Notes (Chapter 6), python Study Notes

Source: Internet
Author: User

Head first python cainiao Study Notes (Chapter 6), python Study Notes

1. Python provides a dictionary that allows you to effectively organize data and associate the data with the name to achieve quick search, rather than associate the data with numbers.

A dictionary is a built-in data structure that allows you to associate data with keys rather than numbers. In this way, the data in the memory is consistent with the actual data structure .???

 

2. Package the Code and its data into a class: Python allows you to create and define an object-oriented class, which can be used to associate the Code with the data processed by the Code. Code and the data it processes can be defined as a class. Once a class is defined, you can use it to instantiate a data object. It inherits the features of the class.

Where:

The Code is a class method.

Data is a class attribute

The instantiated data object is an instance.

 

3. Use class to define a class. The method is as follows:

 

 

All methods defined in the class must use self as its first function:

 

 

ImportantPythonExecuted code .!!!!!!

 

 

4. Extended built-in classes to add custom attributes

How to inherit python's built-in list class.

First, derive the built-in list class to create a custom list

 

 

Summary:

1. Use the dict () factory function or {} to create an empty dictionary.

2.

3. Define the _ init _ () method to initialize the object instance. Each method in the class must provide self as the first parameter. Each attribute in the class must have self before it, so that the data is connected to the instance.

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.