Python has been used for some time now, so here are some tips and tricks you can use in Python to share the following.1.lambda use.The lambda function, which is an anonymous function , creates the syntax:Lambda parameters:expressExamples are as
1. Definition of functionDefinition: A function is a collection of a set of statements by a name (function name) encapsulated, in order to execute this function, just call its function name. The characteristics are as follows:
Reduce
Map () and reduce () in PythonPython has the map () and reduce () functions built into it.Map ()The map () function receives two parameters, one is a function, the other is a sequence, and map passes the incoming function to each element of the
In Python, there are single-line comments, multiline comments, special annotationsSpecial NOTES:#!/usr/bin/env pythonThis annotation means: Python tells Linux which path to search for Python's translator#-*-coding:utf-8-*-This annotation means: Tell
List: Lists1) List expression: Sometimes it is convenient to replace the function to implement some functions1.1) Center string (9 characters long) >>> a = ["123", "456", "ABC", "abc", "AAA"]>>> [K.center (9) for K in a][' 123 ', ' 4 ", ' abc ', '
Python Common File Operations Summary: fromrandom Import Shuffle determine if the folder is valid:ifNot Os.path.isdir (targetDir): Print'Invalid target directory: {}'. Format (targetDir) sys.exit (2) to determine if a folder exists:ifnot
########## #使用线程完成多任务 ################ from Import Thread Import Time # 1. If multiple threads are executing the same function, they will not affect each other, each of which is a def Test (): print(" ----drank too much last night and drank
1. Slicing operations 1.1 slicing a list or tuple 1.1.1 using the range functionl=[0,1,2,3,4,5,6,7,8,9]R=[]# range function, does not contain the number of terminationsFor I in range (2,5):R.append (L[i])1.1.2 Using the slice operatorL[0:3],
Recently in order to implement automated test case failed to automatically retry after the study for two or three days to fail, and finally found on the Internet a great God rewrite the Run method in Suite said can be implemented, but not very
One, variable
Variable naming rules
Variable names can only be any combination of letters, numbers, or underscores
The first character of a variable name cannot be a number
The following keywords cannot be
5. FunctionsThe Python function code block starts with the DEF keyword; The function contents begin with a colon and are indented. * Note: python, strings, tuples, and numbers are objects that cannot be changed, while list,dict are objects that can
' 1.int 2.str 3. Meta-zu tuple Tu = (' name ') TU1 = (' name ',) Print (Tu,type (TU)) Print (Tu1,type (TU1)) 4. List When you loop through a list, if you delete some or some elements in the loop, the number of elements in the list changes,
CollectionA collection is an unordered, non-repeating collection of data in which the elements are hashed (immutable types), but the collection itself is not hashed (so the collection cannot be a key to the dictionary). The following are the two
Syntax for exception:Types of exceptions:
nameerror
Try to access an undeclared variable, such as I did not define the variable a and then I go to access this variable and the exception appears
Used to install the Python plugin with PIP until todayThe PIP principle is actually downloaded from the official Python source Pypi.python.org/pypi to the local, then unpacking the installationBut sometimes, this operation will be very slow, the
In the Ubuntu 14.04 system, for example, the Python and Python3 installed are 2.7.6 and 3.4.3, but some projects require a specific Python version. The current system default Python is already closely coupled with the system, you can not arbitrarily
1 direct command line enable Python. Of course, if you enter Python directly in cmd, you are likely to get an error. Resolution: 1. Enter the absolute path to the Python.exe by CD in cmd mode; 2. Set in the PATH environment variable in Windows,
Python logging module and pythonlogging ModulePython logging Module 1. Simply print logs to the screen
ImportLogging
Logging. debug ('This is debug message')
Logging.info ('This is info message')
Logging. warning ('This is warning message')
The
The general difference between the Process and the thread in Python, and the overall situation of pythonNum01-> thread
A thread is the smallest unit in the operating system that can perform operation scheduling. It is included in the process and is
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