Setting Up the Environment and Your First Program#
Python is a simple and easy-to-learn high-level programming language with syntax close to plain English, making it ideal for beginners. It is widely used in:
- Data analysis and scientific computing : pandas, NumPy
- Machine learning and AI : TensorFlow, PyTorch
- Web backend development : Django, FastAPI
- Automation scripts : web scraping, batch processing
- Quantitative trading : strategy backtesting, data processing
Installing Python#
1. Download Python#
Go to the official Python website and download the latest version (3.10 or above recommended).
2. Important Notes During Installation#
On Windows, make sure to check “Add Python to PATH” during installation, otherwise you won’t be able to run the python command directly from the terminal later.
3. Verify the Installation#
Open a terminal (on Windows press Win + R and type cmd), then enter:
python --versionIf a version number appears (e.g., Python 3.12.0), the installation was successful.
Choosing an Editor#
| Editor | Suitable For | Description |
|---|---|---|
| VS Code | Beginner to Advanced | Free, rich extensions, most recommended |
| PyCharm | Intermediate to Advanced | Powerful Python-dedicated IDE |
| Jupyter Notebook | Data Analysis | Interactive execution, great for analysis and learning |
| IDLE | Beginners | Built into Python, simple and lightweight |
It is recommended to use VS Code and install the Python extension (search for “Python” and choose the one published by Microsoft).
Your First Python Program#
Method 1: Run from the Terminal#
Create a file called hello.py and enter the following:
| |
Run it from the terminal:
python hello.pyOutput:
Hello, World!Method 2: Interactive Mode#
Type python in the terminal to enter interactive mode, where you can execute code immediately:
| |
Type exit() or press Ctrl + Z (Windows) to exit interactive mode.
Basic Usage of print()#
print() is the most commonly used output function:
| |
Comments#
Text starting with # is a single-line comment and is ignored by Python when executed:
| |
Triple quotes create a multi-line string, which is also commonly used as a multi-line comment:
| |
Indentation Matters#
Python uses indentation (spaces or tabs) to define code blocks. This is the biggest difference between Python and most other languages.
| |
It is recommended to consistently use 4 spaces as the indentation unit.