An OOP Like C + + and Java, Python also has an OOP design. Program: From the front to the back, a line, the machine can accept the order of the way, the way is probably "what you should do first, what the second should do, the advanced point of doing something if you encounter what to do, or how many times a thing to do, ..."
I. Object-oriented and physiognomy processesObject-oriented programming--object oriented programming, short for OOP, is a programming idea. OOP takes objects as the basic unit of a program, and an object contains functions for data and manipulating data.Process-oriented programming treats a computer program as a set of commands, which is the sequential execution of a set of functions. In order to simplify t
run time. __init__() Is the key point for creating these properties.>>> c.__dict__ # 此时实例c还没属性{}>>> c.__class__ # 实例化的类What are the similarities and differences between Python object-oriented and other languages?SimilarDifferences between "Java oop" and "Pythonic oop"?True TM's tongue, who English good can translate under.What is a constructor,__init__What does
From this Article At the beginning, I began to share some features of Python Oop, hoping to help you understand Python oop. In fact, Python OOP is different from other languages. Today I will talk about one aspect of private mecha
▲ Object-oriented programming OOP Object oriented programming. OOP takes objects as the basic unit of a program, and an object contains functions for data and manipulating data. Process-oriented programming treats a computer program as a set of commands, which is the sequential execution of a set of functions. In order to simplify the program design, the process will continue to cut the function into sub-fu
O bjectsSorts of program LanguagesMachine orintedMachine instructionsAssemblyProcedure orintedFollow steps and branch processingCObject orintedMulti-person, multi-departmental writingC + + Java Python
Everything in Python, object-oriented, very thorough.
Objects are encapsulated in data and operations
Objects are independent, but objects can interact with each other
At present,
The interview was asked a few times the python oop all hung up, decided to seriously learn it again ~ ~Python's object-oriented design differs from compiled languages such as C + +, with the following main notes:
The Python class does not have access to the problem, which means that all variables are accessible.In fact, P
Use Python to implement the book expiration reminder, and use python to implement the book expiration reminder
1. Simulate login to the Library Management System
Let's take a look at the login page (many schools have these management system pages that are very low ):
Two methods are used to simulate the login to the L
DFS steps are as follows: [d]-->[d,b]-->[d,b,a]-->[d,b,a,c]--> (the parent class of C is a, which already appears in front, remove the previous a)-->[d,b,c,a] Polymorphic (polymorphism): Simple to understand, different classes have the same method name (methods name), that is, there is the same interface, we can call the same method name in any instance of a class.But in fact, although these methods have the same name and are conceptually similar, internal operations are different.For example,
class on the fly A . The parent class is object (note that the multiple-inheritance parent class is placed inside tuple .) Suppose there is only one parent class, the tuple has only one element, and the comma is not limited. And there is a af method named.metaclassMeta class *
Class is equivalent to an instance of a meta class. Metaclass is the most difficult and difficult-to-use magic code for Python-oriented objects. Generally not used
Java, must specify a type when passing parameters, and Python does not have this limitation, which is one of the reasons why Python natively supports polymorphism.This paper mainly describes the three main characteristics of Python object-oriented, encapsulation, inheritance and polymorphism, inheritance has multiple inheritance, new inheritance and classical cl
type()function can either return the type of an object or create a new typeDEF fn (self, name= "World"): print ("Hello,%s!"% name) Hello = Type ("Hello", (object,), Dict (hello= fn))
h = Hello () >>> H.hello () Hello, world!>>> type (h) out[165]: __main__. hello>>> Type (Hello) out[166]: type
To create a class object, the type() function passes through 3 parameters in turn:
The name of the class;
Inherited parent class Collection, note that
Original title: A Byte of PythonAuthor: Swaroop, C. H.Translator: Shen JieyuanPublisher: UnknownAdvantages1. The explanation is very detailed, very basic, is suitable for the introduction, has also made the simple introduction to the compiler2. The explanation of the __name__ attribute is more detailed, while the other books do not talk about this piece of knowledge3. There is the knowledge of class, inheritance, for me without Java Foundation, the explanation is very popular, but this
Python Book recommendation, python book
Python Book recommendation list:
Tip: Learn how to obtain the file name under the directory on the windows platform. (My python
Self.score = Score Vincent = Student (' Vincent ', +) Lisa = Stud ENT (' Lisa ', 80)Encapsulation of dataAnother important feature of object-oriented is the encapsulation of data. In the above instance of the Student class, each instance has its own name and score data. We can access this data through functions, such as print scores:def print_score (self): print ('%s:%s '% (Self.name,self.score))sinceStudentThe instance itself has this data, to access the data, there is no need to access from t
of the same name to become the cloud, but the ice. to Cloud (), and vapor. Cloud () is a very different process, although the methods are all the sameIntrospection/ReflectionIntrospection, also known as reflection, shows how an object obtains its own information at run time. If you pass an object to you, you can find out what it is capable of, which is a powerful feature. If Python does not support some form of introspection, the Dir and type built-i
() class method, class:__main__. Myclass,val1:value changed, cannot access the value of Val2 MYCLASS.CLASSMD () class method, class:__main__. Myclass,val1:value changed, unable to access the value of Val2Finally, the implementation and invocation of instance method, static method and class method are summarized.#!python2#-*-coding:utf-8-*-classMethods ():defim (SELF,V2): Self.v2=v2Print "Call instance method:%d"%v2 @staticmethoddefSM (v2):Print "Call static method:%d"%v2 @classmethoddefcm (CLS,
Python implements simplified address book modification and python address book modification
Description:
I wrote a simple address book in my previous blog, but I still think it is not perfect:
You need to enter the ID. Although the ID is the primary key, the auto-increment f
1-Problem descriptionGrab the watercress "new Book Express"[1] page book information (including title, author, profile, url) and redirect the results to a txt text file.
2-Thinking analysis [2]STEP1 reading HTMLSTEP2 XPath traversal elements and attributes
3-Using toolsPython,lxml module, requests module
4-Program Implementation1 #-*-coding:utf-8-*-2 fromlxmlImportHTML3 ImportRequests4 5
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.