Belajar Python untuk Pemula 2026: Tutorial Lengkap dari Nol
Python adalah bahasa pemrograman paling populer di 2026! Easy to learn, powerful, dan banyak job opportunities. Di tutorial ini, kita belajar Python dari nol sampai bisa bikin project sendiri.
Kenapa Belajar Python?
Easy to Learn
# Hello World in Python
print("Hello, World!")
# Compare with Java
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Python jauh lebih simple!
Versatile
- Web Development (Django, Flask)
- Data Science & AI
- Automation & Scripting
- Game Development
- Desktop Apps
- IoT & Robotics
High Demand
- Gaji: Rp 8-20 juta/bulan
- 50.000+ job openings
- Remote work friendly
- Freelance rate tinggi
Large Community
- Banyak tutorial gratis
- Library lengkap (400.000+)
- Stack Overflow support
- Active forums
Setup Python
Install Python
Download: https://python.org (Python 3.12+)
# Check installation
python --version
# or
python3 --version
Code Editor
VS Code (Recommended)
- Download: https://code.visualstudio.com
- Install Python extension
- Install Pylance
Alternatives:
- PyCharm (IDE lengkap)
- Jupyter Notebook (data science)
- Sublime Text
- Atom
First Program
# hello.py
print("Hello, Python!")
print("Welcome to programming")
Run:
python hello.py
Python Basics
Variables & Data Types
# Numbers
age = 25
price = 99.99
complex_num = 3 + 4j
# Strings
name = "John Doe"
message = 'Hello World'
multiline = """This is
a multiline
string"""
# Boolean
is_active = True
is_admin = False
# None (null)
result = None
# Type checking
print(type(age)) # <class 'int'>
print(type(name)) # <class 'str'>
Operators
# Arithmetic
10 + 5 # 15
10 - 5 # 5
10 * 5 # 50
10 / 5 # 2.0
10 // 5 # 2 (floor division)
10 % 3 # 1 (modulo)
10 ** 2 # 100 (power)
# Comparison
10 == 10 # True
10 != 5 # True
10 > 5 # True
10 <= 10 # True
# Logical
True and False # False
True or False # True
not True # False
Input/Output
# Input
name = input("Enter your name: ")
age = int(input("Enter your age: "))
# Output
print("Hello,", name)
print(f"You are {age} years old") # f-string
print("Name: {} Age: {}".format(name, age))
Conditional Statements
age = 18
if age >= 18:
print("Adult")
elif age >= 13:
print("Teenager")
else:
print("Child")
# Ternary operator
status = "Adult" if age >= 18 else "Minor"
Loops
# For loop
for i in range(5):
print(i) # 0, 1, 2, 3, 4
for i in range(1, 6):
print(i) # 1, 2, 3, 4, 5
# While loop
count = 0
while count < 5:
print(count)
count += 1
# Break & Continue
for i in range(10):
if i == 3:
continue # skip 3
if i == 7:
break # stop at 7
print(i)
Data Structures
Lists (Array)
# Create list
fruits = ["apple", "banana", "orange"]
numbers = [1, 2, 3, 4, 5]
mixed = [1, "hello", True, 3.14]
# Access
print(fruits[0]) # apple
print(fruits[-1]) # orange (last)
# Modify
fruits[1] = "mango"
fruits.append("grape")
fruits.insert(0, "kiwi")
fruits.remove("apple")
fruits.pop() # remove last
# Slicing
print(numbers[1:4]) # [2, 3, 4]
print(numbers[:3]) # [1, 2, 3]
print(numbers[2:]) # [3, 4, 5]
# Methods
len(fruits)
fruits.sort()
fruits.reverse()
Tuples (Immutable)
coordinates = (10, 20)
rgb = (255, 128, 0)
# Cannot modify
# coordinates[0] = 15 # Error!
# Unpacking
x, y = coordinates
r, g, b = rgb
Dictionaries (Key-Value)
# Create
person = {
"name": "John",
"age": 25,
"city": "Jakarta"
}
# Access
print(person["name"])
print(person.get("age"))
# Modify
person["age"] = 26
person["email"] = "john@example.com"
del person["city"]
# Methods
person.keys()
person.values()
person.items()
Sets (Unique)
numbers = {1, 2, 3, 4, 5}
numbers.add(6)
numbers.remove(3)
# Operations
set1 = {1, 2, 3}
set2 = {3, 4, 5}
set1.union(set2) # {1, 2, 3, 4, 5}
set1.intersection(set2) # {3}
set1.difference(set2) # {1, 2}
Functions
Basic Function
def greet(name):
print(f"Hello, {name}!")
greet("John")
# Return value
def add(a, b):
return a + b
result = add(5, 3)
Default Parameters
def greet(name, greeting="Hello"):
print(f"{greeting}, {name}!")
greet("John") # Hello, John!
greet("Jane", "Hi") # Hi, Jane!
*args & **kwargs
def sum_all(*args):
return sum(args)
print(sum_all(1, 2, 3, 4)) # 10
def print_info(**kwargs):
for key, value in kwargs.items():
print(f"{key}: {value}")
print_info(name="John", age=25)
Lambda Functions
square = lambda x: x ** 2
print(square(5)) # 25
# With map, filter
numbers = [1, 2, 3, 4, 5]
squared = list(map(lambda x: x**2, numbers))
evens = list(filter(lambda x: x % 2 == 0, numbers))
Object-Oriented Programming
Classes & Objects
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
def greet(self):
print(f"Hi, I'm {self.name}")
def birthday(self):
self.age += 1
# Create object
person1 = Person("John", 25)
person1.greet()
person1.birthday()
Inheritance
class Student(Person):
def __init__(self, name, age, student_id):
super().__init__(name, age)
self.student_id = student_id
def study(self):
print(f"{self.name} is studying")
student = Student("Jane", 20, "S001")
student.greet()
student.study()
File Handling
Read File
# Read all
with open("file.txt", "r") as file:
content = file.read()
print(content)
# Read lines
with open("file.txt", "r") as file:
for line in file:
print(line.strip())
Write File
# Write (overwrite)
with open("output.txt", "w") as file:
file.write("Hello, World!\n")
file.write("Python is awesome!")
# Append
with open("output.txt", "a") as file:
file.write("\nNew line")
Error Handling
try:
number = int(input("Enter number: "))
result = 10 / number
print(result)
except ValueError:
print("Invalid number!")
except ZeroDivisionError:
print("Cannot divide by zero!")
except Exception as e:
print(f"Error: {e}")
finally:
print("Done!")
Modules & Packages
Import Modules
# Built-in modules
import math
print(math.pi)
print(math.sqrt(16))
from datetime import datetime
now = datetime.now()
print(now)
import random
print(random.randint(1, 10))
Create Module
# mymodule.py
def greet(name):
return f"Hello, {name}!"
PI = 3.14159
# main.py
import mymodule
print(mymodule.greet("John"))
print(mymodule.PI)
Popular Libraries
pip install requests # HTTP requests
pip install pandas # Data analysis
pip install numpy # Numerical computing
pip install flask # Web framework
pip install django # Web framework
Project Ideas
1. Calculator
def calculator():
num1 = float(input("Enter first number: "))
operator = input("Enter operator (+, -, *, /): ")
num2 = float(input("Enter second number: "))
if operator == "+":
print(num1 + num2)
elif operator == "-":
print(num1 - num2)
elif operator == "*":
print(num1 * num2)
elif operator == "/":
print(num1 / num2)
else:
print("Invalid operator!")
calculator()
2. To-Do List
3. Password Generator
4. Weather App (API)
5. Web Scraper
6. Chatbot
7. File Organizer
8. Budget Tracker
Next Steps
Web Development
- Flask: Micro framework
- Django: Full-stack framework
- FastAPI: Modern, fast API
Baca: Cara Membuat API dengan Node.js 2026
Data Science
- Pandas: Data manipulation
- NumPy: Numerical computing
- Matplotlib: Visualization
- Scikit-learn: Machine learning
Automation
- Selenium: Browser automation
- BeautifulSoup: Web scraping
- PyAutoGUI: GUI automation
Resources Belajar
Official
- Python.org Documentation
- Python Tutorial (official)
YouTube
- Corey Schafer
- Programming with Mosh
- freeCodeCamp
- Tech With Tim
Practice
- HackerRank
- LeetCode
- Codewars
- Project Euler
Artikel Terkait
- Cara Membuat API dengan Node.js 2026 - Backend development
- Belajar React JS untuk Pemula 2026 - Frontend development
- Tren Teknologi 2026 - Future of programming
Kesimpulan
Python adalah bahasa pemrograman terbaik untuk pemula di 2026. Easy to learn, versatile, dan high demand. Dengan practice konsisten, Anda bisa mahir dalam 3-6 bulan.
Key Takeaways:
- Start with basics (variables, loops, functions)
- Practice daily (30 menit minimum)
- Build real projects
- Join community
- Never stop learning
Butuh bantuan develop aplikasi Python? Hydra Core Digitech siap bantu. Konsultasi gratis!
