/tuple/string and an initial value, and the return value is numeric.#Coding=utf-8" "Created on 2016-12-14@author:jennifer Project: Usage of filter, map, reduce, lambda in Python" "#1.LAMBDA usage, before the colon is the argument, after the colon is the expression, the return value, the simplest functionPrint[(LambdaX:X*X) (x) forXinchRange (11)]#results: [0, 1,
example, you can use to sum a list:defAdd (x, y):returnX +yPrintReduce (Add, range (1, 11)) Note:1+2+3+4+5+6+7+8+9+10reduce (Add, range (1, 11), 20) Note:1+2+3+4+5+6+7+8+9+10+20 iv.Lambda This is Python support an interesting syntax that allows you to quickly define a single line of the smallest function, similar to the C language of the macro, these functions,
,,,,,,,,,, isatty peek raw readinto readline readlines seek seekable tell writable write and writelines . To see the full list, you can BufferedReader run it on the object dir() .Back to top of pageConclusionWill the Python community pick up? Version 3 is still in the people's guess. Breaking backward compatibility means that two versions will be supported. Some project developers may not want to migrate th
expressions (two arguments can be followed, only one line)1 Lambda A, b:a + B + 100Four function I return valueIf return does not specify a value, it is none.1 def F1 (): 2 Print (123) 3 return ' 111 ' 4 # in the function, once the return is executed, the function execution process terminates immediately, and the following print will no longer execute 5 Print (456)II parameters1 General par
. The main points are as follows:
(1) define functions using def keywords, function names, Parentheses, parameters (optional), and colons in Python (remember to indent the function body ), A function can have 0, 1, or multiple return values;(2) A Python-defined function does not need or cannot specify the parameter type. It is inherently generic;(3)
Python 2 library to Python X? There is no taste, but it is sad because it is interesting that makes Python today.
Unfortunately, Python 2 is not recommended, and Python 3 is rarely used. Pyth
), and a colon (to remember that the function body is indented), and the function can have 0, 1, or more return values;(2) Python-defined functions do not need (and cannot) specify parameter types, which are inherently generic;(3) Python supports (single or simultaneous use) common parameters, keyword parameters, tuple parameters and dictionary parameters four ty
Python function Programming Guide (3): iterator details, python programming guide
3. iterator
3.1. Iterator Overview
An iterator is a way to access elements in a set. The iterator object is accessed from the first element of the set until all elements are accessed.
The iterator cannot be rolled back and can only be ite
]: Default Start_index and End_index that represent the value of a rule that the entire sequence is divisible by the step in the index
you can do slices with negative numbers. Negative numbers are used at positions beginning at the end of the sequence
S[::-1] can be considered a rollover effect
3, two-dimensional ndarray slices in numpy
For the specific use of one-dimensional data and similar in Python
For
Developed with the old boy's education in Python [Article 3]: Python functions, old boy python
Set
Unordered, non-repeated, nested.Function
Create a function:
1. def Keyword: Create a function
2. Function Name
3 ,()
4. Function body
5. return valuesDefault return val
This blog collects the pits encountered from Python 2 to Python 3 due to different writing. Gives a written notation that Python 2 and Python 3 are compatible. 1. How to be compatible with raw_input () and input ()
Python BASICS (3) and python BasicsMy life is short. I want to learn Pyhton.
Python is an object-oriented, interpreted computer programming language, invented by Guido van rosum at the end of 1989, the first Public release was released on July 15, 1991. The Python source co
variable, which is actually a variable pointing to the function. A variable can point to a function, and the argument of a function can accept a variable. Then a function can receive another function as a parameter, which is called the higher order function. If you point a python built-in function name to another object, you cannot call the function through the variable name and error. The sample code is as follows: >>> ABS ( -10)10>>> abs in functio
, which is actually a variable pointing to the function.A variable can point to a function, and the argument of a function can accept a variable. Then a function can receive another function as a parameter, which is called the higher order function.If you point a python built-in function name to another object, you cannot call the function through the variable name and error. The sample code is as follows:>>> ABS ( -10)10>>> abs in function abs>>>> f
example of the maximum value:f = (Lambda x,y:x if x>y else y) print (f (2,3)) print (f (6,4))But the above example doesn't usually have to be written like this. This is not normally used because anonymous functions are used in conjunction with other functions, such as reduce, filter.A = filter (lambda x:x>3,[1,2,3,4,5,6,7,8,9]) # filter elements in list by
Python basic 3 file functions,
Today, I will review the previous knowledge about file operations. The operations on files mainly consist of the following parts:
I. Basic file knowledge
1. Basic File Operations
File operations can be divided into three parts:
1. open the file, get the file handle, and assign a variable
2. Read and Write files using a handle
3. clo
sequence[x1, x2, x3, ...], This function must receive two parameters,reduceCalculates the result continuation and the next element of the sequence. The result is:
Reduce (f, [x1, x2, x3, x4]) = f (x1, x2), x3), x4 ). However, you must useFrom functools import reduce import
A function that converts a string to an integer.From functools import performancedigits = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5 '
you have to take the existing list apart. For example, the built-in function range () needs to be independent of the start, stop parameter. You can automatically take the parameter list apart by adding a * operator when calling the function:List (range (3, 6)) # Normal call with separate arguments[3, 4, 5]args = [3, 6]List (range (*args)) # Call with arguments u
:#coding =utf-8Import OSOs.system (' e:\\test_object\\all_test.py ')OrImport OSOs.chdir ("E:\\test_object")Os.system (' Python all_test.py ')-----------------
All files under the directory can be obtained by Os.listdir ()
Through Os.path.getmtime (path) #返回在此path下最后一次修改的时间
Connecting directories and filenames via os.path.join (path, name)
#coding =utf-8Import OS#定义文件目录Result_dir = ' E:\\test_object\\report 'Lists=os.listdir (Resu
:
>>> 2 is a prime number3 is a prime number4 equals 2 x 24 is a prime number5 is a prime number6 equals 2 x 36 equals 3 x 26 is a prime number7 is a prime number8 equals 2 x 48 equals 4 x 28 is a prime number9 equals 3 x 39 is a prime number>>>
5. ''' contains docstring. It can be printed with print. As follows.
def M(): '''test docstring''' returnprint M.__doc__
Output result:
>>> test docstring>>>
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.