๐ 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:
- No semicolons โ Line endings mark statement boundaries
- No curly braces โ Indentation defines code blocks
- No main function โ Code executes top to bottom
- No compilation step โ Just run:
python filename.py - Case-sensitive โ
Printis NOT the same asprint
How print() Works:
- Accepts multiple arguments:
print("a", "b", "c")โa b c sepparameter: separator between arguments (default: space)endparameter: 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