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 --version

If a version number appears (e.g., Python 3.12.0), the installation was successful.


Choosing an Editor#

EditorSuitable ForDescription
VS CodeBeginner to AdvancedFree, rich extensions, most recommended
PyCharmIntermediate to AdvancedPowerful Python-dedicated IDE
Jupyter NotebookData AnalysisInteractive execution, great for analysis and learning
IDLEBeginnersBuilt 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:

1
print("Hello, World!")

Run it from the terminal:

python hello.py

Output:

Hello, World!

Method 2: Interactive Mode#

Type python in the terminal to enter interactive mode, where you can execute code immediately:

1
2
3
4
>>> print("Hello, World!")
Hello, World!
>>> 1 + 2
3

Type exit() or press Ctrl + Z (Windows) to exit interactive mode.


Basic Usage of print()#

print() is the most commonly used output function:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# Output text
print("Python is easy to learn!")

# Output numbers
print(42)
print(3.14)

# Output multiple values at once (separated by spaces)
print("My age is", 25)

# Use sep to customize the separator
print("2026", "04", "11", sep="-")
# Output: 2026-04-11

# Use end to change the ending character (default is newline \n)
print("First line", end=" ")
print("on the same line")
# Output: First line on the same line

Comments#

Text starting with # is a single-line comment and is ignored by Python when executed:

1
2
3
4
5
6
# This is a single-line comment
print("Hello")  # This is also a comment, written after the code

# Multi-line content can use # on each line
# First line of description
# Second line of description

Triple quotes create a multi-line string, which is also commonly used as a multi-line comment:

1
2
3
4
5
6
"""
This is a multi-line string
that can span multiple lines.
It is typically used to describe the purpose of a function or module.
"""
print("Program continues executing")

Indentation Matters#

Python uses indentation (spaces or tabs) to define code blocks. This is the biggest difference between Python and most other languages.

1
2
3
4
if True:
    print("This line is indented and belongs to the if block")
    print("This line too")
print("This line has no indentation and does not belong to the if block")

It is recommended to consistently use 4 spaces as the indentation unit.