๐Ÿ Introduction to Python
Module 1 ยท Topic 5

Your First Python Program

Write, understand, and run your first Python program. Learn the anatomy of Python code.

Theory

Writing Your First Program:

The classic first program in any language prints "Hello, World!" โ€” in Python, this is just one line:

print("Hello, World!")  

Anatomy of This Program:

  • print โ€” A built-in function (one of 71 built-in functions in Python)
  • () โ€” Parentheses to call the function
  • "Hello, World!" โ€” A string argument (can use single or double quotes)

Key Things About Python Code:

  1. No semicolons โ€” Line endings mark statement boundaries
  2. No curly braces โ€” Indentation defines code blocks
  3. No main function โ€” Code executes top to bottom
  4. No compilation step โ€” Just run: python filename.py
  5. Case-sensitive โ€” Print is NOT the same as print

How print() Works:

  • Accepts multiple arguments: print("a", "b", "c") โ†’ a b c
  • sep parameter: separator between arguments (default: space)
  • end parameter: what to print at the end (default: newline \n)
  • Automatically converts non-string arguments to strings
Syntax
# Basic print
print("Hello, World!")

# print() parameters
print(value1, value2, sep=" ", end="\n")

# Run a Python file
# python filename.py