Process oriented
Command-centric, with instructions to process data
How to organize code to solve problems
Object oriented
Data-centric, all processing code is expanded around the data
How to design the data structure and provide
Tuple tuple: ()
List: []
Dictionary: Dictionary: {}
Function:
Core Data types:
Numbers: Int,long,float,bool
Character: Str
Listing: List
Dictionary: Dict
Tuples: Tuple
Files: File
Other types: Collection (SET)
--------------------------------------------------------------------------------------------------------------- --------
Class: The expression that abstracts the common characteristics of the same particular transaction
States and transforms these operations
Data
Variable: is the property of the class
Method:
Functions: Code that manipulate the data referenced by a variable
Three principles for object-oriented programming:
Encapsulation, inheritance, polymorphism
__varname__ ():p Ython automatic Call
--------------------------------------------------------------------------------------------------------------- --------
Review: Restudying
1. Python Basics
2. Python Basic data type
Int
Str
List
Tuple
Dict
Set
3. Function-Type programming
4, the decorative device
@ Adorner Function name
def func ():
Pass
1, the Func as singular to the adorner function, and execute
2. Re-assign function return value of adorner function to Func
--------------------------------------------------------------------------------------------------------------- --------
Second, the decoration device
1, single-layer decorative device
2, double-decked decorative device
Third, the module:
Built-in Modules
__doc__
__package__
__name__
Common __file__
Sys
Sys.path: Path to the search module
Os
HASHLIB:MD5 encryption
Custom Modules
Third-party modules
1, serialization of related modules:
JSON: Suitable for cross-language, string, basic data types
Pickle: Serialization of all types, just for Python
Import JSON:
Json.dumps () Turns the base data type out into a string
Json.loads () Converts a string into a basic data type!! When deserializing, be sure to use double quotation marks ""
Json.dump () writes the converted string to the file
Json.load () Place a string into a list
Import Pickle
2, Processing module:
Import time
Four, string formatting
%s
$d
V. Generators and iterators
Vi. Other
Recursive
Bubble sort
Vii. Reflection: Manipulating its members in a string-based form object (module)
Getattr,delattr,setattr,hasattr
!! Reflection: No learning!!
Eight, the regular expression:
^: match at start position
.: Any character
*: represents 0 to several times
+:1 to multiple times
?: 0 to 1 times
{}:
Nine, XML:
The string returned by the browser
1. HTML
2. JSON
3. XML
Make a presentation on the page (string type an XML format file)
Configuration file (file you, internal data XML format)
X. Object-oriented (top)
Python-oriented process + object oriented
Object-Oriented: Class, Object
1. Classes and objects
(1), Create a class:
Class name
def method Name (SELF,XX)
Pass
(2), creating objects
Object = Class name ()
(3), through the object execution method
Object. Method Name ()
2.
Function Type:
def fetch (HOST,USERNAME,PASSWD,SQL):
Pass
DEF create ():
Pass
def remove ():
Pass
def modify ():
Pass
3.
Object-oriented:
Class Sqlhtlper:
def remove ():
Pass
def modify ():
Pass
DEF create ():
Pass
When does ===========> use object-oriented? When some functions have the same parameters, you can use an object-oriented approach to encapsulate the parameter values to the object at once, and later to take values.
Example:
Class SQLhelper:
def fetch (SELF,SQL):
Pass
DEF create (Self,sql):
Pass
def remove (Self,sql):
Pass
def modify (Self,sql):
Pass
obj = SQLhelper ()
Obj.hhost = ' 192.168.xxx '
Obj.username = ' Alex '
obj.modify = ' 1233 '
obj.pwd = ' JDJFJ '
4. What is self? Which object executes the method, and who is self.
5. Construction Method:
There is a special method in the class __init__, the class is executed automatically in the ()
6, object-oriented three major features:
Encapsulation, inheritance, polymorphism (multiple forms, multiple types)
7. Object-oriented class members
Field
Static fields (using Class access)
Normal fields (using object access)
PS: Static fields are created when the code is loaded
Method
The method used belongs to the class
Normal method, there is an object call execution (method belongs to class) at least one self
Static methods, called by the class to execute (object execution)
Class method,: With at least one CLS, class execution (object execution)
Property
A nondescript thing.
A form of writing with a method, with a field access form
8, member Modifiers:
Private:
Only members of the class themselves can access
Total:
9, object-oriented other
-Ininstance: See if an object is an instance of a class
-issubclass
-Executes the parent class construction method
10. Single case mode of design mode (GOF design mode)
Single-Case mode:
Used to create a single instance
11. Abnormal capture:
Try
Except Exception as ex
12. Python Inherits:
python2.7:
Classic class: Do not inherit obj, a path to the black
New class: Inheriting obj
Python3:
All new Classes
Python Learning Notes