The decorator can add some extra functions before and after the target function execution without modifying the target function code.For example, there is a simple functionImport timeDef func1 (): Print ("This is a simple function") Time.sleep
Example from the third edition of the basic Python tutorial, 57pThis example uses a dictionary to implement a small database that retrieves the user's information by querying the dictionary's key values.I have modified some of the
Python string built-in functionsPython's string commonly built-in functions are as follows:
Serial Number
Method and Description
1
Capitalize ()Converts the first character of a string to uppercase
1, the role of global keywordsIf you need to modify global variables in a function, you need to use that keyword, see the example below.variable=100def function ():print# does not modify global variables within the function, direct access is no
Exit the Double loop:Way 1:try--excepttry: for i in range(5): for j in range(5): if i==3 and j ==3: raiseexcept: print(1)passMode 2: Return of function implementationdef fun(): for i in range(5): for
1. determine whether a variable is legitimate: (a variable consists of a letter, a numeric underline; and the beginning is not a number)While True:s = raw_input ("Please input values:")If s== "Exit":Print "Welcome use nexttime!"BreakIf S[0].isalpha (
1. Get the current execution main script method: Sys.argv[0] and _ file _(1) SYS.ARGVA list of instruction parameters to be passed to the Python script. Sys.argv[0] is the name of the script. Generally get a relative path, with Os.path.abspath
Today the author for everyone to prepare the recent super-fire python ai full set of video tutorials, hoping to engage in artificial intelligence of the small partners, to provide some help, so as to save more time to focus on learning, to provide
ObjectiveSome time ago, the data range of the colleague is too large, not so much (only need a township, the results brought to the county), too much load is also a problem. So let me deal with it.Due to the large number of files, manual cropping, I
Routines: using except and adding exception types
# -*- coding: UTF-8 -*- try: fh = open("a.txt",‘w‘) fh.write("This is a file for Exception test!")except IOError: print "Error, file not found
First, object-oriented introductionBefore you introduce object orientation, let's review the process-oriented programming thought that we learned before.Process-oriented Programming:The core is the process of the word, the process refers to the
Paste the progress bar of the single-line refresh implementation first:For a single-row refresh of the console, it is relatively straightforward to post the code directly:1Strarrs = ['/','|','\\']2 forIinchRange (15):3Sys.stdout.write (strarrs[i% 3]
(str).Find(Str, Beg = 0 , end Span class= "pun" >= len ( string )
STR--Specifies the retrieved string
Beg--Start index, default is 0.
End--ends the index, which defaults to the length of the string.
Detects if
List Builder# Common is the range () to create a list of numbers >>>[x*x for x in range (10)][0, 1, 4, 9, 16, 25, 36, 49, 64, 81]# back can also be added with a judgment statement >>>[ X*x for x in range (ten) if x%2 = = 0][0, 4, 16, 36, 64]#
There are two ways to format a Python string: a percent-semicolon, format-modeThe percent of the semicolon is relatively old, and format is a more advanced way to replace the old way, the two coexist. [PEP-3101]This PEP proposes a new system for
1. Describe the explanatory and compiled programming language?compile-language :
1, pre-compilation: The source code is written, before execution, the compiler will directly compile the source code into machine code, compile only once,
Read and Write XML in Python
(Original converted from http://zc0604.iteye.com/blog/1520703) converted from external
When using python for development, because Python's open-source ecosystem is very powerful, many class libraries are often
It is easy to use python as a scripting language, but it is not a day to learn how to write a very nice Python code, the purpose of this article is to recommend some excellent Python-related articles (for books, you can refer to dip, learning Python
Built-in modules (which can be used directly without import) Common built-in functions:
Python code
Help (OBJ) online help. obj is of any type.
Callable (OBJ) to check whether an OBJ can be called like a function
Repr (OBJ) to get the OBJ
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