Python
78 ~40 dk
Veritabanı İşlemleri (SQLite)
SQLite ve Python
SQLite, kurulum gerektirmeyen hafif bir veritabanıdır. Python'da sqlite3 modülü ile kullanılır.
import sqlite3
# Veritabanı bağlantısı
conn = sqlite3.connect("okul.db")
cursor = conn.cursor()
# Tablo oluştur
cursor.execute(\"\"\"
CREATE TABLE IF NOT EXISTS ogrenciler (
id INTEGER PRIMARY KEY AUTOINCREMENT,
ad TEXT NOT NULL,
soyad TEXT NOT NULL,
not_ort REAL DEFAULT 0
)
\"\"\")
# Veri ekle
cursor.execute("INSERT INTO ogrenciler (ad, soyad, not_ort) VALUES (?, ?, ?)",
("Ali", "Yılmaz", 85.5))
cursor.execute("INSERT INTO ogrenciler (ad, soyad, not_ort) VALUES (?, ?, ?)",
("Veli", "Kaya", 92.0))
conn.commit()
# Veri çek
cursor.execute("SELECT * FROM ogrenciler")
for row in cursor.fetchall():
print(f"ID: {row[0]} | {row[1]} {row[2]} | Not: {row[3]}")
conn.close()>>> python sqlite_ornek.py
ID: 1 | Ali Yılmaz | Not: 85.5
ID: 2 | Veli Kaya | Not: 92.0🎯 Alıştırmalar
- Kütüphane yönetim sistemi (kitap ekleme, arama, ödünç verme)
- Öğrenci kayıt sistemi (CRUD işlemleri)