Python basic class daily finishing (vi)

Source: Internet
Author: User
Tags instance method

03_ Object-oriented _day03

  1. 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
  2. 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
  3. 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 ().
  4. 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
  5. 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="">
  6. Definition of a singleton pattern
    Only one instance
  7. 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
  8. 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
  9. Try except catch exception
  10. The role of else finally in the exception
    else is not an exception to execute
    Finally, whether or not an exception will be executed
  11. 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
  12. 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
  13. 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
  14. 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
  15. How files are opened
  16. 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.
  17. Common operations for files
    Rename renaming file os.rename (source file name, destination file name)
    Remove Delete file Os.remove (file name)
  18. 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)
  19. 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
  20. 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)

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.