The dictionary works as follows:info={ ' stu1101 ': "Xiaohai", ' stu1102 ': ' liming ', ' stu1103 ': ' Heima ',}1. Increaseinfo['stu1105']='wate'print(info)2. Modificationsinfo['stu1101']='remin'print(info)3. DeleteInfo.pop ("stu1101"# standard delete del info[' stu1102'# another delete # random Delete print(info)4. FindPrint (Info.get ('stu1101')) # If a key does not exist, it will be an error, g
simple to add a line of code for Os.mkdir ("New_dir") and click to run, the original directory from 3 to four:After understanding the basic module, we come to see the magic of the module, first open before we write the passwd program, run, enter the user name and password, the display is welcome to login ..., if we call this passwd module directly in another PY program, Is it possible to run the same results? The answer is yes.Isn't it amazing?Ii. Wh
The Python program can handle dates and times in many ways, and converting date formats is a common feature.Python provides a time and calendar module that can be used to format dates and times.The time interval is a floating-point decimal in seconds.Each timestamp is represented by how long it has been since midnight on January 1, 1970 (the calendar).There are many functions under the time module of Python
4-1.python Control FlowThere are three types of control flows:1, sequential structure, 2, branching structure, (IF) 3, cyclic structure; (while,for)4-2. Branch structure IFformat:If this is the case: Execute this part of the statement elif: Execute this part of the statement else: Execute this part of the statementExam
Python commands. Start the interpreter and wait for the main prompt >>>. (It doesn't take long.) ) 3.1.1. Digital
An interpreter can be used as a simple calculator: You can enter an expression into it and it will return its result. The expression syntax is very simple: the operator +,-, * and/is used in the same way as other languages (for example, Pascal or C); Parentheses (()) can be used for grouping. For example: >>>
>>> 2 + 2
Key points of the fourth lesson of the itpub Python course:
Lesson 4 notes Python Common Data StructuresList:
Define ex: A = [1, 2, 3, 4, 5]One element can be of multiple types2 elements can also be of the list type, or multiple Nesting is also allowed.Multiple Generation Me
It's almost 12 o'clock, and we've just processed two urgent data.Two kids are asleep, and they're a lot quieter.Lately I've been thinking that working overtime every day shouldn't be the meaning of life--it seems like crap.The meaning of life is to live and better continue.Work hard to keep working overtime in order to get the protection of lifeIt's not scientific to spend most of my time working overtime.1. Take care of your body this is hardware (perhaps one day the local does not need hardwar
;> a.extend (b)>>> a[ 1, 2, 3, 4, 5]Extend object is a list, if it is str, then Python will first convert it by character to list and then append to the known list>>> La = [a]>>> B ="ABC">>>La.extend (b)>>>la[1, 2, 3,'a','b','C']>>> C = 5>>>La.extend (c) Traceback (most recent): File"", Line 1,inchTypeError:'int'Object
in one page or a screen. The following methods should be tried when considering what classes are needed and what methods are required for the class:(1) write down a description of the problem (what does the program do?) ), underline all nouns, verbs, and adjectives.(2) for all nouns, as a possible class.(3) For all verbs, as a possible method.(4) For all adjectives, as a possible characteristic.(5) Assign
,age): Self.__name=nameself.__age=agedef setName (self,name): Self.__name =namedef GetName (self): return self.__namedef setage (self,age): Self.__age=agedef getage (self): return self.__agep1= Person (' C + + ', ' $ ') print p1.getname () p1.setname (' Python ') print p1.getname () print P1._person__nameIf so, you can continue to access it.3. InheritanceInheritance does not introduce much, as the example a
In python, the method for determining the object type is very simple. You do not need to use the following method as in other languages:
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->
If
(
Typeof
(Obja)
=
Typeof
(String )){
//
Todo
}
In python, you only need to use the built-in function isinstance, which is very simple to use,
, but note that because program files have spaces and Python cannot recognize it, you need to change zip_command:
Zip_command = r 'd: \ progra ~ 1 \ 7-zip \ 7z' + "A % S % s" % (target, ''. Join (source ))
This is because only 8.3 file names are supported in DOS ~ End 1
The completed script is used to back up system files.
#! F:/document/python # filename: backup_ver1.py Import OS Import time
function have a local scope, which defines the owning global scope outside of the function.Local variables can only be accessed within their declared functions, while global variables are accessible throughout the program. Global variables if you want to modify in the function, you need to add the Global keyword declaration, if it is a list, dictionary and collection , you do not need to add the global keyword, directly can be modified, as follows:Name ='Marry' #String Global Variablesnames =
') ## this works, it created a new tuple
List advanced:
1.
nums = [1, 2, 3, 4] squares = [ n * n for n in nums ] ## [1, 4, 9, 16] [ expr for var in nums] -- ## the expr to its left is evaluated once for each element to give the values for the new list.
2.
strs = ['hello', 'and', 'goodbye'] shouting = [ s.upper() + '!!!' for s in strs ] ## ['HELLO!!!',
the code in a file. First, we can use python
3. The third method is to directly double-click the. py file in windows. This is not enough. We basically do python in Linux.
4. Imports reloads. This is very important. The import command can directly import a py file. The specific search path is described in Chapter 15t
1. The object that directly acts on for the loop is called an iterative object:Iterable。 可以被next()函数调用并不断返回下一个值的对象称为迭代器:Iterator。2, generators are Iterator objects, but,, list dict str Although Yes Iterable , but not Iterator .Turn list , dict wait, and str Iterable turn into Iterator functions that can be used iter()3. Because the Python Iterator object represents a data stream, the iterator object can be
Perform unit tests for different codes based on different command line parameters.
Running a subset of test case MethodsSometimes it's convenient to run only a subset of test methods in a given test case. This recipeWill show how to run either the whole test case, or pick a subset from the command line.
1. Create a new file named recipe4.py in which to put all the code for this recipe.
2. Pick a class to test. In this case, we will use our Roman numeral converter.
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.