Part of Python for Beginners

Introduction to Python - Your First Program | Python Tutorial (Lesson 1)

Sandy LaneSandy Lane

Video: Introduction to Python - Your First Program | Python Tutorial (Lesson 1) by Taught by Celeste AI - AI Coding Coach

Take the quiz on the full lesson page
Test what you've read · interactive walkthrough

Your First Python Program

print("Hello, World!"). One line, one function call. No main, no #include, no compile step. The shortest possible "I have a working program."

Python is the most popular programming language in the world for beginners and experts alike — readable syntax, batteries-included standard library, used everywhere from web servers to data science to scripting. This series walks you through it from zero.

The full program

# My first Python program
print("Hello, World!")
print("Welcome to Python!")

Three lines. The # line is a comment — Python ignores it. The two print(...) calls each output text to your terminal.

Run it

Save as hello.py. From a terminal:

python hello.py

You should see:

Hello, World!
Welcome to Python!

That's it — no gcc, no compile, no int main(). Python interprets your script: reads it line by line, runs each.

What print does

print(value) writes value to standard output, followed by a newline.

print("Hello")              # one string
print("Hello", "World")     # two values, space-separated by default
print(42)                   # numbers work too
print(3.14)
print(True)

print accepts any number of arguments. Output is space-separated. The trailing newline is automatic.

Strings: single or double quotes

print('Hello')      # single quotes
print("Hello")      # double quotes
print('She said "hi"')   # mix to embed quotes
print("It's me")

Both work identically. Pick the one that doesn't conflict with the content.

For multi-line strings, use triple quotes:

print("""
Multiple
lines
""")

Comments

# Single-line comment

"""
Multi-line "comment"
(actually a string that's just discarded)
"""

Comments document why something is there — they don't run. Use them sparingly to explain why, not what (the code already says what).

Print to a file

with open("output.txt", "w") as f:
    print("hello", file=f)

Same print — the file= keyword redirects output. We dive into file I/O in Lesson 15.

Beyond hello world

print("Hello,", "Python!")          # space-separated
print("Hello", "Python", sep="-")   # custom separator
print("Loading", end="")             # no newline
print("...", end="")
print(" Done!")

sep= controls what goes between args. end= controls what goes after (default "\n").

These are the building blocks for formatted output. We cover the f-string syntax (the modern way to format) in lesson 3.

Python vs other languages

Compared to other "first programs":

// C — six lines
#include <stdio.h>
int main() { printf("Hello\n"); return 0; }
// Java — five lines, lots of ceremony
public class Main {
  public static void main(String[] args) {
    System.out.println("Hello");
  }
}
# Python — one line
print("Hello")

Python's design favors readability. No braces, no semicolons, no boilerplate. What you write is what runs.

The REPL

You can also run Python interactively:

python
>>> print("Hello")
Hello
>>> 2 + 2
4
>>> exit()

The >>> prompt is Python's REPL (Read-Eval-Print Loop). Type expressions, see their values immediately. Great for experimenting.

For a richer REPL with syntax highlighting, autocomplete, and history: install IPython (pip install ipython) — covered when we get to packages.

Common stumbles

Forgetting parentheses on print. Python 3 requires them. print "hello" (Python 2 style) errors with a syntax error.

Mixing tabs and spaces in indentation. Python is picky about whitespace. Pick one (4-space indents is the convention) and stick with it.

Saving as .txt instead of .py. Both work for python file.txt, but the .py extension is what your editor and tools expect.

Running with python2 instead of python3. On some systems, plain python is Python 2 — long obsolete. Use python3 to be safe.

Not seeing output. If your script has no print, it computes silently. The result of 2 + 2 in a script doesn't print — only in the REPL.

What's next

Lesson 2: variables and data types. name = "Alice", the four basic types (str, int, float, bool), and Python's dynamic typing.

Recap

print("text") is the simplest Python program. python file.py runs it. No compile step. Strings: single or double quotes; triple for multi-line. # for comments. print accepts multiple args (space-separated by default), and sep=/end= keyword arguments customize the layout. Use the REPL (python interactive) for quick experiments.

Next lesson: variables and data types.

Ready? Take the quiz on the full lesson page →
Test what you've learned. Watch the lesson and try the interactive quiz on the same page.