Python Object-oriented development (i)

Source: Internet
Author: User

Read the medieval education about the Python Foundation for a while, the sense of grammar is very simple, a little bit lazy has not hit the code. Today finally take care of those who look like brick home customers, spare half an hour to write a Python object-oriented demo to find the feeling. Gossip Less code:

File name: personmodel.py

class Person (object): "", "" "," "" "," "__name=" "__age=0def __init__ (Self, **arg): Super (person, self). __init__ () Self.__name = arg.get (' name ') self.__age=arg.get (' age ') def showmessage (self):p rint (' Name: ', self.__name) print (' Age: ', Self.__age)

Main file: demoisrunning.py

#!f:\python\pythonimport personmodelt={' name ': ' Willa ', ' age ':, ' sex ': ' Female '}p=personmodel.person (**t) P.showmessage ()

The effect is as follows:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/4D/F1/wKioL1RckTLQBCsOAABaDRT80eM199.jpg "title=" Snap1.png "alt=" Wkiol1rcktlqbcsoaabadrt80em199.jpg "/>


The above example is primarily to verify object-oriented creation, file invocation. To be closer to the actual development, the above example is the following upgrade. The following directory structure has been modified, demoisrunning.py and personmodel.py in different directories, with the following modified file directories:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/4D/F1/wKioL1Rck5KhyIyaAAImunR8QBI563.jpg "title=" Snap2.png "alt=" Wkiol1rck5khyiyaaaimunr8qbi563.jpg "/>




Main file: demoisrunning.py modified as follows:

#!f:\python\pythonimport model.personmodelt={' name ': ' Willa ', ' age ':, ' sex ': ' Female '}p=model.personmodel.person ( **t) P.showmessage ()

The effect is as above, children's shoes with these questions please consultation fee.

This article is from "The growth of Luo shan black tea" blog, please be sure to keep this source http://85608547.blog.51cto.com/2093443/1574154

Python Object-oriented development (i)

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.