Classes for Python

Source: Internet
Author: User

Class Dog ():

def _init_ (self, Name, age):

Self.name = Name

Self.age=age

def sit (self):

Print (Self.name.title () + "is now sitting")

def roll_over (self):

Print (Self.name.title () + "rolled over!")

The Python class has the default initial capitalization, such as the Dog class, and the lowercase name represents the created instance.

Inherited:

Class Smalldog (Dog)

def _init_ (self, name,age):

Super (). _init_ (name,age) The Super function is a special function that associates a subclass with a parent class, meaning calling the Init method of the parent class, inheriting the parent class property.

python2.7 inherited by Super (Smalldog,self_init_ (Name,age)

From car import car imports car class from module car

Import Car Imports Car module

Classes for Python

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.