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 Dec 1, 2023
1 parent b36f7cd commit 3cdadff
Show file tree
Hide file tree
Showing 9 changed files with 782 additions and 0 deletions.
71 changes: 71 additions & 0 deletions 30 Days Essentials/Days-1-3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
### **Day 1: Introduction to Python**
- Python is a high-level, interpreted programming language known for its readability and simplicity.
- It is versatile and widely used in various domains, including web development, data analysis, artificial intelligence, and more.
- Python code is executed line by line, making it an excellent choice for beginners.
- Example:

```python
# This is a simple Python program that prints a message
print("Hello, World!")
```

### **Day 2: Variables and Data Types**
- Variables are used to store and manipulate data in Python.
- Python supports various data types, including:
- Strings (text): `name = "John"`
- Integers (whole numbers): `age = 30`
- Floats (decimal numbers): `height = 6.1`
- Lists (ordered collections of items): `fruits = ["apple", "banana", "cherry"]`
- Tuples (immutable, ordered collections): `point = (3, 4)`
- Dictionaries (key-value pairs): `person = {"name": "Alice", "age": 25}`
- Variables are dynamically typed, meaning their data type can change during runtime.
- 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 your code to make decisions based on conditions.
- Common conditional statements include `if`, `elif` (else if), and `else`.
- Loops, such as `for` and `while`, are used for repetitive tasks.

**Conditional Statements:**
```python
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:**
- For loops are used to iterate over a sequence (e.g., a list or string).
- Example:

```python
fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
print("I love " + fruit)
```

**While Loop:**
- While loops continue executing as long as a specified condition is True.
- Example:

```python
count = 0
while count < 5:
print("Count: " + str(count))
count += 1
```

These examples provide a deeper understanding of Python's core concepts. Make sure to run them in a Python environment to see the results. You can install Python by downloading it from the official Python website [**python.org**](https://www.python.org/downloads/). After installation, you can use a code editor or Python's built-in IDLE to write and run Python code.

These foundational concepts will serve as the building blocks for your Python journey. Continue to explore and experiment with Python to solidify your understanding and become a proficient Python programmer.
89 changes: 89 additions & 0 deletions 30 Days Essentials/Days-11-14.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
### **Day 11: Functions**
Functions are essential building blocks in Python that encapsulate a set of instructions.

- **Function Basics:**
- Functions are reusable blocks of code that perform a specific task.
- You can define your own functions in Python.
- **Function Definition and Calling:**
- Define functions using the `def` keyword, and call them with arguments.
- Example:

```python
def greet(name):
print(f"Hello, {name}!")

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

- **Function Parameters:**
- Functions can accept parameters (inputs) to perform actions on.
- Parameters are defined within parentheses in the function definition.
- **Function Invocation:**
- When a function is called, it executes the code within its block and may return a result.

### **Day 12: Function Parameters and Return Values**
Functions can take parameters (inputs) and return values (outputs).

- **Parameters:**
- Parameters allow you to pass data into a function.
- Functions can accept multiple parameters.
- Example:

```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.
```

- **Return Values:**
- The `return` statement is used to send a result back from a function.
- Functions can return values of various data types.

### **Day 13: Built-in Modules**
Python provides built-in modules that offer additional functionality.

- **Importing Modules:**
- You can use the `import` statement to access built-in modules.
- Modules extend Python's capabilities for various purposes.
- Example:

```python
import math

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

- **Common Built-in Modules:**
- Python has a wide range of built-in modules, including `math`, `random`, `datetime`, and `os`, among others.
- These modules provide functions and classes to solve common programming problems.

### **Day 14: Creating Your Own Modules**
You can create your own Python modules to organize and reuse your code.

- **Module Basics:**
- A module is a Python file containing functions, variables, and classes.
- It allows you to organize and encapsulate related code.
- **Creating a Custom Module:**
- You can create your own modules by defining functions and variables in a Python file.
- Example:

```python
# my_module.py
def greet(name):
print(f"Hello, {name}!")

# wifi-app.py
import my_module

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

- **Module Reusability:**
- Modules promote code reusability and maintainability.
- You can use modules across multiple Python scripts to share functionality.

Understanding functions and modules is essential for writing organized, reusable, and efficient code in Python. By mastering these concepts, you can 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.
95 changes: 95 additions & 0 deletions 30 Days Essentials/Days-15-18.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
### **Day 15: File Handling**
File handling in Python is essential for reading from and writing to files.

- **Opening a File:**
- Use the `open()` function to interact with files, specifying the file name and the mode ("r" for read, "w" for write, "a" for append, etc.).
- **Reading from a File:**
- To read the contents of a file, use the `read()` method on the file object.
- **Writing to a File:**
- To write content to a file, use the `write()` method on the file object.

**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**
Understanding file modes and using context managers (with statement) can simplify file handling.

- **File Modes:**
- File modes, such as "r" (read), "w" (write), and "a" (append), determine how the file is opened.
- **Context Managers:**
- Context managers ensure that files are automatically closed, even if an exception occurs.

**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.

- **Try-Except Blocks:**
- Use `try` and `except` blocks to catch and handle exceptions.
- **Exception Types:**
- Python has many built-in exception types, and you can create custom exceptions.

**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)**
Handling multiple exceptions and creating custom exceptions enhance your error-handling capabilities.

- **Handling Multiple Exceptions:**
- You can use multiple `except` blocks to handle different exception types.
- **Custom Exceptions:**
- Create custom exception classes by defining new exception types.

**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}")
```

Mastering file handling and error handling is crucial for writing robust and reliable Python programs. These skills enable you to work with files effectively and gracefully manage errors that may occur during program execution. Practice with these examples to become proficient in file handling and error handling in Python.
116 changes: 116 additions & 0 deletions 30 Days Essentials/Days-19-22.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
### **Day 19: Introduction to Object-Oriented Programming (OOP)**
Object-Oriented Programming is a programming paradigm that uses objects to represent real-world entities.

- **Classes and Objects:**
- Classes define blueprints for creating objects.
- Objects are instances of classes.
- **Attributes and Methods:**
- Classes can have attributes (data) and methods (functions) that define their properties and behavior.

**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 and methods that define their behavior.

- **Class Attributes:**
- Class attributes are shared among all instances of the class.
- **Instance Attributes:**
- Instance attributes are specific to individual objects.
- **Methods:**
- Methods are functions defined within a class.

**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 new classes that inherit attributes and methods from existing classes.

- **Parent Class (Superclass):**
- The parent class defines common attributes and methods.
- **Child Class (Subclass):**
- The child class inherits from the parent class and can have additional attributes and methods.

**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.

- **Common Superclass:**
- Create a common superclass that defines shared methods or attributes.
- **Subclasses with Different Implementations:**
- Subclasses provide their own implementations of methods.

**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.
Loading

0 comments on commit 3cdadff

Please sign in to comment.