Introduction
Installation
Due to space limitations, please refer to online tutorials (it is recommended to use Anaconda for Python).
Code Repository
How to Run
For example, printing “Hello World”:
1 | # main.py file |
1 | python main.py |
Variable Definition and Data Types
A variable is an identifier that points to a specific address in memory, typically used to store data.
Data types represent the type of a variable, determining the amount of memory space it occupies.
Assignment involves storing data (value) at the address pointed to by the variable, allowing subsequent retrieval using
this variable.
1 | # Example: Defining variables of different types |
Arrays/Lists/Dictionaries|Maps/Sets
1 | # Define a list |
Control Flow
Control flow defines the execution order of our program.
Sequential
Sequential execution runs from top to bottom, which is the normal execution flow of our program.
Selection
Selection executes different code based on different conditions.
The selection process is divided into single branch and multiple branches.
Single Branch
Single branch refers to having only one branch node, with only one conditional judgment.
1 | # Example: Single branch if statement |
Multiple Branches
Multiple branches have multiple branch nodes and multiple conditional judgments (if-elif-else | switch-case).
1 | # Example: Multiple branch if-elif-else statement |
Loops
Loops represent a repeated execution process.
1 | # Example: for loop iterating over a list |
Functions
The essence of a function is a closure with its own scope.
We can define a piece of code as a function, accepting 0 or more inputs, executing the code within the function body,
and returning 0 or more outputs at the end.
Using functions can extract common logic and simplify our code.
1 | # Example: Define a function and call it |
Classes/Structs
Classes/Structs
A class is an abstract structure containing data and methods (functions). We can define it, and to use a class, we need
to instantiate it, which essentially means allocating a specified amount of space in memory to hold it.
The size of a class depends on what data is defined inside it (e.g., int), and the compiler automatically decides how
much space to allocate based on the data size.
A class can have multiple instantiated objects, meaning multiple different variables, but these variables all conform to
the structure of the class.
1 | # Example: Define a class and create an instance |
Interfaces
Interface syntax is a way of defining behavior specifications. It describes which methods (functions) a certain type
should have, without caring about how these methods are implemented.
An interface is an abstract contract:
- It only defines method names, parameters, and return values.
- It does not contain any specific implementation (logic code).
- A type is called “implementing the interface” as long as it implements all the methods defined in the interface.
1 | # Example: Using the abc module to simulate an interface |
Frameworks
To simplify development, programmers extract common logic, encapsulating it into functions or classes and methods, thus
simplifying development. During this continuous simplification process, frameworks are born.
However, in my understanding, a library (library) is a collection of extracted common methods and classes, and users can
add many different libraries as they like; while a framework (framework) is more like a set of project specifications
and templates, and then users develop based on the framework while adhering to its agreed standards or structure;
however, this boundary is often not very clear, and the two terms are frequently used interchangeably.
Web
The programs we write currently run locally. To allow users around the world to use them, we need to make them available
on the network, and web frameworks encapsulate the language’s own networking libraries and provide various methods for
offering network services.
Commonly used web frameworks in the Python language are Flask, FastAPI, Django. Here we take FastAPI as an example.
1 | pip install fastapi uvicorn -i https://pypi.tuna.tsinghua.edu.cn/simple |
1 | from fastapi import FastAPI |
Visit localhost:8080 to view. Swagger UI: http://127.0.0.1:8000/docs ReDoc: http://127.0.0.1:8000/redoc.
Databases (DB)
We currently use variables to store data, but the data in variables is placed in memory. Once the program stops, the
data in memory will be reclaimed. The next time the program starts, the operating system may allocate a different memory
space, so we need persistent storage for our data, which requires the use of database systems.
Here we take SQLAlchemy as an example:
1 | pip install sqlalchemy -i https://pypi.tuna.tsinghua.edu.cn/simple |
1 | from sqlalchemy import create_engine, Column, Integer, String |
Expansion
AI Direction:
- Data Analysis | Machine Learning | Deep Learning | Reinforcement Learning
- numpy (Numerical Operations) | pandas (Data Loading and Processing) | matplotlib (Visualization)
- scikit-learn (Machine Learning) | TensorFlow | PyTorch (Deep Learning)
- Implementation of various machine learning models | Deep Learning Neural Networks
- langchain | llama-index for Large Model Applications
Multithreading/Microservices/Reflection-Dynamic Proxy/File Operations/Network Programming
Principles of Frameworks/Handwritten Code
wasm/gRPC
Community
You can contact me on these platforms:
- Bilibili: GangziGeForever
- QQ Group: 940263820
- Gitee: gitee
- Blog: malcode-site
- Email: malguy2022@163.com
- Zhihu: LeMiaoShanZhaiJuShi
- CSDN: FeiNiaoMalred