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)