Review what you learned last week and how time is transformed

Source: Internet
Author: User

Object-oriented:
Object: Everything is an object. An object in which a feature, action, or function is put together.
How the object was created. In Python, objects are created through classes. A class is a description of an object. Collectively, constraints.
Class Car:
Def fly (self):
Pass

The relationship of a class to an object:
A class is a type, a category. A description of the thing
The object is an individual. A specific object or thing.

To create an object:
Instantiation of the class name ().

Three major features:
1. Encapsulation. Encapsulates a data or method in a class.
2. Inheritance. Subclasses can automatically be useful for everything except private content in the parent class. Includes an abstract approach
3. Polymorphism. Python native is polymorphic. The same object, a variety of forms.


Members:
1. Variables
Instance variable. object to have something.
Class variable. Class has. Multiple object sharing. It's better to have a class name to access the class variable
2. Methods
1. Example Method Def method (self):p
Self: The object that is currently calling this method.
2. Static methods are best accessed by the class name
@staticmethod
Def method ():
3. Class methods are best accessed by class names
@classmethod
Def method (CLS):
3. Properties
To describe property information in a method

@property
def age (self):
return 18
The relationship between classes and classes:
1. The relationship between dependency classes and classes is the weakest
Passing objects of other classes in the parameters of a method

2. Association relationship. Combination. The aggregation relationship is very close.
Put an object on yourself

Class Phone:
def __init__ (self, person):
Self.owner = person
Self.user = user

Class Person:
Pass

Class User:
Pass

3. Inheriting relationships, implementing relationships
Class Subclass (Parent Class):
Pass
Parent class: base class. Super class
Subclass: Derived class.

To implement a relationship:
Parent class: abstract class. If all are abstract methods. The parent class is called: interface
Subclass: The abstract method in the parent class must be overridden.
Constraints:
The parent class's constraints on the child class. What the subclass must override
1. Throw exception Raise Notimplementerror
2. Abstract class
From ABC import Abcmeta, Abstractmethod
The meta-class must be set to Abcmeta. Metaclass = Abcmeta
In this class, you can write abstract methods. @abstractmethod
The class contains abstract methods. Then this class is an abstract class. Abstract classes do not typically create objects

Mro:
1. Classic Class
The use of depth-first traversal
2. New class
If there is no diamond inheritance. is the depth-first traversal.
If it is a simple diamond inheritance. Kill your head. Use depth first. And finally the head.
If it is a complex diamond, you need to use the C3 algorithm
Find the inheritance relationship for each class. Then split. Split to the end. and then merge.

Written questions. The first piece of the drawing. See if there is a diamond. and then count.
Super
Perform methods in the next class in the MRO list
Super (). Method ()
Super (class name, self). Method ()

Reflection
Hasattr (obj, str)
GetAttr (obj, str)
SetAttr (obj, str, value)
Delattr (obj, str)

Issubclass, type, isinstance
Issubclass: Judging whether it is a subclass of XXX
Type: The exact object of which class the object is given
Isinstance: Determine if XXX is of type XXX.

Methods and functions
Functiontype, Methodtype

Exception handling:
Throw exception: Raise Exception ()
Catching Exceptions:
Try
Xxxx
Except Exception as E:
Xxxx
Else

Finally

Stack information:
Import Traceback
With the logging.

Custom exception: Inherit exception



# 18888888888 time stamp, format time
# turn timestamps into structured time
# f = 18888888888
# st = Time.localtime (f)
# Print (ST)
# # Formatting the structure of time
# t = time.strftime ("%y/%m/%d%h:%m:%s", st) # F:format formatting
# print (t)

# User entered a time 2018-09-08 11:22:36 -store timestamp
# Convert formatted time to structured time first
# s = "2018-09-08 11:22:36"
# st = Time.strptime (S, "%y-%m-%d%h:%m:%s") # P:parse Conversion
# t = time.mktime (ST) # converted to timestamp 1536376956
# print (t)

Review what you learned last week and how time is transformed

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.