There is a phrase that sums up the meaning of this code in a classic way:"Make a script both importable and executable"It means that the script module that you write can be imported into other modules, and the module can be executed by itself.This
1 Scope of variables Python is a static scope, meaning that in Python, the scope of a variable derives from its position in the code, and there may be different namespaces in different locations. Namespaces are the embodiment of variable scopes.2
1. DefinitionObjects copied using the prototype schema have the same structure and data as the original object, with shallow and deep clones2. Application Scenarios(1) The structure and data of the original object are expected to be copied to affect
1, because Python multi-threading suitable for multi-io operation, but not suitable for CPU computing work, this time can be achieved through a multi-process. Python multi-process simple and practical # multi-process, can be CPU consistent, Python
1. The Python class attribute cannot be changed by the objectThe instance object cannot change the class property if the object is strongly written. class Property = XXX Just adds an instance variable to the object, and the instance variable's name
Adorner: Essentially a function that adds additional functionality to other functionsPrinciple:1. Do not modify the source code of the modified function2. Do not modify the calling method of the modified functionKnowledge Reserve for
SysModule SYS gives you access to variables and functions that are closely related to the Python interpreter.
function/variable
Describe
Argv
command-line arguments, including the script name
1.try-except code blockTry Print (5/0)Except Zerodivisionerror: Print ("You can ' t divide by zero!")Exceptions are handled using the TRY-EXCEPT code block. The try-except code block lets python perform the specified action and tells Python
Crawler IntroductionCrawler: You can think of the Internet as a large network, reptiles are like the spider in the net, if you want to get the resources in this net, you can crawl it down.In short, it is the automated program that requests the site
Import OsFilePath = "/users/busensei/wzy/filepath/" def read (FilePath, n): it = Os.listdir (filePath) # Open Folder for El in it: # Get path fp = Os.path.join (FilePath, el) # Get to Absolute path if Os.path.isdir (FP):
Loops are used to repeatedly execute some blocks of the program. From the previous selection structure, we have seen how to use indentation to represent the membership of a program block. The loop will also use a similar notation.For LoopThe For
Try: Print("in Try")exceptKeyerror as E:#exception, the block is executed Print("exception in")Else: #The main code block (try) finishes executing the block Print("normal execution in try will come to else")finally: Print("finally in")
I. Dynamic parameter transfer1. Positional parameters Dynamic parameter transferdef func (*args): * Indicates dynamic parameter transfer* Here is the acceptance of the dynamic parameters of the positional parameter, the received tuple.def fun (*args)
Features of the Python language: generic, scripting, open source, cross-platform, multi-modelNumber Typeinteger: (with mathematical concepts) no value range limit4 Types of binary representations-Decimal: 1010, 99, 217-Binary, beginning with 0b or 0
First, the use of the package1. What is a packageA package is a folder that contains a __init__.py filePackage is the essence of a module, that is, the package is used for import, the package contains files are also used to be imported2. Why use the
1.global is called a keyword in python, not a commandThe role of 2.global is to refer to global variables to local scopes3. If there is not a variable A in the global variable and a statement such as Globa A is written in the function, then a
One, module, packageWhat is a module?The module is essentially a Python file, which is used to organize the code, meaning that the Python code is written inside, the filename is the name of the module, test.py test is the module name.What is a
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