---
---
Python bir programlama dilidir ve özellikleri şunlardır:
- ✅ Okuması ve yazması kolay
- 🆓 Ücretsiz ve açık kaynak
- 🌍 Birçok alanda kullanılır: web, veri bilimi, yapay zeka, oyunlar, otomasyon
# Örnek: İlk Python programın
print("Merhaba, Python 🚀")
---
Python’u bilgisayarına kurmak için şu adımları izle:
- ⬇️ Download: [python.org](https://www.python.org/)
- 💻 Install: Kurulum sırasında "Add Python to PATH" kutucuğunu işaretle
- 🧪 Verify: Terminal / CMD aç → `python --version`
---
Python’da değişkenler (variables), verileri saklamak için kullanılır. Veri tipleri ise bu verilerin türünü belirler.
- 🔤 String: Metin verileri
Örn: `"Hello, Python"`
- 🔢 Integer: Tam sayılar
Örn: `42`
- 🔣 Float: Ondalıklı sayılar
Örn: `3.14`
- ✅ Boolean: Doğru / Yanlış
Örn: `True` veya `False`
# Örnekler
name = "Ebrar" # String
age = 20 # Integer
pi = 3.14 # Float
is_student = True # Boolean
print(name, age, pi, is_student)
Ebrar 20 3.14 True
---
Python’da operatörler, değişkenler ve değerler üzerinde işlem yapmamızı sağlar.
- ➕ Arithmetic Operators (Aritmetik)
+ Toplama: `x + y`
+ Çıkarma: `x - y`
+ Çarpma: `x * y`
+ Bölme: `x / y`
+ Mod (kalan): `x % y`
+ Üs alma: `x ** y`
- 🔄 Comparison Operators (Karşılaştırma)
+ Eşit mi: `x == y`
+ Eşit değil mi: `x != y`
+ Büyük mü: `x > y`
+ Küçük mü: `x < y`
+ Büyük eşit mi: `x >= y`
+ Küçük eşit mi: `x <= y`
- 🧩 Logical Operators (Mantıksal)
+ `and` → ve
+ `or` → veya
+ `not` → değil
# Örnekler
x = 10
y = 3
print(x + y) # 13
print(x > y) # True
print(x % y) # 1
print(x > 5 and y < 5) # True
---
Python’da kontrol akışı, koşullara göre farklı kodların çalışmasını sağlar.
- ✅ if: Koşul doğruysa çalışır
- 🔄 else: Koşul yanlışsa çalışır
- ➕ elif: Birden fazla koşulu kontrol eder
- 🔁 for loop: Belirli sayıda döner
- 🔂 while loop: Koşul doğru olduğu sürece döner
# if - elif - else örneği
x = 7
if x > 10:
print("x 10'dan büyük")
elif x == 7:
print("x tam olarak 7 🎯")
else:
print("x 10'dan küçük")
# for loop örneği
for i in range(3):
print("Tekrar:", i)
# while loop örneği
count = 0
while count < 3:
print("Count:", count)
count += 1
---
Python’da veri yapıları, bilgileri saklamak ve düzenlemek için kullanılır.
- 📋 List: Değiştirilebilir, sıralı koleksiyon
- 🔒 Tuple: Değiştirilemez, sıralı koleksiyon
- 📖 Dictionary: Anahtar → Değer çiftleri
- 🎯 Set: Tekrarsız, sırasız koleksiyon
# List
fruits = ["apple", "banana", "cherry"]
fruits.append("orange")
print(fruits) # ['apple', 'banana', 'cherry', 'orange']
# Tuple
colors = ("red", "green", "blue")
print(colors[0]) # red
# Dictionary
person = {"name": "Ebrar", "age": 20}
print(person["name"]) # Ebrar
# Set
unique_numbers = {1, 2, 3, 3, 2}
print(unique_numbers) # {1, 2, 3}
---
Fonksiyonlar, belirli bir görevi gerçekleştiren kod bloklarıdır. Kod tekrarını azaltır ve düzeni artırır.
- 🔹 def: Fonksiyon tanımlamak için kullanılır
- 📥 Parameters: Fonksiyona dışarıdan değer gönderilir
- 📤 return: Fonksiyon bir sonuç döndürebilir
# Basit bir fonksiyon
def greet():
print("Hello, Python Beginner! 🚀")
greet() # Çıktı: Hello, Python Beginner! 🚀
# Parametreli fonksiyon
def add(a, b):
return a + b
print(add(3, 5)) # Çıktı: 8
---
Python’da modüller, fonksiyonları ve kodları organize etmek için kullanılan dosyalardır.
Paketler ise birden fazla modülü bir araya getiren klasörlerdir.
- 📄 Module: `.py` uzantılı dosya (örnek: `math`, `random`)
- 📂 Package: İçinde `__init__.py` olan klasör
- 📥 import: Başka modülleri projeye dahil etmek için kullanılır
# Hazır bir modül kullanma
import math
print(math.sqrt(16)) # 4.0
# Kendi modülünü oluşturma
# mymodule.py dosyası:
def say_hello(name):
return f"Hello, {name}!"
# main.py dosyası:
import mymodule
print(mymodule.say_hello("Ebrar")) # Hello, Ebrar!
---
Python’da dosya işlemleri için open()
fonksiyonu kullanılır.
Dosyaları okuyabilir, yazabilir ve ekleyebilirsin.
- 📖 Read (`r`): Dosyadan okuma
- ✍️ Write (`w`): Dosyaya yazma (öncekini siler)
- ➕ Append (`a`): Dosyanın sonuna ekleme
- 🔒 with: Dosya işini bitirince otomatik kapatır
# Dosyaya yazma
with open("notes.txt", "w") as f:
f.write("Hello, file!")
# Dosyadan okuma
with open("notes.txt", "r") as f:
content = f.read()
print(content) # Hello, file!
# Dosyaya ekleme
with open("notes.txt", "a") as f:
f.write("\nNew line added!")
---
Python’da Nesne Yönelimli Programlama, kodu sınıflar (classes) ve nesneler (objects) üzerinden organize etmeyi sağlar.
- 🏷️ Class: Bir nesnenin planı / şablonu
- 🎭 Object: Class’tan oluşturulan örnek
- 🧱 Attributes: Nesnenin özellikleri (değişkenler)
- ⚡ Methods: Nesnenin yapabildiği işler (fonksiyonlar)
- 🧬 Inheritance: Bir sınıfın başka bir sınıftan miras alması
# Basit bir sınıf
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
def greet(self):
print(f"Hello, my name is {self.name} and I am {self.age} years old.")
# Nesne oluşturma
p1 = Person("Ebrar", 20)
p1.greet()
# Çıktı: Hello, my name is Ebrar and I am 20 years old.
# Inheritance (Kalıtım) örneği
class Student(Person):
def __init__(self, name, age, student_id):
super().__init__(name, age)
self.student_id = student_id
s1 = Student("Ebrar", 20, "ST123")
print(s1.student_id) # ST123
---
Artık Python’un temellerini öğrendin! Bundan sonra:
- 🧩 Practice: Daha çok örnek yap, küçük projeler üret
- 📂 Explore: Kendi projelerini GitHub’da paylaş
- 🕹️ Build: Mini oyunlar, web uygulamaları veya otomasyon scriptleri yap
- 🤝 Collaborate: Açık kaynak projelere katkı ver
---
> Python basit ama güçlüdür. Öğrenmenin yolu, **her gün kod yazarak ilerlemektir.** 🚀
---
---
Python is a programming language with the following features:
- ✅ Easy to read and write
- 🆓 Free and open-source
- 🌍 Used in many fields: web, data science, AI, games, automation
# Example: Your first Python program
print("Hello, Python 🚀")
---
To install Python on your computer, follow these steps:
- ⬇️ Download: [python.org](https://www.python.org/)
- 💻 Install: Check the "Add Python to PATH" box during setup
- 🧪 Verify: Open Terminal / CMD → `python --version`
---
In Python, variables are used to store data. Data types define the kind of data.
- 🔤 String: Text data
Ex: `"Hello, Python"`
- 🔢 Integer: Whole numbers
Ex: `42`
- 🔣 Float: Decimal numbers
Ex: `3.14`
- ✅ Boolean: True / False values
Ex: `True` or `False`
# Examples
name = "Ebrar" # String
age = 20 # Integer
pi = 3.14 # Float
is_student = True # Boolean
print(name, age, pi, is_student)
Ebrar 20 3.14 True
---
Operators in Python allow us to perform operations on variables and values.
- ➕ Arithmetic Operators
+ Addition: `x + y`
+ Subtraction: `x - y`
+ Multiplication: `x * y`
+ Division: `x / y`
+ Modulo (remainder): `x % y`
+ Exponentiation: `x ** y`
- 🔄 Comparison Operators
+ Equal: `x == y`
+ Not equal: `x != y`
+ Greater than: `x > y`
+ Less than: `x < y`
+ Greater than or equal: `x >= y`
+ Less than or equal: `x <= y`
- 🧩 Logical Operators
+ `and` → and
+ `or` → or
+ `not` → not
# Examples
x = 10
y = 3
print(x + y) # 13
print(x > y) # True
print(x % y) # 1
print(x > 5 and y < 5) # True
---
Control flow in Python allows different code blocks to run based on conditions.
- ✅ if: Runs if condition is true
- 🔄 else: Runs if condition is false
- ➕ elif: Checks multiple conditions
- 🔁 for loop: Runs a set number of times
- 🔂 while loop: Runs as long as the condition is true
# if - elif - else example
x = 7
if x > 10:
print("x is greater than 10")
elif x == 7:
print("x is exactly 7 🎯")
else:
print("x is less than 10")
# for loop example
for i in range(3):
print("Repeat:", i)
# while loop example
count = 0
while count < 3:
print("Count:", count)
count += 1
---
Python has built-in data structures for storing and organizing data.
- 📋 List: Mutable, ordered collection
- 🔒 Tuple: Immutable, ordered collection
- 📖 Dictionary: Key → Value pairs
- 🎯 Set: Unordered collection of unique items
# List
fruits = ["apple", "banana", "cherry"]
fruits.append("orange")
print(fruits) # ['apple', 'banana', 'cherry', 'orange']
# Tuple
colors = ("red", "green", "blue")
print(colors[0]) # red
# Dictionary
person = {"name": "Ebrar", "age": 20}
print(person["name"]) # Ebrar
# Set
unique_numbers = {1, 2, 3, 3, 2}
print(unique_numbers) # {1, 2, 3}
---
Functions are blocks of code that perform a specific task. They reduce repetition and increase organization.
- 🔹 def: Used to define a function
- 📥 Parameters: Values passed into the function
- 📤 return: Returns a result from the function
# Simple function
def greet():
print("Hello, Python Beginner! 🚀")
greet() # Output: Hello, Python Beginner! 🚀
# Function with parameters
def add(a, b):
return a + b
print(add(3, 5)) # Output: 8
---
In Python, modules are files that organize functions and code.
Packages are folders that contain multiple modules.
- 📄 Module: File with `.py` extension (e.g., `math`, `random`)
- 📂 Package: Folder with an `__init__.py` file
- 📥 import: Used to include modules in your project
# Using a built-in module
import math
print(math.sqrt(16)) # 4.0
# Creating your own module
# mymodule.py file:
def say_hello(name):
return f"Hello, {name}!"
# main.py file:
import mymodule
print(mymodule.say_hello("Ebrar")) # Hello, Ebrar!
---
In Python, the open()
function is used for file operations.
You can read, write, or append to files.
- 📖 Read (`r`): Read from file
- ✍️ Write (`w`): Write to file (overwrites existing)
- ➕ Append (`a`): Add to end of file
- 🔒 with: Automatically closes file after operation
# Write to file
with open("notes.txt", "w") as f:
f.write("Hello, file!")
# Read from file
with open("notes.txt", "r") as f:
content = f.read()
print(content) # Hello, file!
# Append to file
with open("notes.txt", "a") as f:
f.write("\nNew line added!")
---
Object-Oriented Programming in Python lets you organize code using classes and objects.
- 🏷️ Class: A blueprint for an object
- 🎭 Object: An instance of a class
- 🧱 Attributes: Properties of the object (variables)
- ⚡ Methods: Actions the object can perform (functions)
- 🧬 Inheritance: One class inherits from another
# Basic class
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
def greet(self):
print(f"Hello, my name is {self.name} and I am {self.age} years old.")
# Create object
p1 = Person("Ebrar", 20)
p1.greet()
# Output: Hello, my name is Ebrar and I am 20 years old.
# Inheritance example
class Student(Person):
def __init__(self, name, age, student_id):
super().__init__(name, age)
self.student_id = student_id
s1 = Student("Ebrar", 20, "ST123")
print(s1.student_id) # ST123
---
Now that you’ve learned the basics of Python, what’s next?
- 🧩 Practice: Try more examples, build small projects
- 📂 Explore: Share your work on GitHub
- 🕹️ Build: Create mini games, web apps, or automation scripts
- 🤝 Collaborate: Contribute to open-source projects
---
> Python is simple but powerful. The way to learn it is to **code every day.** 🚀
---