MindMap Gallery Python basics
This is a mind map about the basics of Python. Python is an interpreted, object-oriented, high-level programming language with dynamic data types.
Edited at 2024-04-21 20:49:13One Hundred Years of Solitude is the masterpiece of Gabriel Garcia Marquez. Reading this book begins with making sense of the characters' relationships, which are centered on the Buendía family and tells the story of the family's prosperity and decline, internal relationships and political struggles, self-mixing and rebirth over the course of a hundred years.
One Hundred Years of Solitude is the masterpiece of Gabriel Garcia Marquez. Reading this book begins with making sense of the characters' relationships, which are centered on the Buendía family and tells the story of the family's prosperity and decline, internal relationships and political struggles, self-mixing and rebirth over the course of a hundred years.
Project management is the process of applying specialized knowledge, skills, tools, and methods to project activities so that the project can achieve or exceed the set needs and expectations within the constraints of limited resources. This diagram provides a comprehensive overview of the 8 components of the project management process and can be used as a generic template for direct application.
One Hundred Years of Solitude is the masterpiece of Gabriel Garcia Marquez. Reading this book begins with making sense of the characters' relationships, which are centered on the Buendía family and tells the story of the family's prosperity and decline, internal relationships and political struggles, self-mixing and rebirth over the course of a hundred years.
One Hundred Years of Solitude is the masterpiece of Gabriel Garcia Marquez. Reading this book begins with making sense of the characters' relationships, which are centered on the Buendía family and tells the story of the family's prosperity and decline, internal relationships and political struggles, self-mixing and rebirth over the course of a hundred years.
Project management is the process of applying specialized knowledge, skills, tools, and methods to project activities so that the project can achieve or exceed the set needs and expectations within the constraints of limited resources. This diagram provides a comprehensive overview of the 8 components of the project management process and can be used as a generic template for direct application.
Python basics
Introduction to Python
Python is an interpreted, object-oriented, high-level programming language with dynamic data types
Python syntax basics
Python variables
1. Python variables are containers used to store data. They can store different types of data, such as integers, floating point numbers, strings, etc.
2. Python variable names consist of letters, numbers, and underscores, and cannot start with numbers.
3. Variables in Python do not need to be declared. Variables can be created by assigning values directly.
4. Variable names are case-sensitive. For example, var and Var will be regarded as two different variables.
5. You can modify the value of a variable through an assignment statement, or delete a variable through the del keyword.
Python data types
1. Data types in Python include: integer (int), floating point number (float), string (str), list (list), tuple (tuple) and dictionary (dict).
2. A list is a mutable ordered collection that can store different types of data.
3. Tuples are immutable ordered collections, similar to lists, but tuples are represented using parentheses instead of square brackets.
4. A dictionary is an unordered data structure consisting of key-value pairs, with each key corresponding to a value.
5. Python also provides other data types, such as sets and bool, for processing specific data scenarios.
6. When writing Python code, understanding different data types and their characteristics can help us process and manipulate data more effectively.
Python operators
arithmetic operators :addition -: Subtraction *:multiplication /:division //: Integer division (floor division) %: Modulo (remainder) **: Power operation
comparison operator ==: equal to !=: Not equal to >: greater than <: less than >=: greater than or equal to <=: less than or equal to
assignment operator =: assignment =: Addition assignment -=: subtraction assignment *=: multiplication assignment /=: division assignment //=: Integer division assignment %=: Modulo assignment **=: Power operation assignment
operator precedence Operator precedence in Python from highest to lowest is: brackets Exponential operations (**) Sign (x, -x, ~x) Multiplication, division, modulo and integer division (*, /, //, %) Addition and subtraction ( , -) Bit operations (<<, >>, &, ^, |) Comparison operators (<, <=, >, >=, !=, ==) Identity operator (is, is not) Membership operator (in, not in) Logical operators (not, and, or)
Bit operators &: bitwise AND |: bitwise OR ^: Bitwise XOR ~: bitwise negation <<: shift left >>:Move right
Logical Operators and: logical AND or: logical or not: logical negation
Python object-oriented
1. Objects in Python are instances of classes, and classes define the structure and behavior of objects.
2. Use the `class` keyword to define a class and create an object by calling the class name.
3. Object attributes: variables in the class, used to store the state of the object.
4. Object methods: functions in the class, used to describe the behavior of the object.
5. Construction method: `__init__` method, used to initialize object attributes.
6. Inheritance: Subclasses can inherit the attributes and methods of the parent class to achieve code reuse.
7. Polymorphism: Objects of different classes can use the same method name, but the specific implementation may be different.
8. Encapsulation: Hide the internal implementation details of the object and expose only the necessary interfaces to external access.
encryption
Symmetric encryption: AES (key, random number)
Asymmetric encryption: Algorithm asymmetry Key asymmetric (RSA
Array search
Find
binary search Binary search can be replaced by a binary tree
linear search
sort
Bubble(O(N^2))
Merge (O(N*log(N)))
Python web crawler
First: Do not crawl unauthorized websites and abide by robots.txt
No login required Log in directly with username and password Require verification code to log in
Crawler steps: initiate a request, obtain response content, parse content, and save data
Initiate a request: The request is initiated by using the http library to initiate a request to the target site, that is, sending a Request Get the response content: After the crawler sends the request, if the server can respond normally, it will get a Response Parsing content: parsing html data: parsing html data methods include using regular expressions and third-party parsing libraries such as Beautifulsoup Save data: The crawled data is saved locally in the form of files or the crawled content is saved directly in the database. The database can be MySQL, Mongdb, Redis, Oracle, etc...
Python data structures
Python list
List is one of the most commonly used data structures in Python. It is an ordered collection of elements, usually placed in [] Ordering: The elements in the list are ordered according to their position in the list, the first index is 0, the second is 1, and so on Mutability: elements in the list can be added, removed, and modified at any time as needed
Python tuple
A tuple is similar to a list. It is also an ordered collection of elements that can store different types of elements. However, once a tuple is created, it cannot be modified. Elements cannot be added, deleted, or modified to the tuple. Tuples are represented by parentheses (), and the elements are also separated by commas. Immutability: Tuples cannot be modified after they are created. Orderliness: The elements in the tuple also have positional relationships, and the elements in the tuple can be accessed through indexing and slicing operations.
Python dictionary
Dictionary is the only mapping type in Python, which stores key-value pairs. Keys in a dictionary must be unique, while values can be any type of data Dictionaries are represented by braces {}, with each key-value pair separated by commas. Unordered: The data in the dictionary is arranged in an unordered manner, which is different from the order of lists and tuples. Mutability: Dictionaries are mutable, key-value pairs can be added, deleted, or modified. Dictionaries are very powerful in Python and are often used to store data that needs to be looked up quickly. You can use keys to quickly access, modify, or delete corresponding values.
Python collection
A set is an unordered and non-repeating collection of elements Disorder: The elements in a set have no specific order. Non-repetition: All elements in the set are unique, no duplicate elements are allowed
Python string
Concatenation: Use the operator to concatenate two strings. Copy: Use the * operator to copy a string. Slicing: Use [start:stop:step] to obtain substrings of a string. Length: Use the len() function to get the length of a string. Search: Use find(), index(), startswith(), endswith() and other methods to find substrings or characters. Replacement: Use the replace() method to replace a substring. Split: Use the split() method to split a string into a list. Case conversion: Use upper(), lower(), capitalize(), title() and other methods to convert the case of strings. Remove whitespace: Use strip(), lstrip(), rstrip() methods to remove whitespace characters at both ends of the string. Determination: Use isalpha(), isdigit(), isalnum(), isspace() and other methods to determine the type of the string.
Python sequences
Sequence is another important type of data structure in Python, which contains an ordered set of elements. Index: Access elements in a sequence by index (position). Slicing: Use the slicing operation to access subsequences of a sequence. Add: Use the operator to join two sequences. Multiply: Use the * operator to repeat a sequence. Length: Use the len() function to get the length of the sequence. Maximum/Minimum Values: Use the max() and min() functions to get the maximum and minimum values in a sequence (for numeric sequences)
Python database operations
Python database added: insert sql = "INSERT INTO your_table (name, age, city) VALUES (%s, %s, %s)"
Connect to the database: Before doing anything, you need to connect to the database. This usually involves providing the hostname, port, user, password and database name import pymysql #Call python database conn = pymysql.connect(host='localhost', user='your_username', password='your_password', database='your_database') # Create connection cursor = conn.cursor() # Create a cursor object
Python database query: select sql = "SELECT * FROM your_table"
Python database deletion: delete sql = "DELETE FROM your_table WHERE name=%s"
Python database update: update sql = "UPDATE your_table SET age=%s, city=%s WHERE name=%s"
Close the database: cursor.close() # Close the cursor conn.close() # Close the connection