python
python
## **Table of Contents**
1. [Introduction to Python](#1-introduction-to-python)
2. [Setting Up Python](#2-setting-up-python)
- [Installing Python](#installing-python)
3. [Python Basics](#3-python-basics)
- [Hello World](#hello-world)
- [Operators](#operators)
4. [Control Structures](#4-control-structures)
- [Conditional Statements](#conditional-statements)
- [Loops](#loops)
5. [Functions](#5-functions)
6. [Data Structures](#6-data-structures)
- [Lists](#lists)
- [Tuples](#tuples)
- [Dictionaries](#dictionaries)
- [Sets](#sets)
7. [File Handling](#7-file-handling)
8. [Error Handling](#8-error-handling)
Python is a high-level, interpreted, and general-purpose programming language known for its
simplicity and readability. It supports multiple programming paradigms, including procedural,
object-oriented, and functional programming.
**Key Features:**
- Cross-platform compatibility
- Dynamically typed
**Use Cases:**
---
2. **Run Installer**: Follow the installation steps (ensure "Add Python to PATH" is checked).
```sh
python --version
```
```sh
python3 --version
```
---
```python
print("Hello, World!")
```
Run this in a Python interpreter or save it as `hello.py` and execute:
```sh
python hello.py
```
Python supports:
### **Operators**
- **Arithmetic**: `+`, `-`, `*`, `/`, `%`, `**` (exponent), `//` (floor division)
```python
print(f"Hello, {name}!")
```
---
```python
age = 18
print("Adult")
print("Teen")
else:
print("Child")
```
### **Loops**
- **`for` Loop**:
```python
for i in range(5): # 0 to 4
print(i)
```
- **`while` Loop**:
```python
count = 0
while count < 5:
print(count)
count += 1
```
---
## **5. Functions**
```python
def greet(name):
print(greet("Alice"))
```
```python
square = lambda x: x * x
print(square(5)) # Output: 25
```
---
### **Lists**
```python
fruits.append("orange")
```
```python
point = (3, 4)
x, y = point # Unpacking
```
```python
```
```python
unique_numbers = {1, 2, 2, 3}
```
---
## **7. File Handling**
```python
# Writing to a file
file.write("Hello, File!")
content = file.read()
print(content)
```
---
```python
try:
result = 10 / 0
except ZeroDivisionError:
finally:
print("Execution complete.")
```
---
## **9. Object-Oriented Programming (OOP)**
```python
class Dog:
self.name = name
def bark(self):
dog = Dog("Buddy")
dog.bark()
```
---
- **Importing Modules**:
```python
import math
```
```sh
```
---
- **Explore Libraries**:
---
### **Conclusion**
Python is a versatile language suitable for beginners and professionals alike. This guide covers
the fundamentals, but continuous practice and project-building will solidify your skills. Happy
coding! 🚀🐍