Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
HalilDeniz authored Oct 5, 2023
1 parent b136ecb commit b571e3f
Show file tree
Hide file tree
Showing 10 changed files with 669 additions and 0 deletions.
51 changes: 51 additions & 0 deletions Days-1-3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
**Day 1: Introduction to Python**
- Python is a high-level programming language.
- It's known for its readability and simplicity.
- Python code is executed line by line.
- Example:
```python
print("Hello, World!")
```

**Day 2: Variables and Data Types**
- Variables are used to store data.
- Common data types include strings, integers, floats, lists, tuples, and dictionaries.
- Example:
```python
name = "John"
age = 30
height = 6.1
fruits = ["apple", "banana", "cherry"]
person = {"name": "Alice", "age": 25}
```

**Day 3: Conditional Statements and Loops**
- Conditional statements allow you to make decisions in your code.
- `if`, `elif`, and `else` are used for branching.
- Loops like `for` and `while` are used for repetitive tasks.
- Example:
```python
# Conditional statement
x = 10
if x > 5:
print("x is greater than 5")
elif x == 5:
print("x is equal to 5")
else:
print("x is less than 5")

# For loop
fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
print(fruit)

# While loop
count = 0
while count < 5:
print(count)
count += 1
```

Remember to run these examples in a Python environment. You can install Python on your computer by downloading it from the official Python website (https://www.python.org/downloads/). Once installed, you can use a code editor or Python's built-in IDLE to write and run Python code.

These examples should give you a good start in understanding basic Python concepts and how to run Python code.
55 changes: 55 additions & 0 deletions Days-11-14.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
**Day 11: Functions**
- Functions are reusable blocks of code that perform a specific task.
- You can define your own functions in Python.

**Example of defining and calling a function:**
```python
def greet(name):
print(f"Hello, {name}!")

greet("Alice") # Call the greet function with the argument "Alice".
```

**Day 12: Function Parameters and Return Values**
- Functions can take parameters (inputs) and return values (outputs).
- You can use the `return` statement to return a value from a function.

**Example of a function with parameters and a return value:**
```python
def add(x, y):
result = x + y
return result

sum_result = add(3, 5)
print(sum_result) # Prints the result of the add function, which is 8.
```

**Day 13: Built-in Modules**
- Python has many built-in modules that provide additional functionality.
- You can use the `import` statement to access these modules.

**Example of importing and using a built-in module (math):**
```python
import math

sqrt_result = math.sqrt(25) # Calculate the square root of 25.
print(sqrt_result) # Prints the result, which is 5.0.
```

**Day 14: Creating Your Own Modules**
- You can create your own Python modules to organize and reuse your code.
- A module is simply a Python file containing functions and variables.

**Example of creating a custom module (my_module.py):**
```python
# my_module.py
def greet(name):
print(f"Hello, {name}!")

# main.py
import my_module

my_module.greet("Bob") # Call the greet function from the custom module.
```

Understanding functions and modules is crucial for writing organized and reusable code in Python. You can create your own functions and modules to efficiently structure your programs and make them more maintainable. Practice with these examples to become proficient in using functions and modules in your Python projects.
77 changes: 77 additions & 0 deletions Days-15-18.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
**Day 15: File Handling**
- File handling in Python allows you to read from and write to files.
- You can use the `open()` function to interact with files.

**Example of reading from a file:**
```python
# Open a file for reading
file = open("example.txt", "r")

# Read the contents of the file
content = file.read()
print(content)

# Close the file
file.close()
```

**Example of writing to a file:**
```python
# Open a file for writing
file = open("example.txt", "w")

# Write content to the file
file.write("Hello, Python!")

# Close the file
file.close()
```

**Day 16: File Modes and Context Managers**
- File modes (e.g., "r" for read, "w" for write) determine how the file is opened.
- Context managers (with statement) simplify file handling and ensure file closure.

**Example of using a context manager to read a file:**
```python
# Using a context manager to automatically close the file
with open("example.txt", "r") as file:
content = file.read()
print(content)
```

**Day 17: Error Handling (Try-Except Blocks)**
- Error handling allows you to gracefully handle exceptions and errors in your code.
- You can use `try`, `except`, `else`, and `finally` blocks to manage errors.

**Example of handling an exception:**
```python
try:
num = int("abc") # This will raise a ValueError
except ValueError as e:
print(f"An error occurred: {e}")
```

**Day 18: Error Handling (Multiple Exceptions and Custom Exceptions)**
- You can handle multiple exceptions with multiple `except` blocks.
- You can create custom exceptions by defining new exception classes.

**Example of handling multiple exceptions and creating a custom exception:**
```python
try:
result = 10 / 0 # This will raise a ZeroDivisionError
except ZeroDivisionError as e:
print(f"Division by zero error: {e}")
except Exception as e:
print(f"An unexpected error occurred: {e}")

# Custom exception
class MyCustomError(Exception):
pass

try:
raise MyCustomError("This is a custom error.")
except MyCustomError as e:
print(f"Custom error caught: {e}")
```

Understanding file handling and error handling is essential for robust and reliable Python programming. These skills help you work with files and gracefully handle errors that may occur during the execution of your code. Practice with these examples to become proficient in file handling and error handling in Python.
97 changes: 97 additions & 0 deletions Days-19-22.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
**Day 19: Introduction to Object-Oriented Programming (OOP)**
- Object-Oriented Programming is a programming paradigm that uses objects to represent real-world entities.
- In Python, everything is an object.

**Example of creating a simple class and an object:**
```python
# Define a simple class
class Dog:
def __init__(self, name):
self.name = name

def bark(self):
print(f"{self.name} says woof!")

# Create an object (instance) of the Dog class
my_dog = Dog("Buddy")
my_dog.bark() # Call the bark method on the object
```

**Day 20: Class Attributes and Methods**
- Classes can have attributes (data) and methods (functions) that define their behavior.
- You can access attributes and call methods on objects.

**Example of class attributes and methods:**
```python
class Circle:
def __init__(self, radius):
self.radius = radius

def area(self):
return 3.14159 * self.radius**2

def circumference(self):
return 2 * 3.14159 * self.radius

my_circle = Circle(5)
print(f"Area: {my_circle.area()}")
print(f"Circumference: {my_circle.circumference()}")
```

**Day 21: Inheritance**
- Inheritance allows you to create a new class that is a modified version of an existing class (parent class).
- The new class inherits the attributes and methods of the parent class.

**Example of inheritance:**
```python
# Parent class
class Animal:
def __init__(self, name):
self.name = name

def speak(self):
pass

# Child class inheriting from Animal
class Dog(Animal):
def speak(self):
return f"{self.name} says woof!"

my_dog = Dog("Buddy")
print(my_dog.speak()) # Calls the speak method of the Dog class
```

**Day 22: Polymorphism**
- Polymorphism allows objects of different classes to be treated as objects of a common superclass.
- It simplifies code and promotes code reusability.

**Example of polymorphism:**
```python
# Common superclass
class Shape:
def area(self):
pass

# Subclasses with different implementations of area
class Circle(Shape):
def __init__(self, radius):
self.radius = radius

def area(self):
return 3.14159 * self.radius**2

class Rectangle(Shape):
def __init__(self, width, height):
self.width = width
self.height = height

def area(self):
return self.width * self.height

shapes = [Circle(5), Rectangle(4, 6)]

for shape in shapes:
print(f"Area: {shape.area()}")
```

Object-Oriented Programming (OOP) is a fundamental concept in Python and many other programming languages. It allows you to model real-world entities, promote code organization, and enhance code reusability. Practice with these examples to become proficient in using OOP principles in Python.
92 changes: 92 additions & 0 deletions Days-23-26.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
**Day 23: Database Connection**
- Python can connect to various types of databases using different database libraries.
- One common library for working with databases in Python is `sqlite3` for SQLite databases.

**Example of connecting to an SQLite database:**
```python
import sqlite3

# Connect to a database (creates a new one if it doesn't exist)
conn = sqlite3.connect("my_database.db")

# Create a cursor object to execute SQL commands
cursor = conn.cursor()

# Close the connection when done
conn.close()
```

**Day 24: Creating Tables and Inserting Data**
- You can create tables in a database and insert data into them using SQL commands.
- The `execute()` method is used to run SQL queries.

**Example of creating a table and inserting data:**
```python
import sqlite3

conn = sqlite3.connect("my_database.db")
cursor = conn.cursor()

# Create a table
cursor.execute("""
CREATE TABLE IF NOT EXISTS students (
id INTEGER PRIMARY KEY,
name TEXT,
age INTEGER
)
""")

# Insert data into the table
cursor.execute("INSERT INTO students (name, age) VALUES (?, ?)", ("Alice", 25))
cursor.execute("INSERT INTO students (name, age) VALUES (?, ?)", ("Bob", 30))

# Commit the changes and close the connection
conn.commit()
conn.close()
```

**Day 25: Querying Data**
- You can retrieve data from a database table using SQL SELECT queries.
- The `fetchall()` method retrieves all rows from a query.

**Example of querying data from a table:**
```python
import sqlite3

conn = sqlite3.connect("my_database.db")
cursor = conn.cursor()

# Query data from the table
cursor.execute("SELECT * FROM students")
students = cursor.fetchall()

# Print the results
for student in students:
print(f"ID: {student[0]}, Name: {student[1]}, Age: {student[2]}")

conn.close()
```

**Day 26: Updating and Deleting Data**
- You can use SQL UPDATE and DELETE queries to modify or remove data from a database table.
- Be cautious when performing updates or deletions.

**Example of updating and deleting data:**
```python
import sqlite3

conn = sqlite3.connect("my_database.db")
cursor = conn.cursor()

# Update data
cursor.execute("UPDATE students SET age = 26 WHERE name = 'Alice'")

# Delete data
cursor.execute("DELETE FROM students WHERE name = 'Bob'")

# Commit the changes and close the connection
conn.commit()
conn.close()
```

Understanding how to work with databases and SQL in Python is crucial for many real-world applications where data storage and retrieval are required. The `sqlite3` library is suitable for learning and small-scale projects, but for larger databases, you may consider other database systems like MySQL or PostgreSQL. Practice with these examples to become proficient in database operations in Python.
Loading

0 comments on commit b571e3f

Please sign in to comment.