Adorners are difficult to understand and write to people who are new to Python and who are familiar with Python. So share my understanding of the Python decorator today.
The so-called adorner is just a kind of grammatical sugar, can function object
Sometimes we have to go to other interfaces to fetch data, perhaps because the network reason occasionally fails, in order to be able to automatically retry, wrote such an adorner.This is the python2.7x version, python3.x can be rewritten with
Because a function is also an object, and a function object can be assigned to a variable, the function can also be called through a variable.
>>> def now ():
... print ' 2013-12-25 '
...
>>> f = Now
>>> f ()
2013-12-25
The function
function as the return value
In addition to accepting functions as arguments, higher-order functions can return functions as result values.
Let's implement a sum of variable parameters. In general, the function of summation is defined in this way:
List
One of the data types built into Python is the list: lists. A list is an ordered set of elements that you can add and delete at any time.
For example, if you list the names of all the students in your class, you can use a list to say:
Output
With Print plus a string, you can output the specified text to the screen. For example, the output ' Hello, world ', implemented in code as follows:
>>> print ' Hello, world '
The print statement can also be followed by
The first is to download the Python official website download can 2x series and 3x series Gap is very big, I choose is python3.6. Check the add path below as much as possible during installation so that you do not have to configure environment
Defining the Encoding Python would default to ASCII as standard encoding if no other encoding hints is given. To define a source code encoding, a magic comment must is placed into the source files either as first or second l Ine in
First, the basic concept:1. ModuleThere are two types of modules in Python, one is a standard module, Python comes with a module, and the other is a third-party module that needs to be downloaded via Easy_install or PIP.The first week of learning
No intention to see the old boy's blog: qualified Linux OPS personnel will be the 30-way shell programming surface questions and explanationshttp://oldboy.blog.51cto.com/2561410/1632876Try to use the first Python to answer some, right when practiced
Based on Python2.7get and post:url = "http://zzk.cnblogs.com" urllib.urlopen (URL)----->get method name = Urllib.urlencode ({"K": "B"}) Urllib.urlopen ( Url+name)----->pst methodThe method option for form forms in the developer tool is post, so you
Listing: ListTuples: TupleLists are common data types in Python and can be stored and modified by a list.Definition of the list:Name_list = [' Apple ', ' orange ', ' grape ', ' pear ', ' Barry ']You can access the elements in the list by subscript,
Today's learning Record:Functions, variablesExamples of functions:#函数返回def test1 (): Print ("in the Test1") return 0#return is empty, when not written, this function is a procedure, the default return is empty, that is, none; #return为一个对象时, return
Guibs's Python learning _if
# if# If you control whether the code block belongs to if# if conditional_test:# does somethingcars = [' Audi ', ' BMW ', ' Subaru ', ' Toyota ']for car in car S:if car = = ' BMW ': Print (Car.upper ()) Else:print
Dictionary: An associative array or hash list of objects that can be indexed by a keyword.
What a dictionary does: Define an object that can contain multiple named fields, or you can use it as a container to quickly find unordered data
Dictionaries
Generator yield: Using yield statements
You can let a function generate a result sequence, not just a value
def Countdow (n): print ("start!"); While n>0: yield n; n-= 1; c = Countdow (5); Print (c.__next__ ())
Module: As the program becomes more and more large for ease of maintenance you need to divide it into multiple files for this python allows you to put the definition into a file and import it as a module in another script
Create a module: Put
Combination mode
We look at the composite pattern as a complex attribute structure, in fact there are three kinds of characters: the trunk (which defines the operation of the Leaf leaf), the branches (which have many branches on the trunk) and the
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