Skip to content

Latest commit

Β 

History

History
167 lines (125 loc) Β· 2.75 KB

File metadata and controls

167 lines (125 loc) Β· 2.75 KB

🐍 01 – Setup & First Program

🎯 What You'll Learn

  • Install Python and verify it works
  • Understand the REPL (interactive shell)
  • Write and run your first Python script
  • Know the difference between running JS and Python

πŸ“Œ JS vs Python β€” Side by Side

Task JavaScript (Node) Python
Check version node --version python3 --version
Run a file node app.js python3 hello.py
Print output console.log("Hi") print("Hi")
Interactive shell node python3
Exit shell .exit or Ctrl+C exit() or Ctrl+D
Package manager npm pip
File extension .js .py

πŸ’‘ Installing Python

Download from https://python.org β€” always install Python 3.10 or newer.

# Verify installation
python3 --version
# Python 3.12.0

pip3 --version
# pip 23.x

Windows users: Check "Add Python to PATH" during installation.


πŸ’‘ Your First Program

JavaScript

// hello.js
console.log("Hello, World!");
console.log("My name is Ahmed");
node hello.js
# Hello, World!
# My name is Ahmed

Python

# hello.py
print("Hello, World!")
print("My name is Ahmed")
python3 hello.py
# Hello, World!
# My name is Ahmed

Key difference: print() replaces console.log(). No semicolons. No curly braces.


πŸ’‘ The REPL (Interactive Shell)

The REPL lets you type Python and see results immediately β€” perfect for experimenting.

JavaScript REPL

$ node
> 2 + 2
4
> "hello".toUpperCase()
'HELLO'
> .exit

Python REPL

$ python3
>>> 2 + 2
4
>>> "hello".upper()
'HELLO'
>>> exit()

The >>> is Python's prompt. Each line runs immediately.


πŸ’‘ Running Python Files

# Create a file
touch hello.py

# Run it
python3 hello.py

# Run with output
python3 -c "print('Hello from command line')"

πŸ’‘ Recommended Setup

VS Code
  └── Python extension (ms-python.python)
      β”œβ”€β”€ IntelliSense (autocomplete)
      β”œβ”€β”€ Linting (catches errors)
      └── Debugger (breakpoints)

πŸ§ͺ Practice

# Try this in your REPL or a file
print("Hello, World!")
print(2 + 2)
print(10 * 5)
print("Ahmed" + " " + "Bro")
print(type(42))
print(type("hello"))

Expected output:

Hello, World!
4
50
Ahmed Bro
<class 'int'>
<class 'str'>

⚠️ Common Mistakes

Mistake Wrong Right
Using JS syntax console.log("hi") print("hi")
Adding semicolons print("hi"); print("hi")
Wrong command python hello.py python3 hello.py
Python 2 python --version β†’ 2.7 Must be 3.x

πŸ”— Next Lesson

πŸ‘‰ 02 – Variables & Data Types