🌱BeginnerPython Fundamentals

Introduction to Python

What Python is, how to run it, and why it is one of the most popular languages in the world.

Overview

Python is a high-level, general-purpose programming language created by Guido van Rossum and first released in 1991. Its design philosophy emphasizes code readability Python code often reads almost like plain English, making it one of the most approachable languages for beginners while remaining powerful enough for professional use. Python runs on virtually every platform (Windows, macOS, Linux) and powers everything from quick automation scripts to large-scale web applications (Django, FastAPI), data science pipelines (NumPy, Pandas), machine learning models (TensorFlow, PyTorch), and system tools. Its package ecosystem on PyPI has over 500,000 packages covering almost every domain imaginable. Python is an interpreted language you write a .py file and run it with the python command; no compilation step is needed. The interactive REPL (Read-Eval-Print Loop) lets you run Python expressions one line at a time, making it ideal for exploration and learning. The language uses indentation (whitespace) to define code blocks instead of curly braces, which enforces a consistent style across all Python code.

Key Points

  • •Python is interpreted: write .py files and run them with `python filename.py` no compile step
  • •Uses indentation (4 spaces by default) to define blocks inconsistent indentation is a syntax error
  • •Dynamically typed: you don't declare variable types; Python infers them at runtime
  • •The REPL (`python` or `python3` in your terminal) lets you run code line by line interactively
  • •print() is the standard way to output text; the # character starts a comment
  • •Python 3 (current) and Python 2 (end-of-life 2020) are different always use Python 3

Examples

Your first Python program

print("Hello, Python!")

print() writes to standard output and adds a newline by default.

Comments and basic expressions

# This is a comment Python ignores everything after #
print(2 + 2)        # 4
print(10 / 3)       # 3.3333...
print(10 // 3)      # 3  (integer division)
print(10 % 3)       # 1  (remainder)
print(2 ** 8)       # 256 (exponentiation)

Using the built-in help and type functions

print(type(42))       # <class 'int'>
print(type(3.14))     # <class 'float'>
print(type("hello"))  # <class 'str'>
print(type(True))     # <class 'bool'>

type() is useful when you are unsure what kind of value you are working with.

Common Mistakes

  • Mixing tabs and spaces for indentation use 4 spaces consistently (most editors do this automatically)
  • Running `python` and getting Python 2 on some systems use `python3` explicitly if unsure
  • Forgetting parentheses: `print "hello"` is Python 2 syntax; Python 3 requires `print("hello")`

Note

Open your terminal and type `python3` (or `python`) to enter the REPL. Try expressions like `2 ** 10`, `"hello".upper()`, or `len("Python")` to explore the language interactively.

Exercises

Write Python code to solve each exercise. Run it in your browser and check your output.

Loading editor…

Completed: 0 / 5 exercises

Knowledge Check

Question 1 of 4

How does Python define code blocks (such as the body of an if statement)?