03_ Object-oriented _day03
- The concept of class properties and instance properties.
A class property is a property defined in a Class object (a class is a special object) and is typically used to record the characteristics associated with this class, and class properties are not used to record the characteristics of a specific object. The definition of a class property is outside of the initialization method
The properties of an instance object are called instance properties, defined inside the initialization method
- Access to class properties and instance properties
Access to class properties is the class name. Class Properties
Instance properties are accessed as instance objects. Property name, or you can use self within the class. Property name Access
- Class methods are defined and used br/> @classmethod
Pass
A decorator @classmethod is required to identify the first parameter must be CLS, which represents the current class object itself. The class name can be called by the class method ().
- The definition and use of static methods br/> neither need to access instance properties or invoke instance methods, nor need to access class properties or invoke class methods.
@staticmethod
Pass
It needs to be identified with a decorator @staticmethod, telling the interpreter that this is a static method
By the class name. static method () call
- The difference between a class method, a static method, and an instance method
A class method is a method defined for a class object that can directly access class properties or call other class methods inside a class method, use the @classmethod identity, pass a CLS parameter, and represent the class object itself. Br/> static methods do not require accessing instance properties or invoking instance methods, or accessing class properties or invoking class methods. Use the @staticmethod identity.
< li="">
- Definition of a singleton pattern
Only one instance
- The order in which the new and init methods are called
Executing the new method first returns a reference to the created object before the init method is executed
- Understanding the concept of exceptions
When the program runs, if the Python interpreter encounters an error, it stops the execution of the program and prompts some error messages, which is the exception
- Try except catch exception
- The role of else finally in the exception
else is not an exception to execute
Finally, whether or not an exception will be executed
- How to throw a custom exception (actively throwing an exception)
Creates an Exception object that throws an exception object using the Raise keyword
03_ Object-oriented _day04
- Module concepts, how to import modules
Each python source code file that ends with the extension py is a module, and the global variables, functions, and classes defined in the module are tools that are provided for direct use by the outside world, and the module is equivalent to a toolkit
There are two ways to import modules:
①import Module Name 1, module name 2
Import Module Name 1
Import Module Name 2
②from Module Import Tool/*
Alias the module using the AS keyword, the module alias using the Big Hump naming method
- Understanding the concept of packages
The package is a special directory with multiple modules, and there is a special file init. py in the directory.
Use the import package name to import all the modules in a package at once
- The concept of a file, open, read, write, close
A computer file is a piece of data stored on a long-term storage device.
Open opens the file and returns the file Action object
Read reads the contents of the file into memory
Write writes the specified content to a file
Close File
- How files are opened
- Read file contents by line
Use the ReadLine method to read one line at a time, after the method executes, the file pointer will be moved to the next line, ready to read again, suitable for reading large file content.
- Common operations for files
Rename renaming file os.rename (source file name, destination file name)
Remove Delete file Os.remove (file name)
- Common operations for Catalogs
Listdir Directory list os.listdir (directory name)
mkdir Creating a directory Os.mkdir (directory name)
RmDir Delete directory Os.rmdir (directory name)
GETCWD Get current directory OS.GETCWD ()
ChDir Modifying working directory Os.chdir (target directory)
Path.isdir to determine if it is a directory Os.path.isdir (directory path)
Path.isfile to determine if it is a directory os.path.isfile (file path)
- How to set the file encoding to UTF-8
python2.x default character set is ASCII encoded, Chinese is not supported, python3.x default character set is UTF-8 encoding - Coding:utf8 -Coding=utf8
- The role of the Eval function
Evaluates a string as a valid expression and returns the result of the calculation
Python basic class daily finishing (vi)