Basic Python Tutorial (7)

Source: Internet
Author: User

More Abstract:

7.1 The Magic of the object: 1, polymorphic: You can use the same action for objects of different classes.

2. Encapsulation: Work details of hidden objects in the external world.

3, Inheritance: The General class as the basis for the establishment of specialized class objects

7.1.1 polymorphism: means that even if you don't know what type of object the variable refers to, you can manipulate it, and it behaves differently depending on the type of object (or Class). You can let users make method calls to objects that do not know what the class is.

7.1.2 Encapsulation: Hides excess information from other areas in the global scope. You can use it directly without worrying about how the object is created.

7.1.3 Inheritance:

7.2 Classes and types:

What exactly is the 7.2.1 class:

7.2.2 Create your own class: The class statement creates its own namespace where the function is defined. Self is a reference to the object itself, without which the member method cannot access the object in which it operates on its attributes.

7.2.3 features, Functions, and methods:

Private: To make a method or feature private (inaccessible from outside), just precede its name with a double underline. In the internal definition of a class, all names beginning with an underscore are ' translated ' and preceded by a single underscore and a class name. If you do not need to use this method but want other objects to not access internal data, you can use a single underline.

7.2.4 class namespace: When defining a class, all code in the class statement executes the class namespace in a special namespace. This namespace can be accessed by all members within the class. The definition of a class is actually a block of code execution.

7.2.5 Specifies the superclass:

7.2.6 Investigation Inheritance: Built-in functions: Issubclass (C,B); isinstance (object,class); __class__

7.2. More than 7 superclass (multiple inheritance): If a method inherits from multiple superclass, the method in the first inherited class overrides the method in the inherited class.

7.2.8 interface and introspection:

Summary:

objects: Objects include attributes and methods. A method is a function stored inside an object. The difference between a (bound) method and other functions is that the method always takes the object as its first parameter, which is generally called self.

Class: A class represents a collection (or class of objects) of an object, and each object (instance) has a class. The primary task of a class is to define the method that it uses for its instances.

Polymorphism: You do not need to know which class the object belongs to to invoke the method.

Encapsulation: objects can hide their internal state.

Inheritance: A class can be a subclass of one or more classes. Subclasses inherit all methods from the superclass.

Interfaces and introspection:

Object-oriented design:

Basic Python Tutorial (7)

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.