python (first acquaintance)

################################################## ##################################################
_ ####################################Basic Modules

##########################list
["","","",["",["","" ]]] lists nested lists

###########################内置函数(BIF)
len()
pop()
append()
extend()
insert()
print()
remove()
isinstance()
list()
range() 
enumerate()
int()
id()
next()

##########################loop
####for loop
for target indicator in list:
    list processing code

####while loop
while Judgment condition:
    list processing code

###########################Judgment
if a condition:
    "true" group
else:
    "false" group

例:
 for a in movies:
    if isinstance(a,list):
        for b in a:
            if isinstance(b,list):
                for c in b:
                    print(c)
            else:
                print(b)
    else: print(a)

########################## function definition and recursive
def function name (parameter list):
    function code

递归深度默认100。
例:
    def print_lol(the_list):
    for a in the_list:
        if isinstance(a,list):
            print_lol(a)
        else:
            print(a)

################################################## #################################################
_ ######################################Function modules (code reuse)
##### ##################module
A text file containing python code, the filename ends with .py

#######################Comment code
Triple quotes """ create multi-line comments

######################Test code
Open the .py file and press F5

####################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################
_
_
3. Build a release file, open the cmd command window, and enter in the path where the file is located: setup.py sdist  
  python3 setup.py sdist(linux)
4. Install the release into the local copy of python
  sudo python3 setup.py install

5. Release the version before the update
    a. Modify the version='' of setup.py
    b. Update the release: python setup.py sdist upload
#################Enter the specified directory
import os #Get
the current working directory
>>>os.getcwd() #Change
the current working directory
>>>os.chdir('d:\')
>>>os.getcwd()

################################################## ##################################################
_ #######################################Error handling (files and exceptions)
python input The mechanism is row-based.
Data processing follows: input-processing-output.


#############################Data processing functions:
open(),
close(),
readline() (read a line of data in the file ),
seek() (return to the beginning of the file),
tell()
split(), split('symbol', number of divisions), to prevent multiple identical separators
os.path.exists()

#############################Two processing methods for data that does not meet the standard
1. Add additional judgment logic: find( ) returns the index position of the found substring, otherwise returns -1 (not robust enough, the data format changes, the code needs to change) 2. try
/except mechanism
    try: code that
        may cause errors
    except:
        error recovery code


###### Because it does not reflect the type of exception that occurred, you need to specify the exception

    try:
        code that may cause errors
    except errorType:
        error recovery code
    finally: code that
        will definitely be executed

################################################## #################################################
_ ###########################################Data is saved to a file to
view the current effect A set of all names defined in the domain locals()
str(), coerced to a string

################with statement
When using the with statement, don't worry about closing open files

###################### strip() strips
out unwanted whitespace in a string

####################Output files as scheduled
Custom output function

#################python save and load data => standard library pickle
principle: import module => pickle.dump() save data => pickle.load() restore data. The only requirement: the file must be opened in binary access mode


################################################## #################################################
_ ##########################################Processing data
method chain: such as data .strip().split('XX'), concatenate multiple methods together to produce the desired result, read from left to right
Function concatenation: such as print(sorted()), read from right to left
Sort: two methods , the default ascending order, the descending order needs to pass in the parameter reverse=True
1. Sort in place sort(), covering the original data

2. Copy sort sorted(), the source data is retained, the copy is sorted, and an ordered copy is returned

####################List comprehension => done in one statement:

listname=[conversion function (target identifier) ​​for each data item in existing list]

1. Create a new list to store the converted data
2. Iteratively process each data item in the original list
3. Complete data conversion at each iteration
4. Append the converted data to the new list

############################Duplicate data processing
1. Use not in to determine whether it exists

2. Use a collection data structure to deduplicate set()


################################################## ##################################################
_ ########################################Package code and data (custom data objects)
dictionary : equivalent to map, hash, associative array

##########Custom class
Use class to customize the class
constructor
class ClassName:
    def _ _init_ _(self):
        code to initialize the object

The first parameter of each method is self, which is used to call the object instance

################Inheriting classes
Created by inheriting other existing classes (including built-in data structure classes such as list, set, dict, etc.)

class ClassName(list):
    def __init__(self, parameter 1, parameter 2, parameter 3=default value):
        list.__init__([])
        self.attribute name1=parameter1
        self.attribute name2=parameter2
        self.attribute name3=parameter3


################################################## #################################################
_ ##########################################Web development (integrated together)
customers Side request (web browser) and server response (web server)

1. The browser enters the web address 2. The web
browser converts the user action into a web request and sends it to the web server 3. The web
server receives the request and judges
    1. The static content
        searches for resources and returns the result as a web response
    2. Dynamic content
        runs a program to generate a web response
4. Creates a web response, sends it to the web browser 5. The web browser
receives the response and displays it on the user

Web applications should follow the MVC framework (Model-View-Controller)


################################################## ####################Mobile Application Development (Small Devices)

################################################## ##################################################
_ ###########################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################Process

################################################## ##################################################
_ #########################################Expanding Web Applications


################################################## ####################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################
_ ##################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################Processing Complexity )
1. To build a model for the data in the file, you first need to find a data structure to store the data, usually a dictionary

2.input() This built-in function displays a prompt on the screen and returns the input to the code as a string

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325316201&siteId=291194637