Jingdong Book review has a very rich information, which contains the date of purchase, the title, author, Praise, in the evaluation, the difference between the evaluation and so on. Take the purchase date as an example, using Python + MySQL with the implementation of the program is not large, only 100 lines. I have raised the relevant explanations in the program:
From selenium import WebdriverFrom BS4 impo
Recently want to see a film, to know the review, just learning Python crawler, do a small example.Code modified based on third-party source link http://python.jobbole.com/88325/#comment-94754#Coding:utf-8 fromLib2to3.pgen2.grammarImport Line__author__=' Hang'ImportWarningswarnings.filterwarnings ("Ignore")ImportJieba#Word breaker PackageImportNumPy#NumPy Calculation PackageImportReImportPandas as PDImportMa
): Pass # Defining Properties @property def prop (self): pass# # # # # # # # # ########### call ###############foo_obj = foo () Foo_obj.func () Foo_obj.prop # Call PropertiesThe definition and invocation of a property is a few points to note:
When defining, add @property adorners on the basis of common methods;
When defined, the property has only one self parameter
When called, no parentheses are requiredMethod: Foo_obj.func ()Property: Foo_obj.prop
the value corresponding to the key, does not exist when the output can be specified, default is emptyD.get (K[,d]), D[k] if k in D, else D. D defaults to None.
Has_key () to see if key existsD.has_key (k)-True if D has a key k, else False
Iitems () converted to a list of (key, value)D.items (), List of D ' s (key, value) pairs, as 2-tuples
Copy () copyingD.copy (), a shallow copy of D
Clear () Empty dictionaryD.clear (), None. Remove all items from D
Pop () deletes the value of the sp
element from the N1 and returns the element.>>>n1.remove (2) # Remove the first 2 from the N1>>>n1.insert (0,9) # Insert 9 at position Subscript 0In summary, list is a class. Each list belongs to that class.The Python supplement has an appendix to the list of common methods.Operator is a special methodWhen using Dir (list), you can see an attribute, which is __add__ (). From the formal perspective is a special method (underline, underline). Where is
/articles/7580428.html53-Tuple expressions, list derivations, generator expressions, recursion, anonymous functions, built-in functionsLinks: http://www.cnblogs.com/linhaifeng/articles/7580830.htmlSix function draftsThis is the draft part of the above content, the reader does not need to seeDraft: http://www.cnblogs.com/linhaifeng/articles/6883726.htmlSeven jobsJob Requirements:Analog implementation of an ATM + shopping mall Program
Quota 15000 or Custom
Realize shopping mall, buy t
Now it is time to review python keywords and symbols. The following lists some important python keywords and symbols.
Based on your memory, first write down the functions of these keywords, and then go online to find out their actual usage. Some of them may be difficult to find, but you should keep trying.
Write down the cards that you mistakenly remember, and wr
the form of return ' a ', [A, ' B '], ' C ' feeling like returning multiple values, in fact a tuple.94. The interactive mode is also a tuple>>>1,2,3>>> (1, 2, 3)95. The function does not have a clear indication of the return value. The return is None96. Return value 0->none 1->object >1->tuple97.def foo (a,*b,**c)The Declaration and definition of the 98.python function together99. Functions can also have attributes such as: __doc__100.
Main use of Wxpython (most mature cross-platform Python GUI toolkit) foreplay: Veteran python GUI program (Tkinter)Import Tkinter.messagebox asMessageBoxclassApplication (Frame): def __init__ (Self,master=None): frame.__init__ (SELF,MASTER,BG="Red") #设置框架类的父类 (based on master), frame can be considered as the parent container of the control Self.pack () #显示frame控件 self.createwidgets () def createwidgets (sel
Users'(name,fullname,password) VALUES (%s,%s,%s) '
cur.execute (sql, ("aaaaa","asd666" ,"6666"))#获取插入的最后一条数据的自增ID Print (CUR.LASTROWID) #只对一次增加一个可以直接看出, for adding multiple quantities at a time execute multiple SQL at one time='INSERT into Users (Name,fullname,password) VALUES (%s,%s,%s)'Cur.executemany (sql,[("aaadsaaa","Asd6dasd66","6666"),("adsaaaaa","asd6awf66","6666"),("awaaaaa","asd666","6666")]) Note that execute and Executemany will return the number of execution impact bars after exec
([]) # string, list, dictionaryB. Specific methodsCountIndexc. Nesting (elements cannot be modified)t = (11,22,33)t = (11,22,["Alex", {"K1": "V1"}]) e. Properties of tuples, non-modifiable, who cannot be modified tuples, son cannot change tuples, son can't change, grandson, ... organizing: General string, perform a function, generate a new content, the original content is unchanged list,tuple,dict, performing a function that changes itself
1. Condition Judgment:There is only oneIf***Elif: #多个条件加elif, want to add a few plus a few****Else****Python is indented to represent the statement block, see the colon, the downside is to indent2. CirculationTwo types, for and whileFor I in Rangle (): #想循环几次, write a few****While * * *: #while循环必须有计数器****3. String formattingUsername = input (' Please enter your name: ')123Example 1. username+ ', welcome, ' + ' time is: ' +timeExample 2. ' %s Hello '%
One, custom attributesWe know that in the process of front-end page rendering, we may need to use some back-end parameters, the acquisition of this parameter is generally rendered through the template language. But when these parameters are used in the JS file (JS code if the file is a separate reference, template language can not be rendered), how to do? We can write a label that is not actually useful on the page, by customizing the property to this tag to hold the parameters we want. Examples
single line, it is not equivalent to a C or C + + inline function, which is designed to call small functions without consuming stack memory to increase operational efficiency.Example:#!/usr/bin/python#-*-Coding:utf-8-*-# Writable Function Descriptionsum = lambda arg1, arg2:arg1 + arg2;# Call the SUM functionPrint "added value is:", SUM (10, 20)Print "added value is:", SUM (20, 20)Built-in functions:Common functions:ABS ()Max ()Min ()Len ()Divmod ()PO
插入的Key的顺序返回[‘z‘‘y‘‘x‘]OrderedDictYou can implement a FIFO (first-in-one-out) dict, deleting the first added key when the capacity exceeds the limit: fromCollectionsImportordereddictclasslastupdatedordereddict (ordereddict):def __init__(self, capacity): Super (Lastupdatedordereddict, self).__init__() self._capacity=capacitydef __setitem__(self, Key, value): ContainsKey= 1ifKeyinchSelfElse0ifLen (self)-ContainsKey >=Self._capacity:last= Self.popitem (last=False)Print 'Remove:', lastifContainsKey
=[-1,49,38,65,97,76,13,27,49]#where [0]=-1 this position is a staging unitd=[-1,49,38,65,97,76,13,27,49]#Insert sort directly------------------------------------------------------defInsertsort (list): forIinchRange (2, Len (list)):ifLIST[I]#List[i] must be inserted into an ordered sub-tableList[0]=list[i]#Copy as SentinelLIST[I]=LIST[I-1]#First, list[i] The previous element is moved back oneJ=i-2#Judging from the front of List[i] whilelist[0]List[j]: list[j+1]=List[j] J-=1list[j+1]=L
Question 001-1: Please enter a three integer a,b,c to determine whether you can make them into a triangle of three side lengths. Output Yes and area if possible, otherwise the output noA = float (input ())b = float (input ())c = Float (input ())If a > 0 and b > 0 and C > 0: #判断边长是否为正if (A + B > C) and (A + C > B) and (B + C > a): #判断是否可以为三角形p = (A + B + C)/2.0S = (p* (p-a) * (p-b) * (p-c)) **0.5 #面积, Helen FormulaPrint ("YES, side length: a = {},b = {},c = {}, area: {}". Format (a,b,c,s))ElsePri
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.