Discover codecademy python review, include the articles, news, trends, analysis and practical advice about codecademy python review on alibabacloud.com
Review C ++ lambda and pythonlambda from python
Lambda is an anonymous function. python lambda can make simple expressions of simple functions. C ++ lambda can implement functions similar to nested functions.
Python lambda
Lambda [arg1 [, arg2, arg3 .... argN]: expression # def defined function def foo (): return 'Hell
): 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
(' Tmp1 ', '. dat ')Find all the files in a directory and write "Ostest" to each fileDd/users/zhouhaijun/desktop/hhhhh/ostest/users/zhouhaijun/desktop/hhhhh/ostest/ddLiwen.dat/users/zhouhaijun/desktop/hhhhh/ostest/users/zhouhaijun/desktop/hhhhh/ostest/liwen.datOk!If the file name in a directory contains a DAT suffix name, append a line to it "I found it!"DdWhat to modify:Get current pathGet current directory:/users/zhouhaijun/desktop/hhhhh/ostestSeek function:Content is: good! LiwenLearnReview f
Remember, in the previous section, we introduced the if statement specifically: the process of starting the if statement. When learning the if statement, I do not know much about the basic knowledge of python Programming. maybe I have not done anything that is too complicated. This article will review it and improve the basic statement structure through review.
/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
([]) # 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
=[-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
DescribeThe Help () function is used to view a detailed description of the function or module's purpose.GrammarHelp syntax:Help ([Object])Parameter description:
Object--objects;
return valueReturns the object help information.InstanceThe following examples show how help is used:>>>help ('sys'#>>>help ('str ' # >>>a = [# # # ## shows the help of the list's Append method ... Show Help Info ...Python function
Import os# 1. Switch path =============d = OS.GETCWD () #获取当前的工作路径os. ChDir (' d:\\ ') #目录的切换print (OS.GETCWD ()) # (Toggle the past how to come back?) I'll be back in a chdir. Os.chdir (d) Print (OS.GETCWD ()) # 2. Execute the System commands =============# system and Popen are all execution systems commands, but popen is more useful, Because it has a return value of Os.system (' dir ') #显示的是gbk的编码, # solves the system garbled method ret = Os.popen (' dir ') #popen是有返回值的, and self-transcoded pr
than using a varchar type. In fact, because the char type usually takes up more space than the varchar type, it is more advantageous to use the varchar type from the point of view of reducing space consumption and reducing disk I/O;3, store very short information, such as house number 101,201 ... Such a short message should be char, because varchar also has a byte to store the information length, the intention of saving storage is now worth the candle.4, fixed-length. For example, using the UUI
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
Serialization ofFrom https://www.liaoxuefeng.com/In the process of running the program, all the variables are in memory, for example, to define a dict:d = dict(name=‘Bob‘, age=20, score=88)Variables can be modified at any time, such as name change ‘Bill‘ , but once the program is finished, the memory used by the variables is fully recycled by the operating system. If you do not save the modified ‘Bill‘ storage to disk, the next time you rerun the program, the variable is initialized ‘Bob‘ .The p
This series of blogs takes notes from learn python the hard way.
1. Because the five chapters to be viewed today is a review of the nature of the content, the content in the front is integrated, so there is no new content
OnlyCodePaste it here
View code
Print " Let's practice everything. " Print " You \ 'd need to know \ 'bout escapes with \ that do \ n newlines and \ t tabs. " Poem = "
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.