Python Basics-Class

Source: Internet
Author: User

notes:
Object Oriented Introduction

All things in the world can be classified
All things in the world are objects
as long as the object, it must belong to a certain category
as long as the object, there must be attributes
attribute class, Object
Package
Inheritance
# python3.0 Version Breadth First (classic class, Modern Class) D-b,c-a
# python2.0 Version Classic class depth first d-b-a,d-c-a
# New class breadth First
polymorphic
one interface, multiple implementations (interface reuse)

syntax properties, methods,
Constructor _init_
destructors are automatically executed when an instance is disposed, destroyed, and often used to do some finishing work, such as closing some database connections, opening some temporary files _del_
private methods, private properties
instantiation: The process of turning a class into a concrete object
class variables, instance variables
use of class variables: Common attributes, saving overhead (memory)
static method:
Only nominal collation management, in fact, in a static method cannot access any of the properties of the class or instance
Class method:
Only class variables can be accessed and instance variables cannot be accessed
Property Method:
Turn a method into a static property


To illustrate:
1 classDog:2     def __init__(self,name):3Self.name=name4 5     defBulk (self):6         Print("%s: Wang Bark!!!"%self.name)7D1=dog ("Golden Three Fat")8D2=dog ("Wang")9D3=dog ("Lao Wang")Ten  One D1.bulk () A D2.bulk () -D3.bulk ()

Python Basics-Class

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.