Python class properties in a detailed

Source: Internet
Author: User
Tags class definition

in the python in development, we often use python class, today through the example and we grilled a class of properties, come together to see it.

Class properties

1. class definition is present and does not need to be instantiated

2. class attributes allow different instances of the same class to hold the same variable together

Class attribute Instance

attrb.py

Class Testcss:

CSSA = ' Class-attribe '

def __init__ (self):

SELF.A = 0

SELF.B = 10

def info (self):

Print (' A: ', self.a, ' b: ', self.b, ' Cssa: ', testcss.cssa)

def define_a (self):

SELF.C = 19

if __name__ = = ' __main__ ':

# TC = TESTCSS ()

# Tc.info ()

# tc.color = ' Red '

# Print (tc.color)

# TC = TESTCSS ()

# TCA = Testcss ()

# TC.A = 100

# TC.B = 200

# Tc.info ()

# Tca.info ()

# TC = TESTCSS ()

# tc.define_a ()

# Print (tc.c)

TC = TESTCSS ()

Tc.info ()

TCA = Testcss ()

Tc.info ()

Testcss.cssa = 0

Tc.info ()

Tca.info ()

The running result of the program Is:

Original Link:http://www.maiziedu.com/wiki/python/generic/

Python class properties in a detailed

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.