My Python Tour - "Dive Into Python" Reading Notes (1)

xiaoxiao2021-03-05  28

Python has recently reddish big red, and decided to look at it under a friend's suggestion. This is also my first contact scripting language, and I am determined to look at it. Under the Python, install all the smooth, I also found a book "Dive Into Python", English version, not too wonderful, but even guessing, Golden Mountain words, also barely cope, make it. The first example 1: DEF BuildConnectionsTRING (params): 2: "" "Build a connection string from a dictionary of parameters.3: returns string." "4: Return"; "; JOIN (["% s =% S "% (k, v) fork, v in params.Items ()]) 5: if __name__ ==" __main __ ": 6: myparams = {" server ":" MPILGRIM ", / 7:" Database ": "Master", / 8: "UID": "SA", / 9: "PWD": "Secret" / 10:} 11: Print BuildConnectionstring (myparams) I mean by the author, I tried to understand. The first line is quite like a function, and it is estimated that it is a function. The 2, 3 lines should be a note. This is also a sentence with punctuation. I don't believe it is Python's statement :) The fourth line is a bit difficult Understand. Do you want to put a thing Join? (k, v) is like a two-dimensional array, its value comes from params.Items (), the front "% s =% s" should be a Join form, what does it mean? I don't understand, it is estimated and put down. On line 5, is a variable equal to a string? But the variable did not see the declaration? ? 6-10, I finally see the params of BuildConnectionstring, ":" The separated should be two dimensions of the two-dimensional array, what is "/" behind each line? I won't be wrong. Another trouble problem is that the functions and IF do not limit the role domain. Which sentence is it to end? What is the system to determine a role? Unlike the next step, continue. Next, it is easy to understand, it is easy to understand, but it is more interesting, comparing the data type of various languages ​​(probably the author wants to reflect Python through this comparison), static Type language, dynamic type language, strong type language, weak type language, comparison result is only

Python has both the convenience of dynamic type languages ​​such as VBScript, and has the security of Java strong type language. Very good, know why choose it? :) Document function. When you bring your comment to the run, although you still don't know what is much better, but how do you say a lot of reasons for choosing Python. IMPORT statement: Import a module. Start thinking how this program looks like a process, because I have not seen the familiar class declaration. But seeing 2.4, I started to understand anything, Every Thing is an Object! The module is also, even the function is also. So understanding the traditional way, this

The module should be as a class, when IMPORT (or other time?) Generates an object. Is there any other way to construct a class? Unclear, look at it later. Section 2.5, finally said the problem of the role domain. Actually relied on indential blank to limit the field, which means that there is the same indent statement that belongs to the same code block, which is equivalent to {}. It is indeed a very creative idea, but I don't feel my heart? Not too habit, huh. The benefits of doing this will be said. Think that it is true, such code blocks are partially forced you must make appropriate indentation, and the invisible helps the CODER specification code. Is there any way, don't do this, you can't get the right result. Section 2.6, about __name__ this built-in attribute. When it is imported as a module, its value is the file name where the module is located, but when you run the module, its value is "__main__", so that the test program becomes easier, the truth, the truth, the MAIN in the Java class is roughly it's the same.

转载请注明原文地址:https://www.9cbs.com/read-35809.html

New Post(0)