The judgment of 1.square numberFrom math import sqrtdef is_quare (n): PointFrom math import sqrtThe Is_integer () command uses the% use of residual symbolsReturn () can be returned directly to T or F2. Fighters and one winnersPointCeil () takes the integer command, "taking into account the fact that the damage value is more than integer, so use Ceil () rounding"Attrgetter () position command?? "Attribute can create it yourself, such as the turn attribute in this example"3. Find needle in the
First, review:1, the process: The core is the process, the process is the steps to solve the problem, that is, what to do first, what to do, based on process-oriented design procedures, like in the design of a pipeline, is a mechanical thinking method.Pros: Complex questions to simplifyCons: Poor scalability (holding a body)Application scenario: Linux kernel, httpd,git2, Object-oriented programming: The core is the object, to understand the object should regard themselves as God, in the eyes of
user group Name list Os.getlogin () get user login name os.getenv get environment variable OS.PUTENV SET environment variable os.umask settings umask Os.system (cmd) Use system calls to run the cmd command Built-in modules (can be used directly without import) commonly used built-in functions:Help (obj) online, obj is any typeCallable (obj) to see if an obj can be called like a functionRepr (obj) obtains a representation string of obj that can be used to reconstruct a copy of the object us
dictionary three stylesList can be deleted and changed to search index slicesTuples do not support modification but can index slicesA dictionary is a key value stored only by key to find values5, the processing of documentsThe way the file is opened R means read-only w indicates write (if the original file has content will be emptied) a means append (append content after the original file)Read the fileF=open (' file.txt ', ' R ')Print F.read ()#read () indicates that a one-time read-in memory h
Http://www.b-list.org/weblog/2008/dec/05/python-3000/Let's talk about Python 3.0
Published December 5, 2008. Filed under: Python.
There's an old joke, so old that I don't even know for certain where it originated, that's often used to explain why Big invocations do things the way they do. it involves some monkeys, a ca
Python one-day training 104 ---- Django URLconf exercise, pythondjangoWhen the url is http: // 127.0.0.1: 8000/sum/n/(n is a number), the returned page displays the sum of 1-n.Source code views. py file
# Coding: utf-8from django. shortcuts import renderfrom django. http import HttpResponse, Http404 # Create your views here. def num_plus (request, plus): try: plus = int (plus) handle T ValueError: raise Ht
Python one-day training 05 ---- furious clicks, python05 ----
Function
Automatically obtain the CSDN article list and add clicks for each article.
Source code
Import urllib. requestimport reimport timeimport randomfrom bs4 import BeautifulSoupp = re. compile ('/a359680405/article/details /........ ') # Your own blog homepage url = "http://blog.csdn.net/a359680405" # using build_opener () is to let the
Python one-day training 103 ---- Django template exercises, pythondjango
Requirements
Request. META is a Python dictionary that contains all the Header information of this HTTP request, such as the user IP address and user Agent. You can obtain this dictionary through request. META. items. You must output the META information to the webpage.
Output result
Sour
entire page and organizephotos = beautifulsoup (HTML). Find_all (class_= "Imgwrapper") #用BeautifulSoup解析html, then use the function of BS, Find all items of class imgwrapper exist in a listFor photo in photos:img_url = photo.img["src"] #这里是获得上面每一条里面的img (with this method) the string stored in "src" (that is, the real address of the picture)# Print photo, Img_urlimg_filename = "img/" + img_url.split ("/") [-1] #使用切片工具切出每一个文件名img = requests.get (img_url, stream=true) #保存了if Requests.get (img_url)
;> s[::-1]'CBA'6, remove the numbers in the string, and then sort, if the same letters appear, such as AA, uppercase letters in front of lowercase letters#!/usr/bin/python#Coding:utf-8s='ABCDBA233ABC1'L=Sorted (s) upper_list=[]lower_list= [] forVinchL:ifv.isupper (): Upper_list.append (v)elifv.islower (): Lower_list.append (v)Else: Pass#print upper_list, lower_list forXinchUpper_list:x_lower=X.lower ()ifX_lowerinchLower_list:lower_list.insert (
fromBstImportBeautifulSoup#get the contents of the page to crawl by gettingret = Requests.get (url='https://www.autohome.com.cn/news/')#sets the encoding for the acquired content (Apparent_encoding gets the encoding of the current content)Ret.encoding =ret.apparent_encoding#parse the acquired content with the BeautifulSoup moduleSoup = ret. BeautifulSoup (Ret.text,'Html.parser')#Html.parser is the way of parsing #Find finds the first object Find_all finds all objects returns a list of objects
#-*-Coding:utf-8-*-"" "Created on Tue June 15:24:19 2015@author:hd" "" from sklearn import cross_validationc = []j=0fi Lename = R ' C:\Users\hd\Desktop\bookmarks\bookmarks.arff ' Out_train = open (R ' C:\Users\hd\Desktop\bookmarks\ Train.arff ', ' w ') out_test = open (R ' C:\Users\hd\Desktop\bookmarks\test.arff ', ' W ') for line in open (filename): # Items = Line.strip (). Split () C.append (line) c_train,c_test = cross_validation.train_test_split (c,test_size = 0.6) For i in C_train:
(' \ n '). Strip ("")] Biaotouen = [' Co Lor ', ' root ', ' sound ', ' strip ', ' texture ', ' feel ', ' label '] biaotoudict = {} for index in range (len (Biaotouen)): Biaotoudict[biaotouc[index]] = Biaotouen[index] res = [] for eachline in Fileread.readlines (): Eachlinearray = Eachline.split (', ') Reselem = [] for Elemindex in range (len (eachlinearray)): Eachlinearrayelemindexop=eachlinearray[eleminde X].strip (' \ n '). Strip ("") if (Biaotoudict.has_key (Biaotou[elemindex])
Python's dictionary is a very convenient data structure, using which we can easily find his grades, rankings, etc. by name (key) without having to traverse the entire dataset.For example: {' Lee ': [1, +], ' Jane ': [2, 98] ...}But in the process of using the dictionary, there are some problems, that is, the dictionary itself is regardless of the order you enter>>> d = {}>>> d['Lee'] = [1, 100]>>> d['Jane'] = [2, 98]>>> d['Tom']=[3,96]>>>d{'Jane': [2, 98],'Lee': [1, 100],'Tom': [3, 96]}When this
Python Intensive Training Note (7)-use the deque queue and save the object as a file,
The deque object in the collections module is a queue with the first-in-first-out principle for normal queues. We can use this object to save data.
For example, the system starts to randomly roll a game with a guess number ~ Then, the keyboard starts to receive your input. The number system will tell you whether the input
@+ adorner name. Indicates that the function is to be added when the adorner @add_strdef a (): Return ' 123 ' x = A () print XHello 123If the function that was added to the adorner itself would need to pass parametersFor exampledef a (m,n): Return ' 123 ' +m+nx = A (' 321 ', ' ABC ') print X123321ABCThen you only need to set two parameters in the adorner's inline function, so that the adorner can pass the required arguments of the original function into the adorner interior.def add_str (func):
Python training Day2Today, we mainly explain the common methods of int, float, str, list, tuple, and set classes. The difference between encode and decode. Regardless of the operating system character set. When they communicate with each other, they all need to convert the character set to Unicode, such as the universal code. In this way, there will be no barriers to communication between them. For example,
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.