"Stupid methodology python" Essay

String


The string can contain formatting characters% s, as long as the format of variables into a string, and then followed by a percent sign% (percent), then followed by the variable name. The only caveat is the place If you want to pass the time formatting characters into multiple variables in the string, you need to put the variable () parentheses (parenthesis) in, and with between variables, commas (comma) separated. As you go shopping, "I want to buy milk, bread, eggs, soup," the same, but the programmer said that "(milk, eggs, bread, soup)". % R shows a variable "raw" data values,% r can be reproduced when printing the object it represents, but other symbols used to show the user the value of the variable. Can be regarded as a string constant, the addition can be multiplied 
 
 
 
 
 

tip(print)

Print multiple lines, and the need to change line, it requires three print in double quotes or escape character \ n example: print ( "" " . There apos something going ON here Wallpaper . The Three With Double-QUOTES We'll BE Able to type WE much like AS AS. Even Line IF WE want. 4, or. 5, or 6. the "" ") \ T: 8 in the hollow print grid \: a print in the print \, 
 
 
 
 
 
 
 

Question:

input () function, which receives any willful input, default to all input character string processing, and returns a string type. If the input number, can be changed: int (input ())

Argv variable parameters

SYS Import argv from Script, First, SECOND,, THIRD, argv = the parameters are placed inside the argv variable parameters, but these parameters need to assign out this script (.py) file 
 

Note : input and argv are given from the external input, input is then input to run, need to manually enter; argv just need to give input in the running of the script, and then run.

Reading file

file = open (read the address of the file) File.read () 

Write file

Close file close-- read-- read the contents of the file readline-- to read the text file line truncate-- empty file write (string) - the string to the file #from the os.path Import EXISTS #exists ( filename string) function to determine whether the file% exists: the string as a parameter file, if the file exists, it returns True, otherwise, it returns False. 
 
 
 
 
 

tip

print_two DEF ( args): tell python to all function parameters are organized into a list in args.

tip

The seek action python functions: file read pointer moves to the specified location. There are three modes: (1) the file name .seek (p, 0), or seek (p), represents the absolute position, f.seek (0) is moved to the head position of the file (2) f.seek (p, 1 ) represents the relative position, this position is moved in the p position (3) f.seek (p, 2 ) represents the relative position to the p-position on the basis of the end of the file, f.seek (0,2) is moved to the end of the file location. 
 
 

tip

split () designated by the slice delimiter strings, if the parameter value is specified num, num + 1 is separated substring string .split (str = "", num = string.count (str)), num - - the number of divisions. Defaults to -1, i.e., all separated. 

tip


The method is applied on the sort of the list, sorted can be sorted objects operate all iterations. sorted (iterable, cmp = None, key = None, reverse = False): iterable - iterables, reverse - collation, reverse = True descending, reverse = False ascending (default). 

tip


pop () function is used to remove an element of the list (the default last element), and returns the value of the element, list.pop (obj = list [-1 ]), obj - optional parameter to remove Object element of the list. str.strip ([chars]): removing a specified character string craniocaudal (default spaces or new lines), or sequence of characters. 

Boolean truth table

Equal, not equal, greater than or equal, or less, and, or, not, NAND, NOR, Ture, False

tip

Code x + = 1 and x = x + 1 is implemented as a function, but fewer characters can be entered. You can call it "incremental" operator. - = is the same

tip


1.range method returns a list of 2. step 2: range (1,5,2) 

tip

append () method for adding a new object at the end of the list: list.append (obj)

tip

SYS Import Exit from Exit (1) indicates that an error has occurred, and exit (0) indicates that the program is properly exit if "0" in choice or " 1" in choice: 
 

tip

join method is to use a linked list contents of a string, so to write '' .join (string) dict.items (): Python dictionary (Dictionary) items () function can return a list traversal (key, value) tuples array. dict.get (key, default = None) : Returns the specified key, if the value is not in the dictionary returns the default value. 
 

class

Action class is a set of functions and data organization and place them in a container, so that you can. Operator to access them. Instantiate: If a class is like a mini-module, then the class will have a concept similar import. This concept is known as an example of when a class is instantiated, you get a class object. Classes, objects, instantiated, def, self, inheritance, slave, 1, create a call? ? The class inherits the Y- 2, class? ? There is a init method and has self? ? Two parameters. 3, class? ? There is a call? ? The function, which has self and? ? Two parameters. 4, assigned to foo class? ? One example. 5, foo called from inside? ? Function parameters, and passed for the self? ? . 6, calling foo from the inside? ? Property, and set it to? ? . Note: super () function is a way to call the parent class (super class) is used, is used to solve the problem of multiple inheritance. 
 
 
 
 
 
 
 
 

Guess you like

Origin www.cnblogs.com/wangchangshuo/p/11613323.html