python_basics_course โ€” belajar-python.py

Interactive Python Course

Learn Python like you're reading code, not a textbook.

A hands-on, click-and-run introduction to Python โ€” from "what even is programming" to writing your first data-type conversions. Every module is a file. Every concept has a console to try it in.

 python3
1991Year Python was first released to the world
#1Rank on the TIOBE Index, Feb 2026 (21.81% share)
47.2M+Developers worldwide, SlashData 2025
๐ŸŽญNamed after a comedy troupe โ€” not the snake
01

What Is Python, Really?

# 1.1 โ€” Definition

Python is a high-level, interpreted, general-purpose programming language built around one radical idea: code should be easy for humans to read, not just machines. No mandatory semicolons, no curly braces โ€” just clean, indented blocks that read almost like plain English.

hello.pypython3 hello.py
# This is a complete, runnable Python program print("Python was built to be readable.")
FUN FACT

Python wasn't named after the snake. Creator Guido van Rossum was reading scripts from Monty Python's Flying Circus while building the language in the late 1980s and simply liked the sound of it โ€” he wanted a name that was "short, unique, and slightly mysterious." Source: Python.org official FAQ

HISTORY

Guido van Rossum started implementing Python as a hobby project over the Christmas holidays in December 1989 at CWI (Centrum Wiskunde & Informatica) in the Netherlands. Python 0.9.0 went public in February 1991. Source: python.org / Guido van Rossum's own history notes

# 1.2 โ€” Programming vs. Coding

These two words get used interchangeably, but they describe different scopes of work. Tap each one below.

๐Ÿ’ฌ Coding โ€” the act of writing

Coding is the narrow, literal act of translating an idea into syntax a computer can execute โ€” typing lines like print("hi"). It's the typing itself.

Think of it like laying individual bricks: precise, technical, one instruction at a time.

๐Ÿ—๏ธ Programming โ€” the whole process

Programming is the entire engineering journey: understanding the problem, designing the logic, writing the code, testing it, debugging it, and maintaining it over time. Coding is just one step inside programming.

Think of it like architecting and building an entire house โ€” bricklaying (coding) is one job on a much bigger site.

# 1.3 โ€” Applications of Python

One language, an absurd number of industries. Here's where Python actually shows up in the real world:

๐ŸŒ

Web Development

Backends for Instagram, Spotify & Pinterest run on Python frameworks like Django and Flask.

๐Ÿ“Š

Data Science

pandas and NumPy turn messy spreadsheets into insight โ€” the default toolkit for analysts.

๐Ÿค–

AI & Machine Learning

TensorFlow, PyTorch and scikit-learn are all Python-first โ€” the language of modern AI research.

โš™๏ธ

Automation & Scripting

Renaming 10,000 files, scraping a website, scheduling a task โ€” Python glues systems together.

๐ŸŽฎ

Game Development

Libraries like Pygame make it a friendly first step into interactive, graphical programming.

๐Ÿ”

Cybersecurity

Widely used for writing penetration-testing tools, malware analysis and network scanners.

REAL DATA

Python is the most widely used language in AI-tagged repositories on GitHub, and it saw the largest single-year jump of any language in the Stack Overflow Developer Survey โ€” up 7 percentage points from 2024 to 2025. Source: Stack Overflow Developer Survey 2025 ยท GitHub language data

# 1.4 โ€” IDE Setup Checklist

An IDE (Integrated Development Environment) is where you'll actually write and run code. Check off each step as you go โ€” this is exactly what you'd do on a fresh computer.

โœ“

Download Python from python.org

Grab the latest stable release for your OS. On install, tick "Add Python to PATH" (Windows) so your terminal can find it.

โœ“

Verify the install

Open a terminal and run python --version. You should see something like Python 3.13.0.

โœ“

Pick an editor

VS Code (lightweight, huge extension library) or PyCharm (batteries-included) are the two most common. Thonny is great for absolute beginners.

โœ“

Create your first file

Make a file named main.py. The .py extension is what tells your computer (and editor) "this is Python."

โœ“

Run it

In the terminal: python main.py. Or just hit the โ–ถ Run button most editors give you.

0 / 5 steps complete
02

Syntax, Comments & Your First Program

# 2.1 โ€” Syntax basics

Python's biggest personality trait: indentation is the syntax. No curly braces define a block โ€” whitespace does. Compare the same idea in Python vs. a brace-based language:

Pythonindentation = structure
if age >= 18: print("You can vote")
Java / C-stylebraces = structure
if (age >= 18) { System.out.println("You can vote"); }

Other core rules: Python is case-sensitive (Name โ‰  name), one statement usually lives per line, and a colon : always signals "a new block starts here."

# 2.2 โ€” Comments

Comments are lines the interpreter completely ignores โ€” they exist purely for humans. Use # for a single line, or triple quotes for a block.

comments.pytoggle below
# This line explains what happens next print("This line always runs") print("This line is commented out โ€” try toggling it") """ A multi-line comment (docstring-style) โ€” great for explaining a whole block at once. """

# 2.3 โ€” print()

print() is how Python talks back to you. Edit the text below and run it.

print_playground.pylive
// output appears here

# 2.4 โ€” input()

input() pauses your program and waits for the user to type something โ€” and whatever they type always comes back as a string, even if it looks like a number.

input_playground.pylive
// program: name = input("What's your name? ") โ†’ print(f"Hello, {name}!")
GOOD TO KNOW

input() ALWAYS returns text โ€” even input("Age: ") when someone types "25" gives you the string "25", not the number 25. You'll need type conversion (module 04) to do math with it.

# 2.5 โ€” Writing your first program

Every programmer's first ritual. Hit run.

first_program.pyready
# my very first Python program name = input("What's your name? ") print("Hello,", name, "โ€” welcome to Python!")
// click Run โ€” it'll reuse the name from the input() demo above
FUN FACT

The "Hello, World!" tradition is widely traced to Brian Kernighan's 1978 book on the C programming language โ€” and decades later, it's still the unofficial rite of passage for every new programmer, in every language, Python included.

03

Variables: Naming, Assignment & Storage

# 3.1 โ€” What is a variable?

Think of a variable as a labeled storage locker. The label is the name you choose; what's inside the locker is the value. Python doesn't make you declare a type up front โ€” it figures that out from whatever value you assign.

age
โ†’
17

# 3.2 โ€” Naming rules

RuleExample
Must start with a letter or underscoreโœ” _score, name
Cannot start with a digitโœ˜ 1score
Only letters, digits & underscores after thatโœ˜ user-name
Case-sensitiveAge โ‰  age
Can't be a reserved keywordโœ˜ class, for, True
Convention: snake_caseโœ” total_price

Try it yourself โ€” type any name below and see if Python would accept it:

name_validator.pylive

# 3.3 โ€” Assignment

The = operator assigns a value to a name โ€” read it as "gets set to," not "equals."

assignment.pypython3
score = 90 # single assignment x, y, z = 1, 2, 3 # multiple in one line a = b = c = 0 # chained assignment a, b = b, a # swap โ€” no temp variable needed!
FUN FACT

That last line is a small piece of Python magic: swapping two variables normally needs a third "temporary" holder in most languages. Python does it in one clean line because it builds a tuple on the right side first, then unpacks it. It's one of the most-loved examples of "Pythonic" code.

# 3.4 โ€” How Python stores data

Under the hood, a variable name is really just a reference โ€” a sticky note pointing at a value living in memory. That's why reassigning a name doesn't change the old value; it just moves the sticky note to point somewhere new. This is also why Python variables can freely be reassigned to a completely different type at any time โ€” dynamic typing in action.

04

Data Types & Type Conversion

# 4.1 โ€” The four basics

Every value in Python belongs to a type. These four are where every beginner starts:

int โ€” Integer
age = 25 โ†’ type(age) is int

Whole numbers, positive or negative, no decimal point.

float โ€” Floating point
price = 19.99 โ†’ type(price) is float

Numbers with a decimal point โ€” used for anything requiring precision beyond whole units.

str โ€” String
name = "Aisyah" โ†’ type(name) is str

Text, wrapped in single or double quotes. Even "123" is a string, not a number.

bool โ€” Boolean
is_active = True โ†’ type(is_active) is bool

Only two possible values: True or False โ€” the backbone of every decision your code makes.

# 4.2 โ€” Type conversion (casting)

Use int(), float(), str(), or bool() to explicitly convert a value from one type to another. Try it:

type_playground.pylive
// try converting "42", "3.14", "hello", or "" (empty)
GOOD TO KNOW

Not every conversion is legal. int("hello") raises a ValueError because Python has no idea what number "hello" is supposed to be. Converting downward (float โ†’ int) also truncates โ€” it doesn't round: int(9.9) is 9, not 10.

# 4.3 โ€” Quick quiz: name that type

"25"
Score: 0 / 0
05

History Log & What's Next for Python

# git log --oneline --graph python-history

Dec 1989

Guido van Rossum begins writing Python as a Christmas-holiday hobby project at CWI in the Netherlands, as a successor to the ABC language.

Feb 1991

Python 0.9.0 is released publicly โ€” already featuring functions, exception handling, and core data types like strings and lists.

2000

Python 2.0 arrives, introducing list comprehensions and a full garbage collector.

2008

Python 3.0 ships โ€” a deliberate, backward-incompatible cleanup of the language's inconsistencies.

2018

Guido van Rossum steps down as Python's "Benevolent Dictator For Life," handing governance to an elected steering council.

Jan 2020

Python 2 officially reaches end-of-life โ€” the whole ecosystem fully shifts to Python 3.

Jul 2025

Python peaks at 26.98% on the TIOBE Index โ€” the highest rating any language has recorded in the index's 24-year history.

Feb 2026

Python holds #1 on TIOBE at 21.81% โ€” more than ten percentage points ahead of #2, its widest lead ever logged.

# Where Python is headed

๐Ÿ† Still #1, by a mile

Python leads the TIOBE Index at 21.81% (Feb 2026) โ€” more than double its nearest competitor, C. (Source: TIOBE Index, Feb 2026)

๐Ÿง  The language of AI

TensorFlow, PyTorch and scikit-learn are all Python-first, cementing it as the default language for machine learning research and production. (Source: Stack Overflow Survey 2025)

๐Ÿ“ˆ Fastest-growing adoption

Python usage grew 7 percentage points year-over-year in the 2025 Stack Overflow Developer Survey โ€” the largest single-year jump of any language tracked. (Source: Stack Overflow Developer Survey 2025)

๐Ÿ’ผ Leading the job market

Python leads U.S. programming job listings with 64,000+ open roles โ€” ahead of Java (~43K) and JavaScript (~30K). (Source: GKDrift labor-market data, 2025)

None of this makes Python "the best" language for everything โ€” Rust wins on raw performance and salary premium, JavaScript still owns the browser. But for beginners, for data, and for AI, the numbers point the same direction: Python isn't going anywhere.