The role of __name__ = ' __main__ ' in Python

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

The LEGB rule of python--scope

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

Python design mode sixth day "prototype mode"

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

Python Multi-process explanation

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

Python Basics Summary

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

Python-based decorator

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

Python knows how to crawl hot Topic data

Import requestsFrom pyquery import Pyquery as PQurl = ' Https://www.zhihu.com/explore 'headers = {' User-agent ':"Mozilla/5.0 (Windows NT 10.0; Win64; x64) applewebkit/537.36 (khtml, like Gecko) chrome/67.0.3396.99 safari/537.36 "}# to allow Web

Python and Module--01sys

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

Python Base---exception

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

Python implements a simple KNN algorithm

fromNumPyImport*ImportoperatordefCreateDataSet (): Group= Array ([[[3,104],[2,100],[1,81],[101,10],[99,5],[98,2]]) labels= ['Love movies','Love movies','Love movies','action movie','action movie','action movie'] returnGroup, Labelsdefclassify0

Basic operations for Python lists

1. Create a list >>list1 = [' Apple ', ' banana ', ' parple ', ' pear ', ' apple '] 2. Copy operation >> list2=list1.copy ()>> List2[' Apple ', ' banana ', ' parple ', ' pear ', ' apple '] 3. Append operation >>

The Crawler Foundation for Python development

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

Python Recursive Implementation Traversal directory

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):

Python base 06 Loop

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

Python Trivia Point (10)--Exception structure record

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")

Python dynamic parameters, namespaces and scopes, nesting of functions, global and nonlocal

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)

python-Grammar Basics (1) numeric types and operations

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

Python Learning---8.10-pack usage and Loggin module

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

Python References global variables

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

Python Common Modules

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

Total Pages: 4013 1 .... 2279 2280 2281 2282 2283 .... 4013 Go to: GO

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.