Study Notes Python 2

All of the following content from the translated versions of "python core programming (Second Edition)", is hereby declared

  1. dir ([obj]) show properties of the object, if the parameter is not provided, the name of the global variable display  help ([obj]) of the display object in a neat appearance in the form of documentation string, if no parameter will enter the interactive help.
    int (obj) converts an integer to an object
    the object returned len (obj) length
    open (fn, mode) to mode ( 'r' = read, 'w' = write) opened, fn one document named
    range ( [[start,] stop [,returns a list of integers. Start value for the start, end is stop - 1; start
    default value of 0, step a default value.
    the raw_input (str) waits for the user to enter a string, it may be provided as an optional parameter message str.
    str (obj) Converts a string object
    type (obj) Returns the type of the object (the return value is a type object itself!)
  2. # Variable values exchanged
    >>> X, Y =. 1, 2
    >>> X, Y = Y, X
    >>> X
    2
    >>> Y
    . 1
  3. CORE NOTE: __ name__ indication of how the modules should be loaded
    because the main process code module is whether it is imported or to be performed will be run directly, we must know how to determine the direction of the module. An application process may need to import one module to another application process in order to reuse some useful code (otherwise, they can use the copy and paste foolish non-object-oriented means). In this case, you just want access code is in the process of those other applications, but do not want to run that application process. So a question arises, "Python Is there a way to detect the module is imported or directly execute it at run time?" The answer is ...... (thunderous drums) ..... Yes! __name__ system variable is the correct answer.
    If the module is introduced, __name__ value is the module name
    if the module is executed directly, __name__ value '__main__'
  4. This is just Tucao about, after seeing the following sentence reminds me of a pseudo-god on a big lesson after the university want to install B did not install know, killing me "Most compiled languages, variables before use you must declare which of the C language more demanding: variable declaration must be in the block beginning, and before any other statements. "
  5. Note any trace or debug a process would add an additional reference objects, which will delay the time the object is recovered.

Original: Big Box  Python study notes 2


Guess you like

Origin www.cnblogs.com/petewell/p/11422053.html