I. Object-oriented programming (OOP)program = algorithm + data structure = instruction + statistics1. The code can choose to write at the command or at the core of the dataTwo types of paradigms:command-centric: writing around "What's going On"process-Oriented programming: The program has a series of linear steps; The main idea is that code is used for datadata-centric: Writing around "Who's going to be affected"O
Property: is a data or function element that belongs to an objectClasses have class methods, instance methods, static methods, class data properties (class variables), and instance data properties (instance variables).Class properties: Include class methods and
First, instance propertiesPython is a dynamic language, and an instance created from a class can be arbitrarily bound to a property.1>>>classStudent (object):2...def __init__(self, name):3... Self.name =Name # Properties required for each instance4 ... 5>>> s = Student ('Jack')6>>> S.score = 90 # Arbitrary binding properties7>>>S.name8 'Jack'9>>>S.scoreTen90Second, clas
The method of defining a class in Python is simple, using the keyword class, which can contain functions with Def#!/usr/bin/envpython#-*-coding:utf-8-*-classtest_n: "" " classgetanameandcountstringornumber "" " def__init__ (self,n): self.name= ndefsqrt_num (SELF,NBSP;CN): ifcn>=0: root=cn**0.5 return-root,rootelse: print "Negativenumber." returndef c_str (SELF,NB
#-*-Coding:utf-8-*-#__author__ = ' Administrator '#一般使用2种方法来解决这个问题isinstance basestring to simply and quickly check the type of a stringdef isstring (obj):Print Isinstance (obj,basestring)It is normal for #如果你第一个想到 (novice) to use Type (obj), but in the case of a veteran, using type (obj) is bad#basestring是str与unicode类型的基类#如果想支持字符串操作, you can use the following methodsdef islinstring (s): #一般 (in most cases) to meet the requirementsTryS+ "Except:return FalseElse:return TruePython Cookbook Learnin
Three classes that look at objects, or the features that objects have:A. The Pycharm IDE is viewed through the type method:Example:temp = "Alex"Print (Type (temp))Returns the result str, in the edit window input str, click CTRL + LEFT mouse button, locate the Str class inside there are all methodsB. Dir () method view:Example:temp = "Alex"Print (dir (Alex))C. Help () method view:Example:temp = "Alex"Print (Help (type temp))Type description:__xxx__ as
First, Abstractmethod
Subclasses must all implement the Abstractmethod method of overriding the parent class
Non-Abstractmethod methods can be overridden without implementation
A class with a Abstractmethod method cannot be instantiated
From ABC import Abstractmethod, Abcmeta1 classBettingstrategy (metaclass=Abcmeta):2 3 @abstractmethod4 defbet (self):5 Print('0')6 7
1.final keywordsAs with the const keyword in. NET, it is the modifier of a constant, but final can also modify the class, method.Specification: Constant All letters are capitalized, the middle of multiple words with "_" connection.2. Iterating through the collectionarraylistList.add (1);List.add (3);List.add (5);List.add (7);Traverse List Method 1, using the normal for loop:for (int i = 0; i System.out.println (List.get (i));List.remove (i);//using th
automatically input d1.bulk () # Call the method print (d1)Why is there self:
The class variables and instance variables are used as explanations. common attributes are generally defined in the common part and do not require _ init __. for example, because everyone has their own names, the name should be private. In order to save resources, class functions are not copied to every
Java Tour (ix)--object class, Equals,tostring,getclass, inner class access rule, static inner class, Inner class principle, anonymous inner class
Every day by some trivial harassment, learning to continue
I.
1.mysql Package ClassDefine parameters for initializing database connections in a constructor "because the parameter passed in when instantiating an object is the only parameter entry for that object"But instead of redundant definitions in the constructor, it is possible to set up the constructor by invoking other methods in the constructor, such as "module separation makes logic simpler"Focus2. Static memb
returns the hashcode of the current object by default, the memory address.Summary: If an object ToString () method is not overridden, the ToString () method of its parent class object is called by default, and the ToString () method of object is to print the object's hashco
Object-Oriented Summary1. First, object-oriented programming uses objects as a processing object "such as inheritance, and so on, the nature of inheritance, is still targeted at the object"But only for class access, static members, and access modifier qualifiers, the concept
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.