Functional programming: A very high degree of abstraction of the paradigm, the important characteristics: the input is determined, the output is determined;Python is partially supported for functional programming;Higher order functions:def add (x,y,f): #函数本身传给函数, is the higher order function return f (x) +f (y) res = Add (3,-6,abs) print (res)Python Learning Path
Official documents:https://pip.pypa.io/en/stable/user_guide/#configurationAs an example:Windows users want to change the PyPI source, you can create a new PIP folder under the%appdata% directory, and then create a new Pip.ini under the Pip folder.(If a folder or file already exists in the path, you do not have to create it, and you can enter "Echo%appdata%" under CMD to see where the path%appdata% represent
(' method.py ', ' test.py ')
Import OSOs.rename (' method.py ', ' test.py ')
Import is recommended here because it makes your program easier to read and avoids conflicting names.
from xxx import xxx as xxx
We can see that this is an alias for the method or module.
From OS import rename as NewNameNewName (' method.py ', ' test.py ')Import OS as Os_nameOs_name.rename (' method.py ', ' test.py ')
The last one doesn't have to be explained. I believe we all understand.(3) Sys.path
Sys
, scipy Module library, pandas module library, etc.AI domain scikit-learn module library, Keras module library, etc.Web development domain Secket Module library, Django Module library, etc.4. What is Virtualenv? What is the role of it? Virtualenv is a virtual environment that is intended to allow multiple versions of Python to coexist.What are the 5.python development ides? A brief description of each type
A robot is located at the Top-left corner of a m x N grid (marked ' Start ' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying-to-reach the bottom-right corner of the grid (marked ' Finish ' in the diagram below).How many possible unique paths is there?Above is a 3 x 7 grid. How many possible unique paths is there?There are two ways of solving this problem.1. Direct mathematical expression Choose M-1 from M+n-2Class solution: # @return
One, the higher order function: Two kinds: One is the return value contains the function body, the other is a function body as a parameter passed to another function1. The return value contains the function bodyExample 1,1 def Test (): 2 Print (' This is a test ') 3 return Test 4 5 f = test ()6 F ()1 This is a test 2 This is a testExample 21 definward ():2 Print('From inward')3 defoutward ():4 Print('From outward')5 returnInward6 7f =Outward ()8F ()1 from Outward 2 from Inw
and print it in a list form1 [' learn file operation \ n' old boy's tutorial good \ n' HelloWorld']Second, the file write operationW Mode: This mode will erase the original content when the file is opened.Example 11f = open ('New_file','W', encoding='Utf-8')2F.write ('11111\n')3F.write ('22222\n')4F.write ('33333\n')5F.write ('555\n666\n777\n')6 7 8F.writelines ('11111111\n2222222\n')9F.writelines (['11113331111\n2227772222\n'])Ten #f.writelines ([' 11111111\n2222222\n ', 6]) #报错 file contents
(Ss_y.inverse_transform (y_test), Ss_y.inverse_transform (lr_y_predict)) $ Print("the mean square error of the linear is:", Lr_mse) -Lr_mae =Mean_absolute_error (Ss_y.inverse_transform (y_test), Ss_y.inverse_transform (lr_y_predict)) - Print("the average absolute error of the linear is:", Lr_mae) - A #evaluation of the SGD model +Sgdr_score =Sgdr.score (x_test, y_test) the Print("the default evaluation value for SGD is:", Sgdr_score) -sgdr_r_squared =R2_score (y_test, sgdr_y_predict) $ Print("
regression tree is:", Dtr.score (X_test, y_test)) - Print("the r_squared values for the flat regression tree are:", R2_score (Y_test, dtr_y_predict)) - Print("the mean square error of the regression tree is:", Mean_squared_error (Ss_y.inverse_transform (y_test), - Ss_y.inverse_transform (dtr_y_predict))) A Print("the average absolute error of the regression tree is:", Mean_absolute_error (Ss_y.inverse_transform (y_test), + Ss_y.inverse_transform (dtr_y_predict))) the - " " $ the default evalua
-za-z]"," ", Sent.lower (). Strip ()). Split () in sentences.append (temp) - to returnsentences + - #The sentences in the long news are stripped out for training . thesentences = [] * forIinchx: $Sentence_list =news_to_sentences (i)Panax NotoginsengSentences + =sentence_list - the + #Configure the dimension of the word vector ANum_features = 300 the #the frequency of the words that are to be considered +Min_word_count = 20 - #number of CPU cores used in parallel computing $Num_workers =
Requests is an HTTP client library for Python , similar to urllib,urllib2 , but urllib2 API is more complex, such as implementing a post or get function requires a lot of code.Let me briefly introduce this library today, and after I have read the official documentation, write a full-fledged one.#-*-Coding:utf8-*-import requestr = requests.get (' http://www.zhidaow.com ') #发送请求r. status_code# Return status Code r.headers[' Content-type '] #返回头部信息r. enc
socket sk.connect ('127.0.0.1 ', 8000) # try to connect to server sk.send (b'hello' ) # dialog (send/Receive) Print # Close Customer socketsView CodeProblem: May be encountered when restarting the serverWorkaround:#Add a socket configuration to reuse IP and ports.ImportSocket fromSocketImportSol_socket,so_reuseaddrsk=Socket.socket () sk.setsockopt (SQL_SOCKET,SO_REUSEADDR,1)#That 's it, plus before bind.Sk.bind ('127.0.0.1', 8000)#bind an address to a socketSk.listen ()#Monitoring LinksC
(3,0)#"0" represents an offset from the beginning of the file, offset by 3 units9 Print(F1.tell ())Ten Print(F1.read (3)) One Print(F1.read (6))#starts reading 6 characters from the position indicated by the pointer after the offset A Print(F1.tell ()) - - Print(F1.readline ()) the #print (' see if it's up to the end: ', F1.read (5)) - - Print(F1.seek (5, 0)) - Print(F1.seek (3,1)) + Print(F1.seek (0,2))#"2" represents an offset of 0 units from the end and "0"1 Nam 2 Print (F1.seek (3,1))
.score (X_train_poly2, Y_train))#0.9816421639597427Two-time linear regression model fitted curves:The fitting degree is better than 1 linear fitting.The following 4 linear regression models are performed:1 #four-time linear regression model fitting2Poly4 = Polynomialfeatures (degree=4)#4-time polynomial feature generator3X_train_poly4 =poly4.fit_transform (X_train)4 #Building Model Predictions5Regressor_poly4 =linearregression ()6 Regressor_poly4.fit (X_train_poly4, Y_train)7 #draw a graph of 2
Crawlers do two things.① impersonate a computer to initiate request requests to the server② receive server-side response content and parse to extract the required informationInternet pages are complicated, and a single request cannot get all the information. You need to design a crawler process.This book mainly introduces two kinds of smooth ① multi-page crawler Process ② cross-page crawler processMulti-page Crawler flow:(1) Manually paging and observing the URL composition of each page to const
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.