JSTAcademy
0 XP
Dashboard
Crash Courses
Environment, Syntax & Your First Python Program
12 min
Basic+150 XP
Crash Courses · Basic

Environment, Syntax & Your First Python Program

Install Python, configure VS Code, and write real code using variables, f-strings, and the type system.
12 min read+150 XP on completionCert: Python Crash Course
Tap any word in the text below to start reading from there.

Environment, Syntax & Your First Python Program

Why Python?

Python is the top language for AI/ML, data science, scripting, and backend APIs. Its syntax is closer to plain English than any other production language — which makes it the best first language and a powerful second one. Django, FastAPI, pandas, TensorFlow — they're all Python.

Before a single line: your environment must be correct.

---

Installing Python

Download Python 3.12+ from python.org/downloads. During install on Windows, check "Add Python to PATH" — this is critical.

Verify in terminal:

python --version      # Windows
python3 --version     # macOS/Linux

---

VS Code Setup

Install these extensions:

  1. Python (Microsoft) — syntax highlighting, IntelliSense, linting
  2. Pylance — fast type checking and autocomplete
  3. Python Indent — fixes VS Code's indentation handling

Create your project and virtual environment:

mkdir python-crash-course
cd python-crash-course
python -m venv .venv

# Activate it:
.venv\Scripts\activate     # Windows
source .venv/bin/activate  # macOS/Linux

# VS Code: Ctrl+Shift+P → "Python: Select Interpreter" → pick .venv

Run any file:

python main.py

---

Variables and Dynamic Typing

name = "Jordan"          # str
age = 28                 # int
height = 5.11            # float
is_active = True         # bool (True/False — capital T and F)
nothing = None           # NoneType — Python's null

# Python is dynamically typed — types are checked at runtime, not compile time
x = 10
x = "now a string"      # perfectly valid

# Check types at runtime
print(type(name))        # <class 'str'>
print(type(age))         # <class 'int'>
print(type(nothing))     # <class 'NoneType'>

---

f-strings: The Right Way to Format Strings

name = "Marcus"
year = 2026
score = 94.756

# Basic f-string
print(f"Hello, {name}!")                   # Hello, Marcus!

# Expressions inside braces
print(f"Next year: {year + 1}")            # Next year: 2027

# Format specifiers
print(f"Score: {score:.2f}")               # Score: 94.76
print(f"Padded: {name:>10}")               # Padded:     Marcus
print(f"Year: {year:,}")                   # Year: 2,026

# Multi-line (use parentheses — Python's implicit line continuation)
message = (
    f"Name: {name}\n"
    f"Year: {year}\n"
    f"Score: {score:.1f}%"
)
print(message)

---

Python Arithmetic and String Operations

# Arithmetic
print(10 + 3)   # 13
print(10 - 3)   # 7
print(10 * 3)   # 30
print(10 / 3)   # 3.3333... (always returns float)
print(10 // 3)  # 3 (integer/floor division)
print(10 % 3)   # 1 (remainder/modulo)
print(2 ** 8)   # 256 (exponentiation)

# String operations
greeting = "hello"
print(greeting.upper())             # HELLO
print(greeting.capitalize())        # Hello
print(greeting.replace("l", "r"))   # herro
print(len(greeting))                # 5
print("ell" in greeting)            # True
print(greeting * 3)                 # hellohellohello

---

Multiple Assignment and Unpacking

# Multiple assignment in one line
x, y, z = 10, 20, 30
print(x, y, z)          # 10 20 30

# Swap without a temp variable
x, y = y, x
print(x, y)             # 20 10

# Augmented assignment
count = 0
count += 1   # equivalent to count = count + 1
count *= 2   # count = count * 2

---

Python's Indentation Rule

Python uses indentation (4 spaces) instead of braces to define code blocks. This is not optional:

# CORRECT — 4-space indent inside if block
if True:
    print("indented correctly")
    print("same block")

# INCORRECT — inconsistent indent causes IndentationError
if True:
    print("correct")
  print("wrong indent")  # IndentationError!

VS Code auto-handles this if you installed the Python extension.

0%