Python learning summary 4-4

python

  • python basics
    • Data Types and Variables
      • integer
      • floating point number
      • string
      • Null value None
      • arithmetic operator
    • String: Unicode encoding
      • ord () Gets the integer representation of a character
      • char () converts the code to a character
    • list and tuple
      • list list
        • append adds elements to the end: classmates.append('example')
        • Insert into the specified position: classmates.insert(1,'example')
        • pop delete:
          • Remove the end: classmates.pop( )
          • Delete specified: classmates.pop(i)
      • tuple _
        • Tuples cannot be modified once initialized
        • If you can use tuples, don't use list lists, because the code is safer
    • conditional judgment
      • if-else statement
      • elif statement
        • abbreviation for else if
    • cycle
      • for...in loop
      • while loop
      • break statement: exit the loop early
      • continue statement: skip the current cycle and start the next cycle directly
    • input
      • input( ) reads user input, and the return type is str. If you want to get int type, you can consider casting: int ( input ( ) )
    • dict and set
      • dict : dictionary adopts key-value storage method, can be called by d.get( ), delete d.pop(key)
      • set : a collection of keys, but does not store values
        • add(key) add element
        • remove(key) delete element
  • function
    • Call functions
      • Call abs() function, absolute value function
      • The max() function receives any number of parameters and returns the largest one
    • define function
      • def ( ) statement, write the function name, parentheses, parameters in the parentheses, colon, and return the return value with the return statement
      • pass : empty function
    • function parameters
    • recursive function
      • Calling itself inside a function, this function is a recursive function
  • functional programming
    • higher order functions
      • Variables can point to functions: f=abs
      • The function name is also a variable: abs = 10
      • Incoming function: def add(x ,y ,f): return f(x) +f(y)   
    • map() function
      • map receives two parameters, one is a function and the other is iterable, map applies the incoming function to each element of the sequence in turn, and returns the result as a new iterator
    • filter() function
      • Used to filter sequences, the difference with map() is that filter() applies the incoming function to each element in turn, and then decides whether to keep or discard the element according to whether the return value is True or False.
    • sorted( ) function
      • Sorting, you can sort the list directly, or you can receive a key function to implement custom sorting sorted([36,5,-12,9,-21], key = abs)
    • return function
      • return function as return value
    • anonymous function
      • lambda function
  • module
    • use modules
    • Install third-party modules
  • I/O programming
    • file read and write
      • 读:f = open('1.txt', 'r')   f.read()  f.close()      或者with open('1.txt' , 'r') as f:      print(f.read())
      • 写:f = open('1.txt', 'w')   f.read()  f.close()
    • StringIO vs. ByteIO
      • StringIO reads and writes str in memory
      • BytesIO: Manipulating Binary Data
  • process and thread
    • Multi-process: high stability, expensive process creation, high memory CPU overhead
    • Multithreading: One thread has a problem and the whole process crashes
    • Multithreading is more efficient than multiprocessing
  • turtle drawing
    • width,forward,pencolor,right
  • network programming
    • TCP programming
      • To open a socket, you need to know the IP address and port number of the target computer, and then specify the protocol type
      • client, server
    • UDP programming
      • TCP establishes a reliable connection, and both communicating parties can send data in the form of streams. Compared to TCP, UDP is a connectionless protocol.
      • You only need to know the IP address and port number of the other party, and you can send data packets directly. But I don't know if I can reach it

Guess you like

Origin blog.csdn.net/qq_40843903/article/details/115425219